Bridge between C# System.Diagnostics
tracing and OpenTracing
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
.
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).
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.
TraceEvent(TraceEventType.Start, id: 1, ...)
TraceEvent(TraceEventType.Stop, id: 2, ...)
TraceData(TraceEventType.Information, id: 3, data: IEnumerable<KeyValuePair<string, object>>)
TraceData(TraceEventType.Information, id: 4, data: KeyValuePair<string, object>)
CorrelationManagerHook.PipeCorrelationManagerToOpenTracing()
Trace.Listeners.Add(new OpenTracingTraceListener());
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);