Esempio n. 1
0
        /// <summary>
        /// Sends the given request. If tracing is initialized and enabled the outgoing request is
        /// traced and the trace header is added to the request.
        /// </summary>
        protected override Task <HttpResponseMessage> SendAsync(
            HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var tracer = _managedTracerFactory();

            if (tracer.GetCurrentTraceId() == null)
            {
                return(base.SendAsync(request, cancellationToken));
            }

            var traceHeader = TraceHeaderContext.Create(
                tracer.GetCurrentTraceId(), tracer.GetCurrentSpanId() ?? 0, true);

            request.Headers.Add(TraceHeaderContext.TraceHeader, traceHeader.ToString());

            return(tracer.RunInSpanAsync(
                       async() =>
            {
                tracer.AnnotateSpan(TraceLabels.FromHttpRequestMessage(request));
                var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
                tracer.AnnotateSpan(TraceLabels.FromHttpResponseMessage(response));
                return response;
            },
                       request.RequestUri.ToString()));
        }
        /// <summary>
        /// Sends the given request.  If tracing is initialized and enabled the outgoing request is
        /// traced and the trace header is added to the request.
        /// </summary>
        protected override async Task <HttpResponseMessage> SendAsync(
            HttpRequestMessage request, CancellationToken cancellationToken)
        {
            if (_tracer.GetCurrentTraceId() == null)
            {
                return(await base.SendAsync(request, cancellationToken).ConfigureAwait(false));
            }

            var traceHeader = TraceHeaderContext.Create(
                _tracer.GetCurrentTraceId(), _tracer.GetCurrentSpanId() ?? 0, true);

            request.Headers.Add(TraceHeaderContext.TraceHeader, traceHeader.ToString());

            _tracer.StartSpan(request.RequestUri.ToString());
            try
            {
                return(await base.SendAsync(request, cancellationToken).ConfigureAwait(false));
            }
            catch (Exception e)
            {
                StackTrace stackTrace = new StackTrace(e, true);
                _tracer.SetStackTrace(stackTrace);
                throw;
            }
            finally
            {
                _tracer.EndSpan();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Sends the given request.  If tracing is initialized and enabled the outgoing request is
        /// traced and the trace header is added to the request.
        /// </summary>
        protected override Task <HttpResponseMessage> SendAsync(
            HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var tracer = _managedTracerFactory();

            if (tracer.GetCurrentTraceId() == null)
            {
                return(base.SendAsync(request, cancellationToken));
            }

            var traceHeader = TraceHeaderContext.Create(
                tracer.GetCurrentTraceId(), tracer.GetCurrentSpanId() ?? 0, true);

            request.Headers.Add(TraceHeaderContext.TraceHeader, traceHeader.ToString());

            return(tracer.RunInSpanAsync(
                       () => base.SendAsync(request, cancellationToken),
                       request.RequestUri.ToString()));
        }