fix: support standard OpenTelemetry tracing env vars#1171
Open
AshuOPragmatikosThrylos wants to merge 1 commit into
Open
fix: support standard OpenTelemetry tracing env vars#1171AshuOPragmatikosThrylos wants to merge 1 commit into
AshuOPragmatikosThrylos wants to merge 1 commit into
Conversation
The README referenced OpenTelemetry SDK environment variables, but ratelimit only honored custom TRACING_* settings for protocol, enablement, service identity, and sampling. Add OTEL_* fallbacks when the matching TRACING_* variable is unset, preserve TRACING_* precedence for backward compatibility, and document both configuration surfaces. Fixes envoyproxy#1166 Signed-off-by: thunderdome_ master <43502764+AshuOPragmatikosThrylos@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This change resolves a configuration mismatch where the ratelimit service documented OpenTelemetry SDK environment variables but only honored custom
TRACING_*variables for several critical tracing settings.The service now:
OTEL_*variables when the matchingTRACING_*variable is not explicitly setTRACING_*is setFixes #1166
Problem statement
Operators configuring ratelimit using the OpenTelemetry SDK environment variable spec expect settings like
OTEL_EXPORTER_OTLP_PROTOCOLandOTEL_SERVICE_NAMEto work out of the box.Before this change, only a subset of OTLP exporter settings worked (endpoint, TLS, timeout) because the underlying OTLP client reads those directly. Settings that pass through ratelimit's own
settings.Settingslayer were ignored unless duplicated into customTRACING_*variables.This created silent misconfiguration: tracing appeared configured, but protocol, enablement, service identity, or sampling did not behave as expected.
Root cause
Configuration was split across two layers with inconsistent env var support:
flowchart TB subgraph Before["Before fix"] A[Operator sets OTEL_* env vars] --> B[envconfig reads TRACING_* only] B --> C[ApplyOtelTracingFallbacks missing] C --> D[Runner uses partial TRACING_* values] D --> E[OTLP client reads endpoint/TLS from OTEL_*] D --> F[Protocol/name/sampling from wrong or default TRACING_* values] F --> G[Tracing misconfigured or disabled] endsettings.SettingsviaenvconfigTRACING_*onlyOTEL_EXPORTER_OTLP_PROTOCOL,OTEL_SERVICE_NAME,OTEL_TRACES_EXPORTER, sampler varstrace.createClient()OTLP clientsTRACING_*Solution
Introduce
ApplyOtelTracingFallbacks()immediately afterenvconfig.Process()inNewSettings():flowchart TB subgraph After["After fix"] A[Process all env vars] --> B[envconfig loads TRACING_* defaults/explicit values] B --> C[ApplyOtelTracingFallbacks] C --> D{TRACING_* explicitly set?} D -->|Yes| E[Keep TRACING_* value] D -->|No| F[Resolve from matching OTEL_* var] E --> G[Runner initializes TracerProvider] F --> G G --> H[OTLP client exports with correct protocol + destination] endPrecedence rule
TRACING_*OTEL_*fallbackConfiguration mapping
TRACING_*variableOTEL_*fallbackTRACING_ENABLEDOTEL_TRACES_EXPORTER(otlp= on,none= off)OTEL_SDK_DISABLED=trueTRACING_EXPORTER_PROTOCOLOTEL_EXPORTER_OTLP_PROTOCOLhttp/protobuf→http,grpc→grpcTRACING_SERVICE_NAMEOTEL_SERVICE_NAMETRACING_SERVICE_NAMESPACEOTEL_RESOURCE_ATTRIBUTESservice.namespace=<value>TRACING_SERVICE_INSTANCE_IDOTEL_RESOURCE_ATTRIBUTESservice.instance.id=<value>TRACING_SAMPLING_RATEOTEL_TRACES_SAMPLER,OTEL_TRACES_SAMPLER_ARGalways_on→1.0,always_off→0.0,traceidratio→argExporter destination settings (
OTEL_EXPORTER_OTLP_ENDPOINT, certificates, timeout, headers) continue to be read directly by the OpenTelemetry OTLP client, unchanged.Sequence: settings resolution at startup
sequenceDiagram participant Op as Operator participant Env as Environment participant NS as NewSettings() participant EC as envconfig.Process participant FB as ApplyOtelTracingFallbacks participant R as Runner Op->>Env: Set OTEL_EXPORTER_OTLP_PROTOCOL=grpc Op->>Env: Set OTEL_TRACES_EXPORTER=otlp Op->>Env: Set OTEL_SERVICE_NAME=my-ratelimit R->>NS: Load configuration NS->>EC: Parse TRACING_* struct tags EC-->>NS: Defaults (enabled=false, protocol=http, name=RateLimit) NS->>FB: Fill gaps from OTEL_* where TRACING_* unset FB->>Env: LookupEnv TRACING_* (not set) FB->>Env: Read OTEL_* values FB-->>NS: enabled=true, protocol=grpc, name=my-ratelimit NS-->>R: Final Settings R->>R: InitProductionTraceProvider(...)Before vs after
OTEL_EXPORTER_OTLP_PROTOCOL=grpconlyhttp(default)grpcOTEL_TRACES_EXPORTER=otlponlyOTEL_SERVICE_NAME=my-ratelimitonlyRateLimitmy-ratelimitOTEL_RESOURCE_ATTRIBUTES=service.namespace=prod,service.instance.id=pod-1OTEL_TRACES_SAMPLER=traceidratio,OTEL_TRACES_SAMPLER_ARG=0.251.00.25TRACING_EXPORTER_PROTOCOL=http+OTEL_EXPORTER_OTLP_PROTOCOL=grpchttpwins (explicit TRACING_* precedence)Files changed
src/settings/tracing_config.gosrc/settings/tracing_config_test.gosrc/settings/settings.goREADME.mdTRACING_*andOTEL_*variable setsTest plan
Automated
Results (verified locally)
Full settings package suite: 22/22 tests pass.
Runtime evidence (debug session, pre-instrumentation removal)
Observed in
debug-b3e99e.logduring verification:OTEL_EXPORTER_OTLP_PROTOCOL=grpcprotocol=httpprotocol=grpcOTEL_EXPORTER_OTLP_PROTOCOL=http/protobufprotocol=httpprotocol=httpOTEL_SERVICE_NAME=my-ratelimitname=RateLimitname=my-ratelimitOTEL_RESOURCE_ATTRIBUTES=...prod/pod-123OTEL_TRACES_EXPORTER=otlpenabled=falseenabled=trueOTEL_SDK_DISABLED=true+ exporter otlpenabled=falseOTEL_TRACES_SAMPLER=traceidratio, arg0.25rate=1rate=0.25TRACING_*+ conflicting OTELExample configurations
Standards-first (recommended for new deployments)
Legacy-compatible (unchanged)
Compatibility and risk
TRACING_*values still winOTEL_*without matchingTRACING_*FAQ (preemptive reviewer questions)
Q: Why not remove
TRACING_*entirely?A: Backward compatibility. Existing Helm charts, sidecars, and runbooks already use
TRACING_*. Removing them would be a breaking change without a deprecation cycle.Q: Why check
os.LookupEnv("TRACING_*")instead of comparing against defaults?A: Defaults like
TRACING_EXPORTER_PROTOCOL=httpare indistinguishable from an operator intentionally choosing HTTP. Explicit presence detection is the only safe precedence model.Q: Why not use the OpenTelemetry SDK's auto-config env parser for everything?
A: Ratelimit still owns a service-specific enable gate and maps OTEL protocol values (
http/protobuf) to its internalhttp/grpcswitch. A thin fallback layer keeps behavior explicit and testable.Q: Does this fix exporter endpoint configuration?
A: Endpoint configuration already worked via OTLP client env vars. This PR fixes the settings that were not delegated to the SDK.
Q: What about
OTEL_TRACES_SAMPLER=parentbased_always_onand other samplers?A: Not mapped in v1. Unsupported values are ignored; existing default sampling remains. Can be extended in a follow-up if needed.
Q: Does this address #326?
A: Partially related. #326 tracked adding tracing support (landed in #332). #1166 tracks configuration consistency with OTEL standards.
Q: Why fix README typo OLTP → OTLP?
A: Minor but reduces confusion while documenting the tracing section.
Suggested reviewer focus
ApplyOtelTracingFallbacks()- confirmLookupEnvbehavior matches intentTestTracingEnvOverridesOtelEnv)Checklist
Related links