Beispiel #1
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.
            Trace trace = new Trace()
            {
                ProjectId = _projectId,
                TraceId   = headerContext.TraceId ?? _traceIdfactory.NextId(),
            };
            IManagedTracer tracer = SimpleManagedTracer.Create(_bufferingConsumer, 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));
        }
Beispiel #2
0
        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();
        }
Beispiel #3
0
 /// <summary>
 /// Gets the current <see cref="IManagedTracer"/> for the given request.
 /// </summary>
 public static IManagedTracer GetCurrentTracer()
 {
     return(TracerManager.GetCurrentTracer() ?? DoNothingTracer.Instance);
 }