Skip to content
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

Calling trace.get_tracer before initializing tracing turns entire tracing pipeline into a noop pipeline. #1276

Closed
owais opened this issue Oct 23, 2020 · 2 comments · Fixed by #1726
Labels
bug Something isn't working

Comments

@owais
Copy link
Contributor

owais commented Oct 23, 2020

Calling trace.get_tracer() before setting a global tracer provider effectively disables all tracing for the process.

  • opentelemetry.ap.trace.get_tracer_provider() checks if a global tracer provider is set or not and if not, it sets the global provider to the default implementation from the api package.
  • Calling opentelemetry.trace.get_tracer() internally calls get_tracer_provider() meaning if it is called before a set_tracer_provider() call, it ends up setting the global provider to the default tracer provider.
  • This means subsequent calls to set_provider will not do anything and no spans will be exported.
  • Depending on which framework the user is instrumenting or how logging is set up, this may or may not provide helpful hints.

Steps to reproduce

Example project: https://github.com/owais/otel-django-test

Steps

  • Run the project as ./manage.py runserver 8000
  • Make requests to localhost:8000/hello.
  • No spans are printed to console.

Fix

  • Either move trace.get_tracer() to inside the view or move init_tracing from wsgi.py to manage.py to fix the issue.

Possible fixes

  1. Document this and highlight it as a caveat, and hope users don't get tripped by it.
  2. Partial fix would be for trace.set_tracer_provider() to accept new tracer provider instances and replace the old one if the old one was an instance of the default tracer provider. This would be a partial fix because it would make the trace pipeline and any tracers fetched after the pipeline was setup functional but it would still render the tracers fetched before the pipeline was setup non-functional as they'd export spans to the default tracer provider.
  3. Patch the default tracer to actually be a proxy to a real tracer. May be the default tracer can lazily "upgrade" itself to a real tracer if an actual tracer provider was set, otherwise continue to be a noop implementation.
@owais owais added the bug Something isn't working label Oct 23, 2020
srikanthccv pushed a commit to srikanthccv/opentelemetry-python that referenced this issue Nov 1, 2020
…server and value recorder (open-telemetry#1276)

* chore: updating aggregator MinMaxLastSumCount and use it for value observer and value recorder

* chore: fix after merge
@aabmass
Copy link
Member

aabmass commented Dec 3, 2020

Any idea why this happens before the setup in wsgi.py? I thought that would be the first thing to run

@lzchen
Copy link
Contributor

lzchen commented Dec 3, 2020

Closing in favour of #1159

Let's continue the discussion there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants