ndrwrbgs / OpenTracing-System.Diagnostics

Bridge between C# `System.Diagnostics` tracing and `OpenTracing`
MIT License
0 stars 1 forks source link

NuGet

OpenTracing-System.Diagnostics

Bridge between C# System.Diagnostics tracing and OpenTracing

CorrelationManagerHook

Target audience: Folks who have code instrumented with Trace.Correlationmanager.StartLogicalOperation and Trace.CorrelationManager.StopLogicalOperation but want those calls to go to OpenTracing.

Use CorrelationManagerHook.PipeCorrelationManagerToOpenTracing() to establish the connection so that all calls to Trace.CorrelationManager are passed to GlobalTracer.Instance.

OpenTracingTraceListener

Creates a TraceListener that will forward the writes to GlobalTracer.Instance.ActiveSpan.Log. This is useful if your exiting code contains Trace.Write events that you wish to have proper context for (having them be logged to the ISpan rather than ambiently).

OpenTracingTraceSource

Creates a ITracer/TraceSource pair that are tied together. The ITracer returned is the source of the events, and they're sent to the TraceSource's .Listeners as TraceEvent, TraceInformation, and TraceData calls.

Usage

  1. Hook Trace.CorrelationManager to GlobalTracer to capture legacy calls CorrelationManagerHook.PipeCorrelationManagerToOpenTracing()
  2. Hook Trace to GlobalTracer to capture Trace messages Trace.Listeners.Add(new OpenTracingTraceListener());
  3. [Optional] Hook your-logging to GlobalTracer to capture those calls (as desired)
  4. Hook GlobalTracer to an output system of your choosing. E.g. to ConsoleListener

    var pair = OpenTracingTraceSource.CreateTracerTraceSourcePair();
    var traceSourceSink = pair.TraceSourceSink;
    var tracerSource = pair.TracerSource;
    
    // Tell the sink to write to console
    traceSourceSink.Listeners.Add(new ConsoleTraceListener());
    
    // Tell OT to write to the sink
    GlobalTracer.Register(tracerSource);