コード例 #1
0
        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            var spanContext = _spanContextExtractor
                              .Extract(context.Request)
                              .Sample(_sampler);

            var spanBuilder = new SpanBuilder(spanContext);

            spanBuilder.Start()
            .Name(context.Request.Method)
            .Kind(SpanKind.Server)
            .Tag("host", context.Request.Host.Value)
            .Tag("resource", context.Request.Path.Value)
            .Tag("method", context.Request.Method)
            .WithLocalEndpoint(new Endpoint
            {
                ServiceName = _localEndpointName
            });

            _spanContextAccessor.SaveContext(spanContext);

            try
            {
                await next(context);
            }
            catch (Exception ex)
            {
                spanBuilder.Error(ex.Message);
            }
            finally
            {
                var span = spanBuilder
                           .End()
                           .Build();

                try
                {
                    _dispatcher.Dispatch(span);
                }
                catch (DispatchException)
                {
                    // ignore
                }
            }
        }
コード例 #2
0
        public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
        {
            var spanContext = _spanContextExtractor
                              .Extract(WebOperationContext.Current?.IncomingRequest);

            spanContext.Sample(_sampler);

            var spanBuilder = new SpanBuilder(spanContext);

            spanBuilder.Start()
            .Tag("action", request.Headers.Action)
            .Kind(SpanKind.Server)
            .WithLocalEndpoint(new Endpoint
            {
                ServiceName = _localEndpointName
            });

            _spanContextAccessor.SaveContext(spanContext);

            return(spanBuilder);
        }