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?.ShouldTrace(request));

            var tracer = _tracerFactory.CreateTracer(headerContext);

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

            TracerManager.SetCurrentTracer(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.
            tracer.StartSpan(HttpContext.Current.Request.Path);
            tracer.AnnotateSpan(Labels.FromHttpRequest(HttpContext.Current.Request));
            tracer.AnnotateSpan(Labels.AgentLabel);
        }
Esempio n. 2
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));
        }
        private void BeginRequest(object sender, EventArgs e)
        {
            var headerContext = TraceHeaderContextUtils.CreateContext(HttpContext.Current.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);
        }
Esempio 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);
        }