示例#1
0
        /// <summary>
        /// Sends the given request. If tracing is initialized and enabled the outgoing request is traced
        /// and the trace context is propagated.
        /// </summary>
        protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var tracer = _managedTracerFactory();

            if (SimpleTraceContext.FromTracer(tracer) is SimpleTraceContext traceContext)
            {
                _traceContextPropagator(request, traceContext);

                return(tracer.RunInSpanAsync(
                           async() =>
                {
                    try
                    {
                        tracer.AnnotateSpan(TraceLabels.FromHttpRequestMessage(request));
                        var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
                        tracer.AnnotateSpan(TraceLabels.FromHttpResponseMessage(response));
                        return response;
                    }
                    finally
                    {
                        tracer.AnnotateSpan(_customLabels);
                    }
                },
                           request.RequestUri.ToString()));
            }

            return(base.SendAsync(request, cancellationToken));
        }
示例#2
0
 /// <summary>
 /// Gets the current <see cref="ITraceContext"/> as defined by the <see cref="GetCurrentTracer"/>
 /// or null if the current trace context is not known at the time.
 /// </summary>
 public static ITraceContext GetCurrentTraceContext() =>
 SimpleTraceContext.FromTracer(GetCurrentTracer());