Description
Describe your environment
Affects the current version of OTel 1.18.0 but affects all versions. I believe this is an issue in both the API and SDK Tracer implementations.
Steps to reproduce
Run the following script
from opentelemetry.sdk.trace import TracerProvider as SdkTracerProvider
from opentelemetry import trace, baggage, context
key = context.create_key("mykey")
def test(tracer):
ctx = context.set_value(key, "myvalue")
with tracer.start_as_current_span("myspan", context=ctx) as span:
# Missing the key set above
print(context.get_current())
print("API tracer")
test(trace.get_tracer("foo"))
print()
print("SDK tracer")
test(SdkTracerProvider().get_tracer("foo"))
What is the expected behavior?
The printed context should have the explicitly set context key that was passed into tracer.start_as_current_span()
. That is my expectation but curious if other people expect something else.
What is the actual behavior?
The printed context is missing the explicitly set context key
API tracer
{}
SDK tracer
{'current-span-06d983ad-613d-4f3e-bb80-0c8443a0722f': _Span(name="myspan", context=SpanContext(trace_id=0x319f42abd006fd7de5f7ee763abbaf23, span_id=0xc5ef9f69b807b7c3, trace_flags=0x01, trace_state=[], is_remote=False))}
Additional context
trace.use_span()
(which both tracer impls use) set the span in the current implicit context, ignoring the span's parent context.
This exacerbates usability issues outline in #2432