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
                }
            }
        }