Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ release.

### Context

- Add context propagation through Environment Variables specification.
([#4454](https://github.com/open-telemetry/opentelemetry-specification/pull/4454))

### Traces

### Metrics
Expand All @@ -17,6 +20,9 @@ release.

### Baggage

- Add context (baggage) propagation through Environment Variables specification.
([#4454](https://github.com/open-telemetry/opentelemetry-specification/pull/4454))

### Resource

### Profiles
Expand Down
149 changes: 149 additions & 0 deletions specification/context/env-carriers.md
Comment thread
adrielp marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Environment Variables as Context Propagation Carriers

**Status**: [Experimental](../document-status.md)

<details>
<summary>Table of Contents</summary>

<!-- toc -->

- [Overview](#overview)
- [Propagator Mechanisms](#propagator-mechanisms)
* [Environment Variable Names](#environment-variable-names)
* [Format Restrictions](#format-restrictions)
+ [Name Restrictions](#name-restrictions)
+ [Value Restrictions](#value-restrictions)
+ [Size Limitations](#size-limitations)
* [Operational Guidance](#operational-guidance)
+ [Environment Variable Immutability](#environment-variable-immutability)
+ [Process Spawning](#process-spawning)
+ [Security](#security)
+ [Case Sensitivity](#case-sensitivity)
Comment thread
reyang marked this conversation as resolved.

<!-- tocstop -->

</details>

## Overview

Environment variables provide a mechanism to propagate context and baggage
information across process boundaries when network protocols are not
applicable. This specification extends the [API Propagators](../context/api-propagators.md)
to define how the
[TextMapPropagator](../context/api-propagators.md#textmap-propagator) can be
used with environment variables.

Common systems where context propagation via environment variables is useful
include:

- Batch processing systems
- CI/CD environments
- Command-line tools

## Propagator Mechanisms

Propagating context via environment variables involves reading and writing to
environment variables. A `TextMapPropagator` SHOULD be used alongside its
normal `Get`, `Set`, `Extract`, and `Inject` functionality as described in the [API
Propagators](../context/api-propagators.md) specification.

### Environment Variable Names

It is RECOMMENDED to use the [W3C Trace
Context](https://www.w3.org/TR/trace-context/) and [W3C
Baggage](https://www.w3.org/TR/baggage/) specifications mapped to environment
variables names for consistent context propagation.
Comment thread
adrielp marked this conversation as resolved.
Outdated

When using the W3C Trace Context and Baggage propagators with environment
variables, the following translated standard environment variable names SHOULD
be used:

| Context Information | Environment Variable | W3C Header Equivalent |
|---------------------|----------------------|------------------------|
| Trace Context | `TRACEPARENT` | `traceparent` |
| Trace State | `TRACESTATE` | `tracestate` |
| Baggage | `BAGGAGE` | `baggage` |
Comment thread
adrielp marked this conversation as resolved.
Outdated

Implementations MAY support additional propagation formats and SHOULD provide
configuration options to override the default environment variable.

### Format Restrictions

#### Name Restrictions

Environment variable names used for context propagation:

- SHOULD use uppercase letters, digits, and underscores for maximum
cross-platform compatibility
- MUST NOT include characters forbidden in environment variables per
platform-specific restrictions
- SHOULD follow naming conventions that align with the propagation format
specification they're implementing (e.g., `TRACEPARENT` for W3C trace context)

#### Value Restrictions

Environment variable values used for context propagation:

- MUST only use characters that are valid in HTTP header fields per [RFC
9110](https://tools.ietf.org/html/rfc9110)
- MUST follow the format requirements of the specific propagation protocol
(e.g., W3C Trace Context specification for `TRACEPARENT` values)
- SHOULD NOT contain sensitive information

#### Size Limitations

Implementations SHOULD follow platform-specific environment variable size
limitations:
Comment thread
adrielp marked this conversation as resolved.

- Windows: Maximum 32,767 characters for name=value pairs according to
[Microsoft Documentation](https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setenvironmentvariable)
Comment thread
adrielp marked this conversation as resolved.
Outdated
- UNIX: System-dependent limits exist and are typically lower than Windows.

Implementations SHOULD handle truncation gracefully when size limits are
exceeded.

### Operational Guidance

#### Environment Variable Immutability

Once set for a process, environment variables SHOULD be treated as immutable
within that process:

- Environment variables SHOULD only be modified before the creation of one or
more child processes occur.
Comment thread
adrielp marked this conversation as resolved.
Outdated
- Applications SHOULD NOT modify context-related environment variables during
execution within the environment in which they were created, as this can lead
to inconsistent trace contexts.
Comment thread
adrielp marked this conversation as resolved.
Outdated
- If modification is required, applications SHOULD create a new environment
variables dictionary with the updated values for the child process.
Comment thread
adrielp marked this conversation as resolved.
Outdated

#### Process Spawning

When spawning child processes:

- Parent processes SHOULD inject context into environment variables before
spawning child processes.
- Child processes SHOULD extract context from environment variables at startup.
- When spawning multiple child processes with different contexts or baggage,
each child SHOULD receive its own copy of the environment variables with
appropriate information.

#### Security

Environment variables are generally accessible to all code running within a
process and with the correct permissions, can be accessed from other processes.

- Implementations SHOULD NOT store sensitive information in environment
variables.
- Applications running in multi-tenant environments SHOULD be aware that
environment variables may be visible to other processes or users with
appropriate permissions.

#### Case Sensitivity

Environment variable names are case-sensitive on UNIX and case-insensitive on
Windows.

- For maximum compatibility, implementations SHOULD:
Comment thread
adrielp marked this conversation as resolved.
Outdated
- Use uppercase names consistently (`TRACEPARENT` not `TraceParent`).
- Use the canonical case when setting environment variables.