opentelemetry-python: AttributeError: 'NoneType' object has no attribute 'get_current'
Describe your environment runtime: python3.6.1; sdk version: 1.7.1
Steps to reproduce Describe exactly how to reproduce the error. Include a code sample if applicable.
What is the expected behavior? What did you expect to see? I use python3.6.1 runtime; But i have a problem,
File "index.py", line 17, in <module>
with tracer.start_as_current_span("foo"):
File "/opt/python3.6.1/lib/python3.6/contextlib.py", line 82, in enter
return next(self.gen)
File "/opt/python3.6.1/lib/python3.6/site-packages/opentelemetry/sdk/trace/init.py", line 980, in start_as_current_span
set_status_on_exception=set_status_on_exception,
File "/opt/python3.6.1/lib/python3.6/site-packages/opentelemetry/sdk/trace/init.py", line 1003, in start_span
context
File "/opt/python3.6.1/lib/python3.6/site-packages/opentelemetry/trace/propagation/init.py", line 48, in get_current_span
span = get_value(_SPAN_KEY, context=context)
File "/opt/python3.6.1/lib/python3.6/site-packages/opentelemetry/context/init.py", line 96, in get_value
return context.get(key) if context is not None else get_current().get(key)
File "/opt/python3.6.1/lib/python3.6/site-packages/opentelemetry/context/init.py", line 67, in wrapper
return func(args, *kwargs) # type: ignore[misc]
File "/opt/python3.6.1/lib/python3.6/site-packages/opentelemetry/context/init.py", line 131, in get_current
return _RUNTIME_CONTEXT.get_current() # type:ignore
AttributeError: 'NoneType' object has no attribute 'get_current'
my code is:
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
BatchSpanProcessor,
ConsoleSpanExporter,
)
provider = TracerProvider()
processor = BatchSpanProcessor(ConsoleSpanExporter())
provider.add_span_processor(processor)
trace.set_tracer_provider(provider)
tracer = trace.get_tracer(name)
with tracer.start_as_current_span("foo"):
with tracer.start_as_current_span("bar"):
with tracer.start_as_current_span("baz"):
print("Hello world from OpenTelemetry Python!")
What is the actual behavior? What did you see instead?
Additional context Add any other context about the problem here. https://opentelemetry-python.readthedocs.io/en/stable/getting-started.html
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 3
- Comments: 25 (13 by maintainers)
Commits related to this issue
- opentelemetry: pin dependencies for the otel as stated in https://github.com/open-telemetry/opentelemetry-python/issues/2288 — committed to andrewkroh/beats by v1v 2 years ago
- action: force python version 3.9 workaround the issue with https://github.com/open-telemetry/opentelemetry-python/issues/2288 — committed to andrewkroh/beats by v1v 2 years ago
- [ci] Use 'go install' in Github Action setup (#32735) * Use 'go install' in Github Action setup As of Go 1.18, "go get no longer builds or installs packages in module-aware mode." * opentelemet... — committed to elastic/beats by andrewkroh 2 years ago
- [ci] Use 'go install' in Github Action setup (#32735) * Use 'go install' in Github Action setup As of Go 1.18, "go get no longer builds or installs packages in module-aware mode." * opentelemetry: ... — committed to elastic/beats by andrewkroh 2 years ago
- [ci] Use 'go install' in Github Action setup (#32735) (#33360) * Use 'go install' in Github Action setup As of Go 1.18, "go get no longer builds or installs packages in module-aware mode." * op... — committed to elastic/beats by mergify[bot] 2 years ago
- [ci] Use 'go install' in Github Action setup (#32735) * Use 'go install' in Github Action setup As of Go 1.18, "go get no longer builds or installs packages in module-aware mode." * opentelemet... — committed to elastic/beats by andrewkroh 2 years ago
Interesting. Since we already assume the default context is contextvars_context in the api and this is the value we attempt to load, should we simply load the default if there is any exception thrown, since we do rely on the context existing downstream.
@ocelotl @aabmass @srikanthccv wdyt