public object BeforeSendRequest(ref Message request, IClientChannel channel) { var spanContext = _spanContextAccessor.HasContext() ? _spanContextAccessor .GetContext() .CreateChild() : new SpanContext(); spanContext.Sample(_sampler); var httpRequest = ExtractHttpRequest(request); // Inject X-B3 headers to the outgoing request _spanContextInjector.Inject(httpRequest, spanContext); var spanBuilder = new SpanBuilder(spanContext); spanBuilder.Start() .Kind(SpanKind.Client) .Tag("action", request.Headers.Action) .WithRemoteEndpoint(new Endpoint { ServiceName = _remoteServiceName }); return(spanBuilder); }
protected override async Task <HttpResponseMessage> SendAsync( HttpRequestMessage request, CancellationToken cancellationToken) { var spanContext = _spanContextAccessor.HasContext() ? _spanContextAccessor .GetContext() .CreateChild() : new SpanContext(); spanContext.Sample(_sampler); var spanBuilder = new SpanBuilder(spanContext); spanBuilder.Start() .Name(request.Method.Method) .Kind(SpanKind.Client) .Tag("uri", request.RequestUri.OriginalString) .Tag("method", request.Method.Method) .WithRemoteEndpoint(new Endpoint { ServiceName = _remoteEndpointName }); // Add X-B3 headers to the request request = _spanContextInjector.Inject(request, spanContext); try { return(await base.SendAsync(request, cancellationToken)); } catch (Exception ex) { spanBuilder.Error(ex.Message); throw; } finally { var span = spanBuilder .End() .Build(); try { _dispatcher.Dispatch(span); } catch (DispatchException) { // ignore } } }