Implement Environment Variable Context Propagation carriers in api/in…#8074
Implement Environment Variable Context Propagation carriers in api/in…#8074Bhagirath00 wants to merge 1 commit intoopen-telemetry:mainfrom
Conversation
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
| * | ||
| * <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. |
There was a problem hiding this comment.
Link to the spec doc for more information: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/env-carriers.md
| return; | ||
| } | ||
| // Spec recommends using uppercase for environment variable names. | ||
| carrier.put(key.toUpperCase(Locale.ROOT), value); |
There was a problem hiding this comment.
| * TRACESTATE}, {@code BAGGAGE}). This getter translates keys to uppercase before looking them up in | ||
| * the carrier. | ||
| */ | ||
| public enum EnvironmentGetter implements TextMapGetter<Map<String, String>> { |
There was a problem hiding this comment.
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>> { |
There was a problem hiding this comment.
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?
Issue: #7992
This PR implements environmental variable context propagation by adding
EnvironmentGetterandEnvironmentSettercarriers to theapi/incubatormodule. This allows the Java SDK to extract and inject trace data through standard environment variables.Changes
EnvironmentGetterto handle context extraction from environment variables.EnvironmentSetterto handle context injection for child processes.Terminal Screenshots
All new unit tests passed successfully.

Code has been formatted and passed style checks.
