-
Notifications
You must be signed in to change notification settings - Fork 648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add central implementation "registry"/global tracer #15
Comments
Actually, I just noticed that the spec covers this point and puts that central component in the API component: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/library-guidelines.md#language-library-generic-design |
So in general it would be nice to have something along the lines of Now, now - in Java this is straightforward to do, as you can load at startup the Maybe something like: import opentelemetry
opentelemetry.set_tracer(my_tracer)
...
opentelemetry.tracer().start_span("etc"):
... A few questions would be:
Let me know what you think ;) |
All good points, and in any case the spec does suggest the real implementation should replace the no-op implementation that ships with the api package (although "exact substitution mechanism is language dependent" leaves some flexibility). My only complaint here is mostly aesthetic -- we're asking application code to import a full implementation from a package named "api". Since we have the option of making the global tracer a module-level variable (or module-level getter/setters as in OpenTracing) we may want to use something like This issue seems like a good place to track the implementation of the actual mechanic that loads a specific implementation. |
What about a single module instead of a singleton?
What's a good use case for replacing the global tracer at run time? Would it solve the problem if we made it easy to swap out the tracer implementation (but not the actual |
My personal taste would be to have all these in a single module (and not through a singleton value). Similarly to how (There's also the question of how many
My feeling is that it's not needed the vast majority of time, but we need to add a note there. |
The only use I can think of for replacing the global tracer is a unit test. That is, if the selection mechanism for the initial tracer object is solid enough that it is not needed to overwrite the selected object right after initialization.
So there is a module I also wanted to initially object that a class/singleton would make it easier to swap out the whole set of meter, tracer, ... (that may need to be synchronized to the same vendor's implementation), but on second thought, it doesn't really make a difference if passing a module instead of a class-based object to some function that wants to be flexible about that, and its an edge case anyway. |
Yeah, that's the only case I could think of as well.
That's accurate ;) |
* Global tracer registry: First somewhat satisfying iteration. * Add API docs for backend module * Fix documentation (and overlong lines within). * Sort imports. * Remove _UNIT_TEST_IGNORE_ENV. We should be able to ensure clean envvars for the test run. * Misc cleanup. * Fix backend.py not being included in wheel. * Rewrite backend/loader. * Rewrite backend/loader more, fix pylint, mypy. * Ditch 'default' in `_load_default_impl`, it's just wrong now. * Fix docs. * Apply new package structure. * Remove unit tests (for now). * Document the factory type aliases. * Store factory functions in respective modules. Gets rid of the dictionary in loader.py. * Fix factory return type (Optional) & improve docs. * Revert accidental changes to setup.py. * Remove unused global.
As the discussion about this on #11 is getting quite long (#11 (comment)), I opened this issue.
Basically, opentelemetry-python should provide some API that decouples code that just wants to use instrumentation/tracing APIs from any particular tracer implementation. Without such an API, one is forced (or at least tempted) to write code like:
I think it is clear that we want to avoid that, as it would force a whole dependency tree of an application and its libraries to coordinate on a particular implementation of the API, which kinda defeats the purpose of having a separate API layer.
OpenTracing handles this by providing a global tracer object: https://github.com/opentracing/opentracing-python/blob/master/opentracing/__init__.py
OpenTelemetry-java also has a global
OpenTelemetry
instance that, among other things, holds a reference to a global tracer: https://github.com/open-telemetry/opentelemetry-java/blob/fb0f5339cd1d665a98996806f45c60c65f47d7b6/api/src/main/java/io/opentelemetry/OpenTelemetry.java#L49-L58There are other options, like having libraries themselves manage their "library-global" tracers. This was also discussed in a different thread #11 (comment).
The text was updated successfully, but these errors were encountered: