-
Notifications
You must be signed in to change notification settings - Fork 976
[spec] add environment variables as context propagators specification #4454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d3afcb4
[chore] more adjustments
adrielp 92f73c1
[chore] slight adjustments to the wording of the specification
adrielp 46def4d
[chore] additional changes
adrielp 88f9d2e
[chore] update changelog
adrielp 1fbea35
[chore] update toc
adrielp e1fbe25
Merge branch 'main' into env-context-spec
adrielp 6a30e75
Update specification/context/env-carriers.md
adrielp 713d1bf
[chore] minor updates to wording
adrielp 8571b89
Apply suggestions from code review
adrielp 6cac377
[chore] minor changes to wording based on feedback
adrielp cad6574
[chore] minor updates to reference env carriers from other locations
adrielp ddbc7f2
[chore] update truncation guidance
adrielp a745c39
[chore] fix link
adrielp d2bfe1c
Merge branch 'main' into env-context-spec
adrielp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| # 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) | ||
|
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 | ||
| variable names for consistent context propagation. | ||
|
|
||
| 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` | | ||
|
|
||
| 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: | ||
|
adrielp marked this conversation as resolved.
|
||
|
|
||
| - Windows: Maximum 32,767 characters for name=value pairs according to | ||
| [Microsoft Documentation](https://docs.microsoft.com/windows/win32/api/winbase/nf-winbase-setenvironmentvariable) | ||
| - UNIX: System-dependent limits exist and are typically lower than Windows. | ||
|
|
||
| When truncation is required due to size limitations, implementations MUST | ||
| truncate whole entries. Truncation SHOULD start at the end of the entry list. | ||
| Implementers MUST document how graceful truncation is handled and SHOULD | ||
| provide the link to the corresponding specification (e.g., [W3C tracestate | ||
| Truncation guidance][w3c-truncation]). | ||
|
|
||
| [w3c-truncation]: https://www.w3.org/TR/trace-context/#tracestate-limits | ||
|
|
||
| ### Operational Guidance | ||
|
|
||
| #### Environment Variable Immutability | ||
|
|
||
| Once set for a process, environment variables SHOULD be treated as immutable | ||
| within that process: | ||
|
|
||
| - Applications SHOULD read context-related environment variables during | ||
| initialization. | ||
| - Applications SHOULD NOT modify context-related environment variables of the | ||
| environment in which the parent process exists. | ||
|
|
||
| #### Process Spawning | ||
|
|
||
| When spawning child processes: | ||
|
|
||
| - Parent processes SHOULD copy the current environment variables (if | ||
| applicable), modify, and inject context when 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 MUST: | ||
| - Use uppercase names consistently (`TRACEPARENT` not `TraceParent`). | ||
| - Use the canonical case when setting environment variables. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.