open-telemetry / opentelemetry-python

OpenTelemetry Python API and SDK
https://opentelemetry.io
Apache License 2.0
1.77k stars 619 forks source link

Support propagating span, trace ids via environment variable #3313

Open dshivashankar1994 opened 1 year ago

dshivashankar1994 commented 1 year ago

Is your feature request related to a problem? Yes. I have a custom multi-processor which is capable of launching workers in remote hosts for processing. In such cases the python context is not propagated and only the environment variables are propagated. Because of this, the parent-child relation is not properly maintained if a function invokes another function over these remote-workers.

Describe the solution you'd like The request is to support setting the span-id, trace-id etc., in the environment whenever span is started and propagate, process them from the environment.

Describe alternatives you've considered Passing the span id, trace id in serialized fashion while to these workers over network is not possible as these workers are linux workers and don't have a port to communicate.

Additional context I've prepared a small PoC for my work. A pre-step is, checking the environment for any existing span-id/trace-id set. If exists, create a span out of it and store in the context and use the context while creating span. While starting span, I set the span-id, trace-id etc., in the environment. I'm not sure of the value this brings to the table. But still wanted to bring this to discussion to see if there are any caveats in such behavior and to understand why OT never supported such env propagation.

srikanthccv commented 1 year ago

to understand why OT never supported such env propagation

Because it should be added to the spec first. See https://github.com/open-telemetry/opentelemetry-specification/issues/740 and https://github.com/open-telemetry/opentelemetry-python/pull/2110