Skip to content

Implement Environment Variable Context Propagation carriers in api/in…#8074

Open
Bhagirath00 wants to merge 1 commit intoopen-telemetry:mainfrom
Bhagirath00:feature/env-var-propagation
Open

Implement Environment Variable Context Propagation carriers in api/in…#8074
Bhagirath00 wants to merge 1 commit intoopen-telemetry:mainfrom
Bhagirath00:feature/env-var-propagation

Conversation

@Bhagirath00
Copy link

Issue: #7992

This PR implements environmental variable context propagation by adding EnvironmentGetter and EnvironmentSetter carriers to the api/incubator module. This allows the Java SDK to extract and inject trace data through standard environment variables.

Changes

  • Added EnvironmentGetter to handle context extraction from environment variables.
  • Added EnvironmentSetter to handle context injection for child processes.
  • Implemented logic to ensure environment variable keys are handled in the standard uppercase format.
  • Added comprehensive unit tests to verify case-insensitive lookups and correct value extraction.

Terminal Screenshots

All new unit tests passed successfully.
image

Code has been formatted and passed style checks.
image

@Bhagirath00 Bhagirath00 requested a review from a team as a code owner February 12, 2026 12:55
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 12, 2026

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: Bhagirath00 / name: Bhagirath (df9a72b)

@codecov
Copy link

codecov bot commented Feb 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.20%. Comparing base (fff95e0) to head (df9a72b).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #8074   +/-   ##
=========================================
  Coverage     90.20%   90.20%           
- Complexity     7592     7606   +14     
=========================================
  Files           841      843    +2     
  Lines         22911    22929   +18     
  Branches       2288     2289    +1     
=========================================
+ Hits          20666    20684   +18     
  Misses         1529     1529           
  Partials        716      716           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

*
* <p>Standard environment variable names are uppercase (e.g., {@code TRACEPARENT}, {@code
* TRACESTATE}, {@code BAGGAGE}). This getter translates keys to uppercase before looking them up in
* the carrier.
Copy link
Member

Choose a reason for hiding this comment

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

return;
}
// Spec recommends using uppercase for environment variable names.
carrier.put(key.toUpperCase(Locale.ROOT), value);
Copy link
Member

Choose a reason for hiding this comment

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

* TRACESTATE}, {@code BAGGAGE}). This getter translates keys to uppercase before looking them up in
* the carrier.
*/
public enum EnvironmentGetter implements TextMapGetter<Map<String, String>> {
Copy link
Member

Choose a reason for hiding this comment

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

We don't use this enum style of pattern for singletons in this repo. Instead, we prefer:

  • A public final class
  • A private constructor
  • A private static final reference to the singleton instance
  • A public static accessor public static EnvironmentGetter getInstance(), accessing the singleton instance

* TRACESTATE}, {@code BAGGAGE}). This setter translates keys to uppercase before inserting them
* into the carrier.
*/
public enum EnvironmentSetter implements TextMapSetter<Map<String, String>> {
Copy link
Member

Choose a reason for hiding this comment

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

So where would this type of thing be used in practice? Since its just setting into a map, the only thing about it specific to env vars is the formatting of the keys.

The caller would have to be managing sub processes and need to manipulate their environment. Something like:

    Map<String, String> env = new HashMap<>();
    contextPropagators.getTextMapPropagator().inject(context, env, EnvironmentSetter.getInstance());
    ProcessBuilder processBuilder = new ProcessBuilder();
    processBuilder.environment().putAll(env);

Is this what you had in mind? Have any users asked for this or this just to be spec complete?

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