public void FromGoogleTrace() { var oldTracer = ContextTracerManager.GetCurrentTracer(); try { string traceId = "dummy_trace_id"; ulong spanId = 0x12D687; // The spanId set on the log entry should confirm to x16 // format so that the backend can really associate the log entry // to the span. string expectedSpanId = "000000000012d687"; ContextTracerManager.SetCurrentTracer(MockTracer(traceId, spanId)); var traceContext = TraceContextForLogEntry.FromGoogleTrace(); Assert.Equal(traceId, traceContext.TraceId); Assert.Equal(expectedSpanId, traceContext.SpanId); } finally { ContextTracerManager.SetCurrentTracer(oldTracer); } }
public void FromGoogleTrace_NoTrace() { var oldTracer = ContextTracerManager.GetCurrentTracer(); try { ContextTracerManager.SetCurrentTracer(MockTracer()); Assert.Null(TraceContextForLogEntry.FromGoogleTrace()); } finally { ContextTracerManager.SetCurrentTracer(oldTracer); } }
public void GetCurrentTraceContext() { string traceId = "105445aa7843bc8bf206b12000100f00"; ulong spanId = 0x12D687; // The spanId set on the log entry should confirm to x16 // format so that the backend can really associate the log entry // to the span. string expectedSpanId = "000000000012d687"; IServiceProvider serviceProvider = MockServiceProvider(traceId, spanId, true); GoogleTraceProvider traceProvider = new GoogleTraceProvider(); TraceContextForLogEntry traceContext = traceProvider.GetCurrentTraceContext(serviceProvider); Assert.Equal(traceId, traceContext.TraceId); Assert.Equal(expectedSpanId, traceContext.SpanId); }
private void SetTraceAndSpanIfAny(LogEntry entry) { if (_traceTarget is null) { return; } // If there's currently a Google trace and span use that one. // This means that the Google Trace component of the diagnostics library // has been initialized. // Else attempt to use an external trace context. if ((TraceContextForLogEntry.FromGoogleTrace() ?? TraceContextForLogEntry.FromExternalTrace(_serviceProvider)) is TraceContextForLogEntry trace) { entry.Trace = _traceTarget.GetFullTraceName(trace.TraceId); entry.TraceSampled = true; entry.SpanId = trace.SpanId; } }
public void FromGoogleTrace_NoSpan() { var oldTracer = ContextTracerManager.GetCurrentTracer(); try { string traceId = "dummy_trace_id"; ContextTracerManager.SetCurrentTracer(MockTracer(traceId)); var traceContext = TraceContextForLogEntry.FromGoogleTrace(); Assert.Equal(traceId, traceContext.TraceId); Assert.Null(traceContext.SpanId); } finally { ContextTracerManager.SetCurrentTracer(oldTracer); } }
/// <inheritdoc/> public TraceContextForLogEntry GetCurrentTraceContext(IServiceProvider serviceProvider) => TraceContextForLogEntry.FromGoogleTraceHeader(serviceProvider);