Esempio n. 1
0
        public static T ExecuteSyncImpl <T>(
            object multiplexer,
            object message,
            object processor,
            object server,
            int opCode,
            int mdToken,
            long moduleVersionPtr)
        {
            if (multiplexer == null)
            {
                throw new ArgumentNullException(nameof(multiplexer));
            }

            var genericType     = typeof(T);
            var multiplexerType = multiplexer.GetInstrumentedType(ConnectionMultiplexerTypeName);
            Func <object, object, object, object, T> instrumentedMethod;

            try
            {
                instrumentedMethod =
                    MethodBuilder <Func <object, object, object, object, T> >
                    .Start(moduleVersionPtr, mdToken, opCode, nameof(ExecuteSyncImpl))
                    .WithConcreteType(multiplexerType)
                    .WithParameters(message, processor, server)
                    .WithMethodGenerics(genericType)
                    .WithNamespaceAndNameFilters(
                        ClrNames.Ignore,
                        StackExchangeRedisMessage,
                        StackExchangeRedisResultProcessor,
                        StackExchangeRedisServerEndPoint)
                    .Build();
            }
            catch (Exception ex)
            {
                Log.ErrorRetrievingMethod(
                    exception: ex,
                    moduleVersionPointer: moduleVersionPtr,
                    mdToken: mdToken,
                    opCode: opCode,
                    instrumentedType: ConnectionMultiplexerTypeName,
                    methodName: nameof(ExecuteSyncImpl),
                    instanceType: multiplexer.GetType().AssemblyQualifiedName);
                throw;
            }

            using (var scope = CreateScope(multiplexer, message))
            {
                try
                {
                    return(instrumentedMethod(multiplexer, message, processor, server));
                }
                catch (Exception ex)
                {
                    scope?.Span.SetException(ex);
                    throw;
                }
            }
        }
        public static object CallElasticsearch <TResponse>(
            object pipeline,
            object requestData,
            int opCode,
            int mdToken,
            long moduleVersionPtr)
        {
            if (pipeline == null)
            {
                throw new ArgumentNullException(nameof(pipeline));
            }

            const string methodName = nameof(CallElasticsearch);
            Func <object, object, TResponse> callElasticSearch;
            var pipelineType    = pipeline.GetType();
            var genericArgument = typeof(TResponse);

            try
            {
                callElasticSearch =
                    MethodBuilder <Func <object, object, TResponse> >
                    .Start(moduleVersionPtr, mdToken, opCode, methodName)
                    .WithConcreteType(pipelineType)
                    .WithMethodGenerics(genericArgument)
                    .WithParameters(requestData)
                    .WithNamespaceAndNameFilters(ClrNames.Ignore, "Elasticsearch.Net.RequestData")
                    .Build();
            }
            catch (Exception ex)
            {
                // profiled app will not continue working as expected without this method
                Log.ErrorRetrievingMethod(
                    exception: ex,
                    moduleVersionPointer: moduleVersionPtr,
                    mdToken: mdToken,
                    opCode: opCode,
                    instrumentedType: RequestPipelineInterfaceTypeName,
                    methodName: methodName,
                    instanceType: pipeline.GetType().AssemblyQualifiedName);
                throw;
            }

            using (var scope = ElasticsearchNetCommon.CreateScope(Tracer.Instance, IntegrationName, pipeline, requestData))
            {
                try
                {
                    var returned = callElasticSearch(pipeline, requestData);
                    scope?.Span.SetDbStatementFromRequestData(requestData);
                    return(returned);
                }
                catch (Exception ex) when(scope?.Span.SetExceptionForFilter(ex) ?? false)
                {
                    // unreachable code
                    throw;
                }
            }
        }
Esempio n. 3
0
        public static object Execute(
            object wireProtocol,
            object connection,
            object cancellationTokenSource,
            int opCode,
            int mdToken,
            long moduleVersionPtr)
        {
            if (wireProtocol == null)
            {
                throw new ArgumentNullException(nameof(wireProtocol));
            }

            const string methodName = nameof(Execute);
            Func <object, object, CancellationToken, object> execute;
            var wireProtocolType = wireProtocol.GetType();

            var tokenSource       = cancellationTokenSource as CancellationTokenSource;
            var cancellationToken = tokenSource?.Token ?? CancellationToken.None;

            try
            {
                execute =
                    MethodBuilder <Func <object, object, CancellationToken, object> >
                    .Start(moduleVersionPtr, mdToken, opCode, methodName)
                    .WithConcreteType(wireProtocolType)
                    .WithParameters(connection, cancellationToken)
                    .WithNamespaceAndNameFilters(ClrNames.Void, "MongoDB.Driver.Core.Connections.IConnection", ClrNames.CancellationToken)
                    .Build();
            }
            catch (Exception ex)
            {
                Log.ErrorRetrievingMethod(
                    exception: ex,
                    moduleVersionPointer: moduleVersionPtr,
                    mdToken: mdToken,
                    opCode: opCode,
                    instrumentedType: IWireProtocol,
                    methodName: methodName,
                    instanceType: wireProtocol.GetType().AssemblyQualifiedName);
                throw;
            }

            using (var scope = CreateScope(wireProtocol, connection))
            {
                try
                {
                    return(execute(wireProtocol, connection, cancellationToken));
                }
                catch (Exception ex) when(scope?.Span.SetExceptionForFilter(ex) ?? false)
                {
                    // unreachable code
                    throw;
                }
            }
        }
Esempio n. 4
0
        public static object GetRequestStream(object webRequest, int opCode, int mdToken, long moduleVersionPtr)
        {
            if (webRequest == null)
            {
                throw new ArgumentNullException(nameof(webRequest));
            }

            const string methodName = nameof(GetRequestStream);

            Func <object, Stream> callGetRequestStream;

            try
            {
                var instrumentedType = webRequest.GetInstrumentedType("System.Net.WebRequest");
                callGetRequestStream =
                    MethodBuilder <Func <object, Stream> >
                    .Start(moduleVersionPtr, mdToken, opCode, methodName)
                    .WithConcreteType(instrumentedType)
                    .WithNamespaceAndNameFilters("System.IO.Stream")
                    .Build();
            }
            catch (Exception ex)
            {
                Log.ErrorRetrievingMethod(
                    exception: ex,
                    moduleVersionPointer: moduleVersionPtr,
                    mdToken: mdToken,
                    opCode: opCode,
                    instrumentedType: WebRequestTypeName,
                    methodName: methodName,
                    instanceType: webRequest.GetType().AssemblyQualifiedName);
                throw;
            }

            var request = (WebRequest)webRequest;

            if (!(request is HttpWebRequest) || !IsTracingEnabled(request))
            {
                return(callGetRequestStream(webRequest));
            }

            var spanContext = ScopeFactory.CreateHttpSpanContext(Tracer.Instance, request.Method, request.RequestUri, IntegrationName);

            if (spanContext != null)
            {
                // Add distributed tracing headers to the HTTP request. The actual span is going to be created
                // when GetResponse is called.
                Tracer.Instance.Propagator.Inject(spanContext, request.Headers.Wrap());
            }

            return(callGetRequestStream(webRequest));
        }
        public static object HttpMessageHandler_SendAsync(
            object handler,
            object request,
            object cancellationTokenSource,
            int opCode,
            int mdToken,
            long moduleVersionPtr)
        {
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            // original signature:
            // Task<HttpResponseMessage> HttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
            var tokenSource        = cancellationTokenSource as CancellationTokenSource;
            var cancellationToken  = tokenSource?.Token ?? CancellationToken.None;
            var callOpCode         = (OpCodeValue)opCode;
            var httpMessageHandler = handler.GetInstrumentedType(HttpMessageHandler);

            Func <HttpMessageHandler, HttpRequestMessage, CancellationToken, Task <HttpResponseMessage> > instrumentedMethod = null;

            try
            {
                instrumentedMethod =
                    MethodBuilder <Func <HttpMessageHandler, HttpRequestMessage, CancellationToken, Task <HttpResponseMessage> > >
                    .Start(moduleVersionPtr, mdToken, opCode, SendAsync)
                    .WithConcreteType(httpMessageHandler)
                    .WithParameters(request, cancellationToken)
                    .WithNamespaceAndNameFilters(ClrNames.GenericTask, ClrNames.HttpRequestMessage, ClrNames.CancellationToken)
                    .Build();
            }
            catch (Exception ex)
            {
                Log.ErrorRetrievingMethod(
                    exception: ex,
                    moduleVersionPointer: moduleVersionPtr,
                    mdToken: mdToken,
                    opCode: opCode,
                    instrumentedType: HttpMessageHandler,
                    methodName: SendAsync,
                    instanceType: handler.GetType().AssemblyQualifiedName);
                throw;
            }

            return(SendAsyncInternal(
                       instrumentedMethod,
                       reportedType: callOpCode == OpCodeValue.Call ? httpMessageHandler : handler.GetType(),
                       (HttpMessageHandler)handler,
                       (HttpRequestMessage)request,
                       cancellationToken));
        }
Esempio n. 6
0
        public static object ExecuteReader(
            object command,
            int opCode,
            int mdToken,
            long moduleVersionPtr)
        {
            Func <DbCommand, DbDataReader> instrumentedMethod;

            try
            {
                instrumentedMethod =
                    MethodBuilder <Func <DbCommand, DbDataReader> >
                    .Start(moduleVersionPtr, mdToken, opCode, AdoNetConstants.MethodNames.ExecuteReader)
                    .WithConcreteType(typeof(DbCommand))
                    .WithNamespaceAndNameFilters(DbDataReaderTypeName)
                    .Build();
            }
            catch (Exception ex)
            {
                Log.ErrorRetrievingMethod(
                    exception: ex,
                    moduleVersionPointer: moduleVersionPtr,
                    mdToken: mdToken,
                    opCode: opCode,
                    instrumentedType: DbCommandTypeName,
                    methodName: nameof(ExecuteReader),
                    instanceType: command.GetType().AssemblyQualifiedName);
                throw;
            }

            var dbCommand = command as DbCommand;

            using (var scope = ScopeFactory.CreateDbCommandScope(Tracer.Instance, dbCommand, IntegrationName))
            {
                try
                {
                    return(instrumentedMethod(dbCommand));
                }
                catch (Exception ex)
                {
                    scope?.Span.SetException(ex);
                    throw;
                }
            }
        }
        public static bool HandleRequest(
            object channelHandler,
            object requestContext,
            object currentOperationContext,
            int opCode,
            int mdToken,
            long moduleVersionPtr)
        {
            if (channelHandler == null)
            {
                throw new ArgumentNullException(nameof(channelHandler));
            }

            Func <object, object, object, bool> instrumentedMethod;
            var declaringType = channelHandler.GetInstrumentedType(ChannelHandlerTypeName);

            try
            {
                instrumentedMethod = MethodBuilder <Func <object, object, object, bool> >
                                     .Start(moduleVersionPtr, mdToken, opCode, nameof(HandleRequest))
                                     .WithConcreteType(declaringType)
                                     .WithParameters(requestContext, currentOperationContext)
                                     .WithNamespaceAndNameFilters(
                    ClrNames.Bool,
                    "System.ServiceModel.Channels.RequestContext",
                    "System.ServiceModel.OperationContext")
                                     .Build();
            }
            catch (Exception ex)
            {
                Log.ErrorRetrievingMethod(
                    exception: ex,
                    moduleVersionPointer: moduleVersionPtr,
                    mdToken: mdToken,
                    opCode: opCode,
                    instrumentedType: ChannelHandlerTypeName,
                    methodName: nameof(HandleRequest),
                    instanceType: channelHandler.GetType().AssemblyQualifiedName);
                throw;
            }

            using (var scope = CreateScope(requestContext as RequestContext))
            {
                try
                {
                    return(instrumentedMethod(channelHandler, requestContext, currentOperationContext));
                }
                catch (Exception ex)
                {
                    scope.Span.SetException(ex);
                    throw;
                }
            }
        }
        public static T SendReceive <T>(
            object redisNativeClient,
            byte[][] cmdWithBinaryArgs,
            object fn,
            object completePipelineFn,
            bool sendWithoutRead,
            int opCode,
            int mdToken,
            long moduleVersionPtr)
        {
            if (redisNativeClient == null)
            {
                throw new ArgumentNullException(nameof(redisNativeClient));
            }

            Func <object, byte[][], object, object, bool, T> instrumentedMethod;

            try
            {
                var instrumentedType = redisNativeClient.GetInstrumentedType(RedisNativeClient);
                instrumentedMethod =
                    MethodBuilder <Func <object, byte[][], object, object, bool, T> >
                    .Start(moduleVersionPtr, mdToken, opCode, nameof(SendReceive))
                    .WithConcreteType(instrumentedType)
                    .WithParameters(cmdWithBinaryArgs, fn, completePipelineFn, sendWithoutRead)
                    .WithMethodGenerics(typeof(T))
                    .WithNamespaceAndNameFilters(ClrNames.Ignore, "System.Byte[][]", "System.Func`1", "System.Action`1", ClrNames.Bool)
                    .Build();
            }
            catch (Exception ex)
            {
                Log.ErrorRetrievingMethod(
                    exception: ex,
                    moduleVersionPointer: moduleVersionPtr,
                    mdToken: mdToken,
                    opCode: opCode,
                    instrumentedType: RedisNativeClient,
                    methodName: nameof(SendReceive),
                    instanceType: redisNativeClient.GetType().AssemblyQualifiedName);
                throw;
            }

            using (var scope = RedisHelper.CreateScope(
                       Tracer.Instance,
                       IntegrationName,
                       RedisAssembly,
                       GetHost(redisNativeClient),
                       GetPort(redisNativeClient),
                       GetRawCommand(cmdWithBinaryArgs)))
            {
                try
                {
                    return(instrumentedMethod(redisNativeClient, cmdWithBinaryArgs, fn, completePipelineFn, sendWithoutRead));
                }
                catch (Exception ex)
                {
                    scope?.Span?.SetException(ex);
                    throw;
                }
            }
        }
        /// <summary>
        /// Calls the underlying ExecuteAsync and traces the request.
        /// </summary>
        /// <param name="apiController">The Api Controller</param>
        /// <param name="controllerContext">The controller context for the call</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <param name="opCode">The OpCode used in the original method call.</param>
        /// <param name="mdToken">The mdToken of the original method call.</param>
        /// <param name="moduleVersionPtr">A pointer to the module version GUID.</param>
        /// <returns>A task with the result</returns>
        private static async Task <HttpResponseMessage> ExecuteAsyncInternal(
            object apiController,
            object controllerContext,
            CancellationToken cancellationToken,
            int opCode,
            int mdToken,
            long moduleVersionPtr)
        {
            Func <object, object, CancellationToken, Task <HttpResponseMessage> > instrumentedMethod;

            try
            {
                var httpControllerType = apiController.GetInstrumentedInterface(HttpControllerTypeName);

                instrumentedMethod = MethodBuilder <Func <object, object, CancellationToken, Task <HttpResponseMessage> > >
                                     .Start(moduleVersionPtr, mdToken, opCode, nameof(ExecuteAsync))
                                     .WithConcreteType(httpControllerType)
                                     .WithParameters(controllerContext, cancellationToken)
                                     .WithNamespaceAndNameFilters(
                    ClrNames.HttpResponseMessageTask,
                    HttpControllerContextTypeName,
                    ClrNames.CancellationToken)
                                     .Build();
            }
            catch (Exception ex)
            {
                Log.ErrorRetrievingMethod(
                    exception: ex,
                    moduleVersionPointer: moduleVersionPtr,
                    mdToken: mdToken,
                    opCode: opCode,
                    instrumentedType: HttpControllerTypeName,
                    methodName: nameof(ExecuteAsync),
                    instanceType: apiController.GetType().AssemblyQualifiedName);
                throw;
            }

            using (Scope scope = CreateScope(controllerContext))
            {
                try
                {
                    // call the original method, inspecting (but not catching) any unhandled exceptions
                    var responseMessage = await instrumentedMethod(apiController, controllerContext, cancellationToken).ConfigureAwait(false);

                    if (scope != null)
                    {
                        // some fields aren't set till after execution, so populate anything missing
                        UpdateSpan(controllerContext, scope.Span);
                        if (responseMessage.StatusCode == HttpStatusCode.OK)
                        {
                            scope.Span.SetTag(Tags.HttpStatusCode, "200");
                        }
                        else
                        {
                            scope.Span.SetTag(Tags.HttpStatusCode, ((int)responseMessage.StatusCode).ToString(CultureInfo.InvariantCulture));
                            if (!string.IsNullOrWhiteSpace(responseMessage.ReasonPhrase))
                            {
                                scope.Span.SetTag(Tags.HttpStatusText, responseMessage.ReasonPhrase);
                            }
                        }
                    }

                    return(responseMessage);
                }
                catch (Exception ex)
                {
                    if (scope != null)
                    {
                        // some fields aren't set till after execution, so populate anything missing
                        UpdateSpan(controllerContext, scope.Span);
                    }

                    scope?.Span.SetException(ex);

                    throw;
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Execute an asynchronous redis operation.
        /// </summary>
        /// <typeparam name="T">The result type</typeparam>
        /// <param name="redisBase">The object this method is called on</param>
        /// <param name="message">The message</param>
        /// <param name="processor">The result processor</param>
        /// <param name="server">The server</param>
        /// <param name="callOpCode">The <see cref="OpCodeValue"/> used in the original method call.</param>
        /// <param name="mdToken">The mdToken of the original method call.</param>
        /// <param name="moduleVersionPtr">A pointer to the module version GUID.</param>
        /// <returns>An asynchronous task.</returns>
        private static async Task <T> ExecuteAsyncInternal <T>(
            object redisBase,
            object message,
            object processor,
            object server,
            int callOpCode,
            int mdToken,
            long moduleVersionPtr)
        {
            if (redisBase == null)
            {
                throw new ArgumentNullException(nameof(redisBase));
            }

            var thisType = redisBase.GetType();

            if (_redisAssembly == null)
            {
                // get these only once and cache them,
                // no need for locking, race conditions are not a problem
                _redisAssembly = thisType.Assembly;
                _redisBaseType = _redisAssembly.GetType("StackExchange.Redis.RedisBase");
                _batchType     = _redisAssembly.GetType("StackExchange.Redis.RedisBatch");
            }

            Func <object, object, object, object, Task <T> > instrumentedMethod;

            try
            {
                instrumentedMethod = MethodBuilder <Func <object, object, object, object, Task <T> > >
                                     .Start(moduleVersionPtr, mdToken, callOpCode, nameof(ExecuteAsync))
                                     .WithConcreteType(_redisBaseType)
                                     .WithMethodGenerics(typeof(T))
                                     .WithParameters(message, processor, server)
                                     .WithNamespaceAndNameFilters(
                    ClrNames.GenericTask,
                    "StackExchange.Redis.Message",
                    "StackExchange.Redis.ResultProcessor`1",
                    "StackExchange.Redis.ServerEndPoint")
                                     .Build();
            }
            catch (Exception ex)
            {
                Log.ErrorRetrievingMethod(
                    exception: ex,
                    moduleVersionPointer: moduleVersionPtr,
                    mdToken: mdToken,
                    opCode: callOpCode,
                    instrumentedType: RedisBaseTypeName,
                    methodName: nameof(ExecuteAsync),
                    instanceType: thisType.AssemblyQualifiedName);
                throw;
            }

            // we only trace RedisBatch methods here
            if (thisType == _batchType)
            {
                using (var scope = CreateScope(redisBase, message))
                {
                    try
                    {
                        return(await instrumentedMethod(redisBase, message, processor, server).ConfigureAwait(false));
                    }
                    catch (Exception ex)
                    {
                        scope?.Span.SetException(ex);
                        throw;
                    }
                }
            }

            return(await instrumentedMethod(redisBase, message, processor, server).ConfigureAwait(false));
        }
Esempio n. 11
0
        public static object Validate(
            object documentValidator,
            object originalQuery,
            object schema,
            object document,
            object rules,
            object userContext,
            object inputs,
            int opCode,
            int mdToken,
            long moduleVersionPtr)
        {
            if (documentValidator == null)
            {
                throw new ArgumentNullException(nameof(documentValidator));
            }

            const string methodName = nameof(Validate);

            // At runtime, get a Type object for GraphQL.ExecutionResult
            var documentValidatorInstanceType = documentValidator.GetType();

            try
            {
                var graphQLAssembly = AppDomain.CurrentDomain
                                      .GetAssemblies()
                                      .Single(a => a.GetName().Name.Equals(GraphQLAssemblyName));
            }
            catch (Exception ex)
            {
                // This shouldn't happen because the GraphQL assembly should have been loaded to construct various other types
                // profiled app will not continue working as expected without this method
                Log.Error(ex, $"Error finding types in the GraphQL assembly.");
                throw;
            }

            Func <object, object, object, object, object, object, object, object> instrumentedMethod;

            try
            {
                instrumentedMethod =
                    MethodBuilder <Func <object, object, object, object, object, object, object, object> >
                    .Start(moduleVersionPtr, mdToken, opCode, methodName)
                    .WithConcreteType(documentValidatorInstanceType)
                    .WithParameters(originalQuery, schema, document, rules, userContext, inputs)
                    .WithNamespaceAndNameFilters(
                        GraphQLValidationResultInterfaceName,
                        ClrNames.String,
                        "GraphQL.Types.ISchema",
                        "GraphQL.Language.AST.Document",
                        "System.Collections.Generic.IEnumerable`1",
                        ClrNames.Ignore,
                        "GraphQL.Inputs")
                    .Build();
            }
            catch (Exception ex)
            {
                Log.ErrorRetrievingMethod(
                    exception: ex,
                    moduleVersionPointer: moduleVersionPtr,
                    mdToken: mdToken,
                    opCode: opCode,
                    instrumentedType: GraphQLDocumentValidatorInterfaceName,
                    methodName: methodName,
                    instanceType: documentValidator.GetType().AssemblyQualifiedName);
                throw;
            }

            using (var scope = CreateScopeFromValidate(document))
            {
                try
                {
                    var validationResult = instrumentedMethod(documentValidator, originalQuery, schema, document, rules, userContext, inputs);
                    RecordExecutionErrorsIfPresent(scope.Span, "GraphQL.Validation.ValidationError", validationResult.GetProperty("Errors").GetValueOrDefault());
                    return(validationResult);
                }
                catch (Exception ex)
                {
                    scope?.Span.SetException(ex);
                    throw;
                }
            }
        }
        public static object BeginInvokeAction(
            object asyncControllerActionInvoker,
            object controllerContext,
            object actionName,
            object callback,
            object state,
            int opCode,
            int mdToken,
            long moduleVersionPtr)
        {
            if (asyncControllerActionInvoker == null)
            {
                throw new ArgumentNullException(nameof(asyncControllerActionInvoker));
            }

            Scope scope = null;

            try
            {
                if (HttpContext.Current != null)
                {
                    scope = CreateScope(controllerContext);
                    HttpContext.Current.Items[HttpContextKey] = scope;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Error instrumenting method {0}", "System.Web.Mvc.Async.IAsyncActionInvoker.BeginInvokeAction()");
            }

            Func <object, object, object, object, object, object> instrumentedMethod;

            try
            {
                var asyncActionInvokerType = asyncControllerActionInvoker.GetInstrumentedInterface(AsyncActionInvokerTypeName);

                instrumentedMethod = MethodBuilder <Func <object, object, object, object, object, object> >
                                     .Start(moduleVersionPtr, mdToken, opCode, nameof(BeginInvokeAction))
                                     .WithConcreteType(asyncActionInvokerType)
                                     .WithParameters(controllerContext, actionName, callback, state)
                                     .WithNamespaceAndNameFilters(
                    ClrNames.IAsyncResult,
                    "System.Web.Mvc.ControllerContext",
                    ClrNames.String,
                    ClrNames.AsyncCallback,
                    ClrNames.Object)
                                     .Build();
            }
            catch (Exception ex)
            {
                Log.ErrorRetrievingMethod(
                    exception: ex,
                    moduleVersionPointer: moduleVersionPtr,
                    mdToken: mdToken,
                    opCode: opCode,
                    instrumentedType: AsyncActionInvokerTypeName,
                    methodName: nameof(BeginInvokeAction),
                    instanceType: asyncControllerActionInvoker.GetType().AssemblyQualifiedName);
                throw;
            }

            try
            {
                // call the original method, inspecting (but not catching) any unhandled exceptions
                var response = instrumentedMethod(asyncControllerActionInvoker, controllerContext, actionName, callback, state);

                if (HttpContext.Current != null && scope != null)
                {
                    ServerTimingHeader.SetHeaders(scope.Span.Context, HttpContext.Current.Response, (resp, name, value) => resp.Headers.Add(name, value));
                }

                return(response);
            }
            catch (Exception ex)
            {
                scope?.Span.SetException(ex);
                throw;
            }
        }