public EndMethodDelegate BeforeWrappedMethod(TraceMethodInfo traceMethodInfo)
 {
     return(delegate(object returnValue, Exception ex)
     {
         Leave(traceMethodInfo, returnValue, ex);
     });
 }
Esempio n. 2
0
        public EndMethodDelegate BeforeWrappedMethod(TraceMethodInfo traceMethodInfo)
        {
            var multiplexer = traceMethodInfo.InvocationTarget;
            var message     = traceMethodInfo.MethodArguments[0];

            var config      = (string)ConfigPropertyFetcher.Fetch(multiplexer);
            var hostAndPort = GetHostAndPort(config);
            var rawCommand  = (string)CommandAndKeyPropertyFetcher.Fetch(message);

            var span = _tracer.BuildSpan("redis.command")
                       .AsChildOf(_tracer.ActiveSpan)
                       .WithTag(Tags.SpanKind, Tags.SpanKindClient)
                       .WithTag(Tags.Component, "StackExchange.Redis")
                       .WithTag("redis.raw_command", rawCommand)
                       .WithTag("out.host", hostAndPort.Item1)
                       .WithTag("out.port", hostAndPort.Item2)
                       .Start();

            traceMethodInfo.TraceContext = span;

            if (traceMethodInfo.MethodBase.Name == ExecuteSyncImpl)
            {
                return(delegate(object returnValue, Exception ex)
                {
                    Leave(traceMethodInfo, returnValue, ex);
                });
            }
            else
            {
                return(delegate(object returnValue, Exception ex)
                {
                    DelegateHelper.AsyncMethodEnd(Leave, traceMethodInfo, ex, returnValue);
                });
            }
        }
        public EndMethodDelegate BeforeWrappedMethod(TraceMethodInfo traceMethodInfo)
        {
            var request = (HttpRequestMessage)traceMethodInfo.MethodArguments[0];

            var scope = _tracer.BuildSpan("http.out")
                        .WithTag(Tags.SpanKind, Tags.SpanKindClient)
                        .WithTag(Tags.Component, "HttpClient")
                        .WithTag(Tags.HttpMethod, request.Method.ToString())
                        .WithTag(Tags.HttpUrl, request.RequestUri.ToString())
                        .WithTag(Tags.PeerHostname, request.RequestUri.Host)
                        .WithTag(Tags.PeerPort, request.RequestUri.Port)
                        .StartActive(false);

            _tracer.Inject(scope.Span.Context, BuiltinFormats.HttpHeaders, new HttpHeadersInjectAdapter(request.Headers));

            traceMethodInfo.TraceContext = scope;

            return(delegate(object returnValue, Exception ex)
            {
                DelegateHelper.AsyncMethodEnd(Leave, traceMethodInfo, ex, returnValue);

                // for async method , at method end restore active scope, important
                var tempScope = (IScope)traceMethodInfo.TraceContext;
                tempScope.Dispose();
            });
        }
 private static void TraceEnd(AsyncMethodEndDelegate endMethodDelegate,
                              TraceMethodInfo traceMethodInfo,
                              Task n)
 {
     if (n.IsFaulted)
     {
         var ex0 = n.Exception?.InnerException ?? new Exception("unknown exception");
         endMethodDelegate(traceMethodInfo, null, ex0);
     }
     else
     {
         if (n.IsCanceled)
         {
             endMethodDelegate(traceMethodInfo, null, CanceledException);
         }
         else
         {
             var methodInfo = traceMethodInfo.MethodBase as MethodInfo;
             if (methodInfo != null && methodInfo.ReturnType == typeof(Task))
             {
                 endMethodDelegate(traceMethodInfo, null, null);
             }
             else
             {
                 var ret = ((dynamic)n).Result;
                 endMethodDelegate(traceMethodInfo, ret, null);
             }
         }
     }
 }
Esempio n. 5
0
        public EndMethodDelegate BeforeWrappedMethod(TraceMethodInfo traceMethodInfo)
        {
            if (HttpRuntime.UsingIntegratedPipeline)
            {
                HttpContext context = (traceMethodInfo.InvocationTarget as HttpApplication)?.Context;
                if (context != null)
                {
                    if (context.Items["ClrProfiler.Trace.AspNet.TraceScope"] == null)
                    {
                        var extractedSpanContext = _tracer.Extract(BuiltinFormats.HttpHeaders, new RequestHeadersExtractAdapter(context.Request.Headers));

                        var scope = _tracer.BuildSpan("http.in")
                                    .AsChildOf(extractedSpanContext)
                                    .WithTag(Tags.SpanKind, Tags.SpanKindServer)
                                    .WithTag(Tags.Component, "AspNet")
                                    .WithTag(Tags.HttpMethod, context.Request.HttpMethod)
                                    .WithTag(Tags.HttpUrl, context.Request.Path.ToString())
                                    .WithTag(Tags.PeerHostname, context.Request.UserHostName)
                                    .StartActive();

                        context.Items["ClrProfiler.Trace.AspNet.TraceScope"] = scope;
                    }
                }
            }
            return(null);
        }
        public static void AsyncMethodEnd(AsyncMethodEndDelegate endMethodDelegate,
                                          TraceMethodInfo traceMethodInfo,
                                          Exception ex,
                                          object returnValue)
        {
            if (ex != null)
            {
                endMethodDelegate(traceMethodInfo, null, ex);
                return;
            }

            if (returnValue != null)
            {
                if (SynchronizationContext.Current != null)
                {
                    ((Task)returnValue).ContinueWith(n =>
                    {
                        TraceEnd(endMethodDelegate, traceMethodInfo, n);
                    }, TaskScheduler.FromCurrentSynchronizationContext());
                }
                else
                {
                    ((Task)returnValue).ContinueWith(n =>
                    {
                        TraceEnd(endMethodDelegate, traceMethodInfo, n);
                    }, TaskContinuationOptions.ExecuteSynchronously);
                }
            }
        }
Esempio n. 7
0
        private void Leave(TraceMethodInfo traceMethodInfo, object ret, Exception ex)
        {
            var span = (ISpan)traceMethodInfo.TraceContext;

            if (ex != null)
            {
                span.SetException(ex);
            }
            span.Finish();
        }
Esempio n. 8
0
        private void Leave(TraceMethodInfo traceMethodInfo, object ret, Exception ex)
        {
            var scope = (IScope)traceMethodInfo.TraceContext;

            if (ex != null)
            {
                scope.Span.SetException(ex);
            }
            scope.Dispose();
        }
Esempio n. 9
0
        public bool CanWrap(TraceMethodInfo traceMethodInfo)
        {
            var invocationTargetType = traceMethodInfo.Type;
            var assemblyName         = invocationTargetType.Assembly.GetName().Name;

            if (AssemblyNames.Contains(assemblyName) && TypeName == invocationTargetType.FullName)
            {
                if (traceMethodInfo.MethodBase.Name == ExecuteAsyncImpl || traceMethodInfo.MethodBase.Name == ExecuteSyncImpl)
                {
                    return(true);
                }
            }
            return(false);
        }
        public bool CanWrap(TraceMethodInfo traceMethodInfo)
        {
            var invocationTargetType = traceMethodInfo.Type;
            var assemblyName         = invocationTargetType.Assembly.GetName().Name;

            if (assemblyName == AssemblyName && TypeName == invocationTargetType.FullName)
            {
                if (traceMethodInfo.MethodBase.Name == MethodName)
                {
                    return(true);
                }
            }

            return(false);
        }
        private void Leave(TraceMethodInfo traceMethodInfo, object ret, Exception ex)
        {
            var scope = (IScope)traceMethodInfo.TraceContext;

            if (ex != null)
            {
                scope.Span.SetException(ex);
            }

            var response = (HttpResponseMessage)ret;

            if (response != null)
            {
                scope.Span.SetTag(Tags.HttpStatus, (int)response.StatusCode);
            }

            scope.Span.Finish();
        }
Esempio n. 12
0
        public EndMethodDelegate BeforeWrappedMethod(TraceMethodInfo traceMethodInfo)
        {
            var dbCommand = (DbCommand)traceMethodInfo.InvocationTarget;
            var scope     = _tracer.BuildSpan("mysql.command")
                            .WithTag(Tags.SpanKind, Tags.SpanKindClient)
                            .WithTag(Tags.Component, "MySql.Data")
                            .WithTag(Tags.DbInstance, dbCommand.Connection.ConnectionString)
                            .WithTag(Tags.DbStatement, dbCommand.CommandText)
                            .WithTag(TagMethod, traceMethodInfo.MethodBase.Name)
                            .StartActive();

            traceMethodInfo.TraceContext = scope;

            return(delegate(object returnValue, Exception ex)
            {
                Leave(traceMethodInfo, returnValue, ex);
            });
        }
Esempio n. 13
0
        public EndMethodDelegate BeforeWrappedMethod(TraceMethodInfo traceMethodInfo)
        {
            var dbCommand = (DbCommand)traceMethodInfo.InvocationTarget;
            var scope     = _tracer.BuildSpan("mysql.command")
                            .WithTag(Tags.SpanKind, Tags.SpanKindClient)
                            .WithTag(Tags.Component, "MySqlConnector")
                            .WithTag(Tags.DbInstance, dbCommand.Connection.ConnectionString)
                            .WithTag(Tags.DbStatement, dbCommand.CommandText)
                            .WithTag(TagMethod, traceMethodInfo.MethodBase.Name)
                            .StartActive(false);

            traceMethodInfo.TraceContext = scope;

            return(delegate(object returnValue, Exception ex)
            {
                DelegateHelper.AsyncMethodEnd(Leave, traceMethodInfo, ex, returnValue);

                // for async method , at method end restore active scope, important
                var tempScope = (IScope)traceMethodInfo.TraceContext;
                tempScope.Dispose();
            });
        }
 public EndMethodDelegate BeforeWrappedMethod(TraceMethodInfo traceMethodInfo)
 {
     if (HttpRuntime.UsingIntegratedPipeline)
     {
         HttpContext context = traceMethodInfo.InvocationTarget as HttpContext;
         if (context != null)
         {
             var scope = context.Items["ClrProfiler.Trace.AspNet.TraceScope"] as IScope;
             context.Items.Remove("ClrProfiler.Trace.AspNet.TraceScope");
             if (scope != null)
             {
                 scope.Span.SetTag(Tags.HttpStatus, context.Response.StatusCode);
                 if (context.Response.StatusCode >= 400)
                 {
                     scope.Span.SetTag(Tags.Error, true);
                 }
                 //asyncLocal lost , so use scope.Span.Finish()
                 scope.Span.Finish();
             }
         }
     }
     return(null);
 }
        private void Leave(TraceMethodInfo traceMethodInfo, object ret, Exception ex)
        {
            var serviceCollection = (ServiceCollection)ret;

            serviceCollection.AddSingleton <IStartupFilter>(n => new ProfilerStartupFilter(_tracer));
        }
Esempio n. 16
0
 public EndMethodDelegate BeforeWrappedMethod(TraceMethodInfo traceMethodInfo)
 {
     HttpWebRequestDiagnostic.Instance.Initialize(_tracer);
     return(null);
 }