Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Method to reset the global tracer? #119

Open
ecourreges-orange opened this issue Oct 8, 2019 · 5 comments
Open

Method to reset the global tracer? #119

ecourreges-orange opened this issue Oct 8, 2019 · 5 comments

Comments

@ecourreges-orange
Copy link

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.

@alnr
Copy link

alnr commented Oct 8, 2019

opentracing::Tracer::InitGlobal({});

However: Tracer::IsGlobalTracerRegistered() will incorrectly return true after this. Should probably be fixed (and simplified).

@rnburn
Copy link
Contributor

rnburn commented Oct 8, 2019

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?

@MikeGoldsmith
Copy link
Member

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.

@alnr
Copy link

alnr commented Oct 9, 2019

Wouldn't returning a null pointer (default-constructed shared_ptr) have exactly the same semantics?

@MikeGoldsmith
Copy link
Member

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants