[Feature Request] Make sure OTel baggage propagates properly throughout activities
Describe the solution you'd like
Write a test confirming that baggage is properly serialized/rehydrated to/within activities and if it is not, fix that.
I did a quick change to _TracingActivityInboundInterceptor to add attach/detach calls, and then it works:
ctx = self.root._context_from_headers(input.headers)
with self.root.tracer.start_as_current_span(
f"RunActivity:{info.activity_type}",
context=ctx,
attributes={
"temporalWorkflowID": info.workflow_id,
"temporalRunID": info.workflow_run_id,
"temporalActivityID": info.activity_id,
},
):
token = opentelemetry.context.attach(ctx)
try:
return await super().execute_activity(input)
finally:
opentelemetry.context.detach(token)
Thanks! I guess it's intentional that https://opentelemetry-python.readthedocs.io/en/latest/api/trace.html#opentelemetry.trace.Tracer.start_as_current_span does not do that.
At first glance, this appears caused by a known OTel Python bug https://github.com/open-telemetry/opentelemetry-python/issues/3350 (as linked from https://github.com/open-telemetry/opentelemetry-python/issues/2432). We will workaround by re-attaching the context (so long as we don't lose the span we created). I will write tests to confirm.