Class EnvironmentSetter
java.lang.Object
io.opentelemetry.api.incubator.propagation.EnvironmentSetter
public final class EnvironmentSetter
extends Object
implements io.opentelemetry.context.propagation.TextMapSetter<Map<String,String>>
A
TextMapSetter that injects context into a map carrier, intended for use with
environment variables when applications spawn child processes.
This is useful when an application needs to propagate context to a child process via its
environment. For example, when using ProcessBuilder:
Map<String, String> env = new HashMap<>();
contextPropagators.getTextMapPropagator().inject(context, env, EnvironmentSetter.getInstance());
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.environment().putAll(env);
This setter automatically normalizes keys as environment variable names:
- An empty key is replaced with a single underscore (
_) - ASCII letters are converted to uppercase
- Any character that is not an ASCII letter, digit, or underscore is replaced with an underscore
- If the result would start with a digit, an underscore is prepended
Values are treated as opaque strings. Any propagation-format-specific validation or parsing is the responsibility of the propagator, not this carrier.
Size limitations: Environment variable sizes are platform-dependent (e.g., Windows limits name=value pairs to 32,767 characters). Callers are responsible for being aware of platform-specific limits when injecting context.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic EnvironmentSetterReturns the singleton instance ofEnvironmentSetter.voidtoString()