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); }
internal void EndRequest(object sender, EventArgs e) { ISpan span = ContextInstanceManager.Get <ISpan>(); if (span == null) { return; } // End the span and annotate it with information from the current response. span.AnnotateSpan(Labels.FromHttpResponse(HttpContext.Current.Response)); span.Dispose(); }