public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext) { var metricsAttributes = input.MethodBase.GetCustomAttributes(true).OfType <IMetricsAttribute>(); var disposables = new List <IDisposable>(); try { foreach (var metricsAttribute in metricsAttributes) { FillMacros(input, metricsAttribute); switch (metricsAttribute) { case MetricsTimerAttribute timerAttribute: var metricTimer = _metricsProvider.Timer(timerAttribute.Context, timerAttribute.Name); disposables.Add(metricTimer); break; case MetricsCounterAttribute counterAttribute: var counterValue = long.Parse(GetMethodParamValue(input, counterAttribute.ParamName) ?? "1"); _metricsProvider.Counter(counterAttribute.Context, counterAttribute.Name, counterValue); break; case MetricsMeterAttribute meterAttribute: var meterValue = long.Parse(GetMethodParamValue(input, meterAttribute.ParamName) ?? "1"); _metricsProvider.Meter(meterAttribute.Context, meterAttribute.Name, meterValue); break; case MetricsHistogramAttribute histogramAttribute: var histogramValue = long.Parse(GetMethodParamValue(input, histogramAttribute.ParamName) ?? "1"); _metricsProvider.Meter(histogramAttribute.Context, histogramAttribute.Name, histogramValue); break; } } return(getNext()(input, getNext)); } finally { foreach (var disposable in disposables) { disposable?.Dispose(); } } }