Exemplo n.º 1
0
        public static void UseMyTracingMiddlewareOfAspNetCore(
            this MicropartOfCallChainAsZipkinBuilder micropartOfCallChainAsZipkinBuilder,
            IApplicationBuilder app)
        {
            var extractor = new ZipkinHttpTraceExtractor();

            app.Use(async(context, next) =>
            {
                var request           = context.Request;
                var httpRequestFilter = app.ApplicationServices.GetService <IMicroserviceFilterManager <HttpRequestFilter, HttpRequest> >();
                if (httpRequestFilter.ShouldBeFiltered(request))
                {
                    return;
                }

                if (!extractor.TryExtract(request.Headers, (c, key) => c[key], out var trace))
                {
                    trace = Trace.Create();
                }
                Trace.Current = trace;
                using (var serverTrace = new ServerTrace(AppInfoProvider.Service.Name, $"{request.Path}/{request.Method}"))
                {
                    trace.Record(Annotations.Tag("http.host", request.Host.ToString()));
                    trace.Record(Annotations.Tag("http.uri", UriHelper.GetDisplayUrl(request)));
                    trace.Record(Annotations.Tag("http.path", request.Path));
                    await serverTrace.TracedActionAsync(next());
                }
            });
        }
Exemplo n.º 2
0
        public static void UseTracing(this IApplicationBuilder app, string serviceName,
                                      Func <HttpContext, string> getRpc = null)
        {
            getRpc = getRpc ?? (context => context.Request.Method);
            var extractor = Propagations.B3String.Extractor <IHeaderDictionary>((carrier, key) => carrier[key]);

            app.Use(async(context, next) =>
            {
                var request      = context.Request;
                var traceContext = extractor.Extract(request.Headers);

                var trace     = traceContext == null ? Trace.Create() : Trace.CreateFromId(traceContext);
                Trace.Current = trace;
                using (var serverTrace = new ServerTrace(serviceName, getRpc(context)))
                {
                    if (request.Host.HasValue)
                    {
                        trace.Record(Annotations.Tag("http.host", request.Host.ToString()));
                    }
                    trace.Record(Annotations.Tag("http.uri", UriHelper.GetDisplayUrl(request)));
                    trace.Record(Annotations.Tag("http.path", request.Path));
                    await serverTrace.TracedActionAsync(next());
                }
            });
        }
Exemplo n.º 3
0
        public async Task Invoke(HttpContext context)
        {
            var trace = Trace.Create();

            Trace.Current = trace;
            using (var serverTrace = new ServerTrace(_serviceName, context.Request.Method))
            {
                trace.Record(Annotations.Tag("http.host", context.Request.Host.ToString()));
                trace.Record(Annotations.Tag("http.path", context.Request.Path));
                await serverTrace.TracedActionAsync(_next.Invoke(context));
            }
        }
Exemplo n.º 4
0
        public override async Task Invoke(IOwinContext context)
        {
            var traceContext = traceExtractor.Extract(context.Request.Headers);
            var trace        = traceContext == null?Trace.Create() : Trace.CreateFromId(traceContext);

            Trace.Current = trace;

            using (var serverTrace = new ServerTrace(this.serviceName, context.Request.Method))
            {
                trace.Record(Annotations.Tag("http.host", context.Request.Host.Value));
                trace.Record(Annotations.Tag("http.url", context.Request.Uri.AbsoluteUri));
                trace.Record(Annotations.Tag("http.path", context.Request.Uri.AbsolutePath));

                await serverTrace.TracedActionAsync(Next.Invoke(context));
            }
        }
Exemplo n.º 5
0
        public override async Task Invoke(IOwinContext context)
        {
            Trace trace;

            if (!this.traceExtractor.TryExtract(context.Request.Headers, (dic, k) => string.Join(",", dic[k]), out trace))
            {
                trace = Trace.Create();
            }

            Trace.Current = trace;

            using (var serverTrace = new ServerTrace(this.serviceName, context.Request.Method))
            {
                trace.Record(Annotations.Tag("http.host", context.Request.Host.Value));
                trace.Record(Annotations.Tag("http.url", context.Request.Uri.AbsoluteUri));
                trace.Record(Annotations.Tag("http.path", context.Request.Uri.AbsolutePath));

                await serverTrace.TracedActionAsync(Next.Invoke(context));
            }
        }
Exemplo n.º 6
0
        public static void UseTracing(this IApplicationBuilder app, string serviceName)
        {
            var extractor = new ZipkinHttpTraceExtractor();

            app.Use(async(context, next) =>
            {
                Trace trace;
                var request = context.Request;
                if (!extractor.TryExtract(request.Headers, (c, key) => c[key], out trace))
                {
                    trace = Trace.Create();
                }
                Trace.Current = trace;
                using (var serverTrace = new ServerTrace(serviceName, request.Method))
                {
                    trace.Record(Annotations.Tag("http.host", request.Host.ToString()));
                    trace.Record(Annotations.Tag("http.uri", UriHelper.GetDisplayUrl(request)));
                    trace.Record(Annotations.Tag("http.path", request.Path));
                    await serverTrace.TracedActionAsync(next());
                }
            });
        }