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); }
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 EndRequest(object sender, EventArgs e) { IManagedTracer tracer = TracerManager.GetCurrentTracer(); if (tracer == null) { return; } // End the span and annotate it with information from the current response. tracer.AnnotateSpan(Labels.FromHttpResponse(HttpContext.Current.Response)); tracer.EndSpan(); }
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); }
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> /// Gets the current <see cref="IManagedTracer"/> for the given request. /// </summary> public static IManagedTracer GetCurrentTracer() { return(TracerManager.GetCurrentTracer() ?? DoNothingTracer.Instance); }