Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Access Custom Tracer's fields through GlobalTracer.get() #365

Open
Ravi18Patel opened this issue Dec 2, 2019 · 4 comments
Open

Access Custom Tracer's fields through GlobalTracer.get() #365

Ravi18Patel opened this issue Dec 2, 2019 · 4 comments

Comments

@Ravi18Patel
Copy link

I have Created my custom tracer and added some methods to it. Now If I register a tracer on GlobalTracer and try to retrieve it using Globaltracer.get() I am getting an instance of GlobalTracer.
The tracer which I have passed is stored in tracer field of GlobalTracer but I don't see any api to access that tracer.
How can I access methods written in my custom tracer?

@sjoerdtalsma
Copy link
Contributor

The GlobalTracer -by design- only exposes the OpenTracing API.
This has the advantage that you're guaranteed of it functioning correctly and discourages people working around it by typecasting.

Technically it also helps reason about the state in an uninitialized application but that is secondary.

Unfortunately this also means that you cannot simply cast the globaltracer to any specific implementation; if you need a specific implementation you should create your own construct to access it.

Technically some kind of 'unwrap' may be possible, but I don't know how other contributors feel about that. Documenting such unwrap method is harder than it looks as it may return unpredictable results during GlobalTracer registration.

@whiskeysierra
Copy link

My two cents: Don't use GlobalTracer at all. Accessing it using dependency injection makes for so much cleaner and more sane code.

@sjoerdtalsma
Copy link
Contributor

My two cents: Don't use GlobalTracer at all. Accessing it using dependency injection makes for so much cleaner and more sane code.

Yes, I completely forgot go mention this ⬆️ ; the GlobalTracer is intended for libraries that have no dependency injection; so by all means set it at application initialisation, but try to avoid using it yourself if at all possible.

@Ravi18Patel
Copy link
Author

The documentation says that Global tracer forwards all of its methods to registered tracer. But I don't see any use of that by preventing users from using the registered tracer.
Wouldn't it be better if there is one more method for eg. getRegisteredTracer() which gives functionality to access the registered tracer through global tracer.

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

3 participants