Exemplo n.º 1
0
        internal void BeginRequest(object sender, EventArgs e)
        {
            var    request       = HttpContext.Current.Request;
            string header        = request.Headers.Get(TraceHeaderContext.TraceHeader);
            var    headerContext = TraceHeaderContext.FromHeader(
                header, () => _traceFallbackPredicate?.ShouldTrace(request));

            var tracer = _tracerFactory(headerContext);

            if (tracer.GetCurrentTraceId() == null)
            {
                return;
            }

            ContextInstanceManager.Set(tracer);

            if (headerContext.TraceId != null)
            {
                // Set the updated trace header on the response.
                var updatedHeaderContext = TraceHeaderContext.Create(
                    tracer.GetCurrentTraceId(), tracer.GetCurrentSpanId() ?? 0, true);
                HttpContext.Current.Response.Headers.Set(
                    TraceHeaderContext.TraceHeader, updatedHeaderContext.ToString());
            }

            // Start the span and annotate it with information from the current request.
            var span = tracer.StartSpan(HttpContext.Current.Request.Path);

            ContextInstanceManager.Set(span);
            tracer.AnnotateSpan(Labels.FromHttpRequest(HttpContext.Current.Request));
            tracer.AnnotateSpan(Labels.AgentLabel);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a <see cref="TraceHeaderContext"/> from an <see cref="HttpRequest"/>.
        /// </summary>
        public static TraceHeaderContext CreateContext(HttpRequest request)
        {
            GaxPreconditions.CheckNotNull(request, nameof(request));
            string header = request.Headers.Get(TraceHeaderContext.TraceHeader);

            return(TraceHeaderContext.FromHeader(header));
        }
Exemplo n.º 3
0
        private void BeginRequest(object sender, EventArgs e)
        {
            TraceHeaderContext headerContext = TraceHeaderContext.FromRequest(HttpContext.Current.Request);
            TraceOptions       headerOptions = _headerFactory.CreateOptions(headerContext);

            // If the trace header says to trace or if the rate limiter allows tracing continue.
            if (!headerOptions.ShouldTrace)
            {
                TraceOptions options = _rateFactory.CreateOptions();
                if (!options.ShouldTrace)
                {
                    return;
                }
            }

            // Create and set the tracer for the request.
            TraceProto trace = new TraceProto
            {
                ProjectId = _projectId,
                TraceId   = headerContext.TraceId ?? _traceIdfactory.NextId(),
            };
            IManagedTracer tracer = SimpleManagedTracer.Create(_consumer, trace, headerContext.SpanId);

            TracerManager.SetCurrentTracer(tracer);

            // Start the span and annotate it with information from the current request.
            tracer.StartSpan(HttpContext.Current.Request.Path);
            tracer.AnnotateSpan(Labels.FromHttpRequest(HttpContext.Current.Request));
        }
Exemplo n.º 4
0
        private void BeginRequest(object sender, EventArgs e)
        {
            var    request       = HttpContext.Current.Request;
            string header        = request.Headers.Get(TraceHeaderContext.TraceHeader);
            var    headerContext = TraceHeaderContext.FromHeader(
                header, () => _traceFallbackPredicate?.Invoke(request));

            var tracer = _tracerFactory.CreateTracer(headerContext);

            if (tracer.GetCurrentTraceId() == null)
            {
                return;
            }

            TracerManager.SetCurrentTracer(tracer);

            // Start the span and annotate it with information from the current request.
            tracer.StartSpan(HttpContext.Current.Request.Path);
            tracer.AnnotateSpan(Labels.FromHttpRequest(HttpContext.Current.Request));
            tracer.AnnotateSpan(Labels.AgentLabel);
        }
 /// <summary>
 /// Create a new <see cref="TraceHeaderTraceOptionsFactory"/> from a <see cref="TraceHeaderContext"/>
 /// </summary>
 public TraceOptions CreateOptions(TraceHeaderContext context)
 {
     GaxPreconditions.CheckNotNull(context, nameof(context));
     return(TraceOptions.Create(context.ShouldTrace));
 }
 /// <summary>
 /// Create a new <see cref="TraceHeaderTraceOptionsFactory"/>.
 /// </summary>
 public TraceOptions CreateOptions() => CreateOptions(TraceHeaderContext.FromRequest(HttpContext.Current.Request));