specification
specification copied to clipboard
API for minimizing no-tracer / non-sampled overhead
trafficstars
Continuing the discussion from https://github.com/opentracing/opentracing.io/issues/31
cc: @dkuebric @bensigelman @bogdandrutu @yurishkuro
In .NET, most new libraries/frameworks provide instrumentation hooks via an observer pattern through a type called DiagnosticSource. Having a "no-tracer"-check (e.g. tracer.isEnabled()) would allow us to not even create a subscription and would therefore result in a zero-overhead situation.
It's already possible to do this by checking the tracer instance type but this is pretty ugly especially due to how GlobalTracer works in Java/C# (it wraps the underlying tracer):
public static bool IsNoopTracer(ITracer tracer)
{
// This will be "if (tracer is NoopTracer)" once an open PR in opentracing-csharp gets merged.
if (tracer == NoopTracerFactory.Create())
return true;
// There's currently no way to check the underlying tracer on the instance
// so we have to check the static method.
if (tracer is GlobalTracer && !GlobalTracer.IsRegistered())
return true;
return false;
}
Having a better way to do this would be nice.