public static IApplicationBuilder UseDataDogTracing(this IApplicationBuilder app, TraceSource source, TraceOptions options) => app.Use(async(context, next) =>
 {
     var resource = context.Request.Host.Host;
     var path     = context.Request.Path.HasValue ? context.Request.Path.Value : string.Empty;
     using (var span = source.Begin("aspnet.request", options.ServiceName, resource, "web"))
         using (var scope = new TraceContextScope(span))
         {
             if (options.AnalyticsEnabled)
             {
                 span.SetMeta("_dd1.sr.eausr", "true");
             }
             span.SetMeta("http.method", context.Request.Method);
             span.SetMeta("http.path", path);
             span.SetMeta("http.query", context.Request.QueryString.HasValue ? context.Request.QueryString.Value : string.Empty);
             try
             {
                 await next();
             }
             catch (Exception ex)
             {
                 span.SetError(ex);
                 throw;
             }
             span.SetMeta("http.status_code", context.Response.StatusCode.ToString());
         }
 });
示例#2
0
文件: Program.cs 项目: ftlab/WCFTrace
        static void Main(string[] args)
        {
            Console.WriteLine("starting sample runner");

            using (var scope = new TraceContextScope("Пример", TraceContextMode.New))
            {
                //Childs = new List<Process>() {
                //Process.Start(nameof(EchoApp))
                //, Process.Start(nameof(HelloApp))};

                AppDomain.CurrentDomain.ProcessExit        += CurrentDomain_ProcessExit;
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                Console.WriteLine("wait...");
                Thread.Sleep(TimeSpan.FromSeconds(2));

                using (var echo = new EchoClient())
                    echo.Echo("Hello");

                using (var hello = new HelloClient())
                    hello.Hello();

                var txt = scope.Root.ToString();
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
示例#3
0
        public void Hello()
        {
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("Hello");
            Console.ResetColor();

            using (var dbscope = new TraceContextScope("бд"))
            {
                Thread.Sleep(TimeSpan.FromSeconds(1));

                TraceContext.SetProperty("cs", "connection string");
            }

            using (var echo = new EchoClient())
                echo.Echo("вызов echo");
        }
示例#4
0
        /// <summary>
        /// Перед отправкой сообщения включаем в заголовок информацию о текущей трассировке
        /// </summary>
        /// <param name="request">запрос</param>
        /// <param name="channel">канал</param>
        /// <returns></returns>
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            var scope = TraceContextScope.Current;

            if (scope == null)
            {
                return(null);
            }

            var action = request.Headers.Action;

            action = action.Replace("http://tempuri.org/", "");

            var id     = scope.Id;
            var @event = TraceEvent.Create(id: id
                                           , name: "call> " + action);

            var callScope = new TraceContextScope(id, @event, TraceContextMode.Add);

            var index = request.Headers.FindHeader(TraceMeHeader.HeaderName, Namespace.Main);

            if (index > -1)
            {
                request.Headers.RemoveAt(index);
            }

            var header = MessageHeader.CreateHeader(
                TraceMeHeader.HeaderName, Namespace.Main
                , new TraceMeHeader()
            {
                Id = id,
            });

            request.Headers.Add(header);
            return(callScope);
        }