Skip to content

[carriers] add env carrier #4609

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

adrielp
Copy link

@adrielp adrielp commented Jun 2, 2025

Description

Adds a prototype for the environment variable carrier, specifically decorating Getter and Setter instead of creating a dedicated propagator. The comes from the conversations within the environment variable context propagation specification pull request.

There's a corresponding thread in Slack around this topic.

The example use of the Getter portion of this prototype can be found in this gist.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

The Getter was tested by using the prototype in a real environment. Unit tests need to be added after conversation around this prototype.

  • Test A

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.
  • Unsure

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Comment on lines +10 to +14
KEY_MAPPING = {
"TRACEPARENT": "traceparent",
"TRACESTATE": "tracestate",
"BAGGAGE": "baggage"
}
Copy link
Member

@pellared pellared Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have a special handling only for these 3 keys?
Couldn't 't it be a generic rule how the env carrier works?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed them and pushed the change. They were there from my working prototype enforcing on those were set. However, in the specification we do outline that those are the three well-known values that SHOULD be used. Ultimately, it doesn't matter. Any keys in the environment, when lowered, will only be considered valid context in the text map propagator when they match one of the well-known specs supported in the SDK. (b3/w3c/etc)

Comment on lines +40 to +41
"""This class decorates Setter to enable setting context and baggage
to environment variables.
Copy link
Member

@pellared pellared Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the purpose to set env var for some external process that is going to be spawned?

From https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/env-carriers.md#environment-variable-immutability and https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/env-carriers.md#process-spawning:

Applications SHOULD NOT modify context-related environment variables of the environment in which the parent process exists.

Parent processes SHOULD copy the current environment variables (if applicable), modify, and inject context when spawning child processes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! and i'm not sure how best to handle that implementation detail in practice at the carrier level, which is why this is the current set.

In my head, the only real path forward I see with that portion is to set a dictionary with that new context, and let the implementer use that returned dictionary when they do a popen run like the below psuedo code:

# somehow the user sets traceparent, tracestate, and baggage and setter returns an env dictionary instead of what it does now

# the user then takes that and sets it in popen
popen.run(["something"], env=env_dict_from_setter)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants