/// <inheritdoc />
        public void SetStackTrace(StackTrace stackTrace)
        {
            GaxPreconditions.CheckNotNull(stackTrace, nameof(stackTrace));
            CheckStackNotEmpty();

            AnnotateSpan(TraceLabels.FromStackTrace(stackTrace));
        }
Exemple #2
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()));
        }
Exemple #3
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));
        }
Exemple #4
0
        /// <inheritdoc />
        public void SetStackTrace(StackTrace stackTrace)
        {
            GaxPreconditions.CheckNotNull(stackTrace, nameof(stackTrace));
            var currentStack = TraceStack;

            CheckStackNotEmpty(currentStack);

            AnnotateSpan(currentStack.Peek(), TraceLabels.FromStackTrace(stackTrace));
        }
 /// <inheritdoc />
 public void SetStackTrace(StackTrace stackTrace) =>
 AnnotateSpan(TraceLabels.FromStackTrace(stackTrace));