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)); }
/// <summary> /// Create a new <see cref="TraceHeaderTraceOptionsFactory"/>. /// </summary> public TraceOptions CreateOptions() => CreateOptions(TraceHeaderContext.FromRequest(HttpContext.Current.Request));