public object AddCustomAttribute(string key, object value)
        {
            try
            {
                _apiSupportabilityMetricCounters.Record(ApiMethod.TransactionAddCustomAttribute);

                if (!_configSvc.Configuration.CaptureCustomParameters)
                {
                    return(_transaction);
                }

                _transaction.AddCustomAttribute(key, value);
            }
            catch (Exception ex)
            {
                try
                {
                    Log.Error($"Error in AddCustomAttribute: {ex}");
                }
                catch (Exception)
                {
                    //Swallow the error
                }
            }

            return(_transaction);
        }
        public ITransaction AddCustomAttribute(string key, object value)
        {
            if (!_isAddCustomAttributeAvailable)
            {
                return(_noOpTransaction.AddCustomAttribute(key, value));
            }

            try
            {
                _wrappedTransaction.AddCustomAttribute(key, value);
                return(this);
            }
            catch (RuntimeBinderException)
            {
                _isAddCustomAttributeAvailable = false;
            }

            return(this);
        }
        public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall instrumentedMethodCall,
                                                              IAgent agent, ITransaction transaction)
        {
            if (!HttpRuntime.UsingIntegratedPipeline)
            {
                return(Delegates.NoOp);
            }

            var httpApplication = (HttpApplication)instrumentedMethodCall.MethodCall.InvocationTarget;

            if (httpApplication == null)
            {
                throw new NullReferenceException("httpApplication");
            }

            var httpContext = httpApplication.Context;

            if (httpContext == null)
            {
                throw new NullReferenceException("httpContext");
            }

            if (httpContext.CurrentNotification != RequestNotification.MapRequestHandler)
            {
                return(Delegates.NoOp);
            }

            prefix = prefix ?? readPrefix(agent);
            if (!captureFullUrl.HasValue)
            {
                readConfiguredRequestProps(agent);
            }
            headerNames = headerNames ?? readConfiguredHeaderNames(agent);
            paramNames  = paramNames ?? readConfiguredParamNames(agent);
            cookieNames = cookieNames ?? readConfiguredCookieNames(agent);

            var requestPath = RequestPathRetriever.TryGetRequestPath(httpContext.Request);

            if (captureFullUrl == true)
            {
                var requestUrl = RequestUrlRetriever.TryGetRequestUrl(httpContext.Request, () => requestPath);
                if (requestUrl != null)
                {
                    transaction.AddCustomAttribute(prefix + "Url", requestUrl.AbsoluteUri);
                }
            }

            foreach (var headerName in headerNames)
            {
                string headerValue = httpContext.Request.Headers?.Get(headerName);
                if (headerValue != null)
                {
                    transaction.AddCustomAttribute(prefix + headerName, headerValue);
                }
            }

            foreach (var paramName in paramNames)
            {
                string paramValue = httpContext.Request.Params?.Get(paramName);
                if (paramValue != null)
                {
                    transaction.AddCustomAttribute(prefix + paramName, paramValue);
                }
            }

            foreach (var cookieName in cookieNames)
            {
                HttpCookie cookieValue = httpContext.Request.Cookies?.Get(cookieName);
                if (cookieValue != null)
                {
                    transaction.AddCustomAttribute(prefix + cookieName, cookieValue.Value);
                }
            }

            return(Delegates.NoOp);
        }