Exemple #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));
        }
 /// <summary>
 /// Create a new <see cref="TraceHeaderTraceOptionsFactory"/> from a <see cref="TraceHeaderContext"/>
 /// </summary>
 public TraceOptions CreateOptions(TraceHeaderContext context)
 {
     GaxPreconditions.CheckNotNull(context, nameof(context));
     return(TraceOptions.Create(context.ShouldTrace));
 }
 /// <summary>
 /// Create a new <see cref="TraceHeaderTraceOptionsFactory"/>.
 /// </summary>
 public TraceOptions CreateOptions() => CreateOptions(TraceHeaderContext.FromRequest(HttpContext.Current.Request));