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 spawning child processes.
This is useful when an application needs to propagate context to sub-processes via their
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 sanitizes keys to be compatible with environment variable naming conventions:
- Converts keys to uppercase (e.g.,
traceparentbecomesTRACEPARENT) - Replaces
.and-with underscores
Values are validated to contain only characters valid in HTTP header fields per RFC 9110 (visible ASCII characters, space, and horizontal tab). Values containing invalid characters are silently skipped.
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()