opentracing-cpp
opentracing-cpp copied to clipboard
Method to reset the global tracer?
Hello, Is it a conscious choice not to have provided a ResetGlobal method or equivalent on the tracer? I suppose the shared_ptr is cleaned up at global shutdown of an application, but that limits the opportunities for "controlled" init/cleanup of the singleton.
Would this be the preferred way to do it with the current opentracing code?
void closeOpenTracer()
{
opentracing::Tracer::Global()->Close();
// How do we delete the global tracer pointer?
// There is no public method to do so
//std::shared_ptr<opentracing::Tracer> t;
// Reinit with an empty shared pointer ?
//opentracing::Tracer::InitGlobal(t);
}
Thank you, Regards, Emmanuel.
opentracing::Tracer::InitGlobal({});
However: Tracer::IsGlobalTracerRegistered()
will incorrectly return true
after this. Should probably be fixed (and simplified).
Or use InitGlobal(nullptr)
I think the intention of IsGobalTracerRegistered was to query whether a global tracer was ever registered, but maybe @MikeGoldsmith can clarify?
The intention was to enable an application, or other library, to detect if a tracer has explicitly registered. Shutdown / cleanup wasn't part of the original design.
I think having a ResetGlobal
function to cleanup the registered tracer that also sets IsGlobalTracerRegistered to false makes sense.
Wouldn't returning a null pointer (default-constructed shared_ptr
) have exactly the same semantics?
IsGlobalTracerRegistered uses an internal bool to determine if a tracer has been registered and is set when InitGlobal is called. Calling InitGlobal(nullptr) would not reset the flag.
We have a bool property to determine if a tracer was registered because we want to know if the app intentionally registers a tracer, and is not just a null or default noop tracer.
Adding ResetGlobal
is explicit where it sets the tracer to a nullptr and resets the flag to false and to be used during app cleanup.