Repository navigation
fix(telemetry): bound metric and log export, and honor OTel timeout env vars - #379
Merged
Merged
Conversation
…nv vars Follow-up to #377, which bounded trace export and deferred two things. The first is that metrics and logs carry the same asymmetry traces had. otlpmetrichttp and otlploghttp default to a 10s per-request deadline while NewPeriodicReader and NewBatchProcessor default to a 30s export budget, so a destination that accepts a batch and answers slower than 10s is handed it again inside the reader's or processor's remaining window. Both now take the resolved budget alongside their exporter, the way the batch span processor already did. The second is that #377 made unset mean 30s rather than "let the SDK decide", which silently disabled OTEL_EXPORTER_OTLP_TRACES_TIMEOUT and friends: the SDK applies env config first and explicit options after, so passing an option at all takes the variables out of play. A caller that tuned export deadlines through the environment lost that lever on upgrade and gained nothing, since its own config had nowhere to put a timeout. ExportTimeout now resolves through the variables before falling back to the default, so the lever works again without code changes and an explicit value still wins. Both variables for a signal feed one budget rather than their own components. That looks lossy and is the point: honoring each on its own component would reinstate the split this field exists to close -- a processor variable set alone would leave the exporter on 10s with room to re-send, and an exporter variable set alone would be truncated by the processor's 30s. Each signal's budget reaches both halves, proven by driving a built provider against an ingest that never answers and asserting the flush gives up on the configured value. Removing any one of the four wirings turns those tests from ~150ms into the 10s ceiling, so none of them pass vacuously. Also tidies two things left in #377's tests: the ingest server now releases its handler on teardown instead of parking a goroutine until the binary exits, and the silent gRPC peer closes its connections from a single cleanup rather than calling t.Cleanup from its accept loop. Co-Authored-By: Claude Opus 5 <[email protected]>
aponcedeleonch
approved these changes
Oct 15, 2026
aponcedeleonch
left a comment
Member
There was a problem hiding this comment.
LGTM, thanks for picking up the env var follow-up. I checked the wiring end to end. All three signals get the budget on the HTTP exporter, the gRPC exporter, and the processor or reader, and all three strategies pass it through. The precedence call of feeding one budget from both variables makes sense to me, it keeps the exporter and processor from drifting apart again.
I left two small nits inline. Neither blocks the PR.
aponcedeleonch
added a commit
that referenced
this pull request
Oct 15, 2026
…bad values Addresses the two nits from the #379 review: - Read the OTel timeout variables through env.Reader instead of os.LookupEnv, matching the rest of the repo. otlp.Config gains an EnvReader field that falls back to the OS environment when nil, the same pattern as networking.ValidatingTransport. - A variable that is set but unparseable or non-positive still falls through to the next tier, and is now also reported via otel.Handle, as the SDK does, so a typo no longer goes unnoticed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
aponcedeleonch
added a commit
that referenced
this pull request
Oct 15, 2026
…bad values Addresses the two nits from the #379 review: - Read the OTel timeout variables through env.Reader instead of os.LookupEnv, matching the rest of the repo. otlp.Config gains an EnvReader field that falls back to the OS environment when nil, the same pattern as networking.ValidatingTransport. - A variable that is set but unparseable or non-positive still falls through to the next tier, and is now also reported via otel.Handle, as the SDK does, so a typo no longer goes unnoticed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
aponcedeleonch
added a commit
that referenced
this pull request
Oct 15, 2026
* feat(telemetry): add sampler override and exact traces endpoint Two hardcoded behaviours kept callers' GenAI spans from reaching cost platforms: - The tracer always used ParentBased(TraceIDRatioBased(rate)), so an edge proxy forwarding an unsampled traceparent suppressed every downstream span. WithSampler lets callers supply their own sampler; nil keeps the existing default exactly. - The HTTP trace exporter always appended /v1/traces, making exact-path ingest routes unreachable. WithTracesEndpoint takes a full URL used verbatim, whose scheme decides TLS. It overrides the traces signal only, works with no OTLP endpoint set, and is rejected under gRPC. The traces URL is validated up front, since the SDK's WithEndpointURL logs and ignores an unparseable URL and silently drops a query string. Co-Authored-By: Claude Opus 5.5 <[email protected]> * refactor(telemetry): read timeout env vars via env.Reader and report bad values Addresses the two nits from the #379 review: - Read the OTel timeout variables through env.Reader instead of os.LookupEnv, matching the rest of the repo. otlp.Config gains an EnvReader field that falls back to the OS environment when nil, the same pattern as networking.ValidatingTransport. - A variable that is set but unparseable or non-positive still falls through to the next tier, and is now also reported via otel.Handle, as the SDK does, so a typo no longer goes unnoticed. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(telemetry): keep traces endpoint exact and out of diagnostics Addresses the review on #383: - Reject a traces endpoint whose path otlptracehttp cannot send as written. WithEndpointURL keeps only the decoded path, the SDK trims surrounding whitespace, and the request is rebuilt from that decoded path, so e.g. "%2F" would reach the wire as "/". Tests now assert the received RequestURI rather than the decoded r.URL.Path. - Never echo the traces endpoint URL in errors or logs, since its path, query or userinfo can carry a credential. Validation errors no longer quote it or wrap url.Parse's error, the gRPC error drops it, and the strategy's log line and error wrappers show only scheme and host. URLs with userinfo are rejected; credentials belong in headers. Sentinel-secret tests cover this through NewCompositeProvider. - Treat an empty OTel timeout variable as unset instead of reporting it. - Document that sampling under an unsampled remote parent yields traces with missing parents, and that it doesn't make export lossless. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Follow-up to #377, which bounded trace export and left two things open. Both are the toolhive-core side; the sprout-side option from @aponcedeleonch's review is not needed if this lands, since the env lever keeps working without changes in sprout.
1. Metrics and logs had the same bug traces did
#377 fixed the exporter-vs-processor asymmetry for spans only. The other two signals carry it unchanged:
BatchSpanProcessor)otlpmetrichttp10sNewPeriodicReader30sotlploghttp10sNewBatchProcessor30sSo the duplicate-delivery window #377 closed for spans was still open for points and records against the same slow third-party ingest. Both now take the resolved budget alongside their exporter.
2. #377 silently disabled the OTel timeout environment variables
This is the regression @aponcedeleonch flagged. Because the SDK applies env config first and explicit options after (
NewHTTPConfigcallsApplyHTTPEnvConfigsbefore the option loop;NewBatchSpanProcessorreads its env var only to seed a default that options then overwrite), passing a timeout option at all takes the variables out of play. After #377, "unset" meant a hard 30s rather than "let the SDK decide" — so a caller tuning deadlines through the environment lost that lever on upgrade and had nowhere in its own config to put one.ExportTimeoutnow resolves in descending precedence:Config.ExportTimeout, when positiveOTEL_EXPORTER_OTLP_{TRACES,METRICS,LOGS}_TIMEOUT)OTEL_EXPORTER_OTLP_TIMEOUTOTEL_BSP_EXPORT_TIMEOUT,OTEL_METRIC_EXPORT_TIMEOUT,OTEL_BLRP_EXPORT_TIMEOUT)DefaultExportTimeout(30s)The lever works again with no code changes anywhere, and an explicit value still wins.
The one judgment call worth reviewing
Both variables for a signal feed one budget, rather than each driving its own component. That is deliberate, and it is the part I'd most like a second opinion on.
Honoring each on its own component would reinstate exactly the split this field exists to close: a processor variable set alone would leave the exporter on the SDK's 10s with room to re-send, and an exporter variable set alone would be truncated by the processor's 30s. Feeding one budget keeps the invariant that neither half can outlive the other, at the cost of
OTEL_BSP_EXPORT_TIMEOUTalso moving the exporter's deadline. Values are read as whole milliseconds per spec; unparseable or non-positive values fall through to the next tier rather than being honored as zero.ExportTimeoutis also now documented as covering all three signals rather than traces only. That follows the existingProtocol/TracesProtocolprecedent inproviders.Config— a general field, with per-signal overrides added later if anyone needs them.Testing
Each signal's budget is proven to reach both halves by driving a built provider against an ingest that never answers and asserting the flush gives up on the configured value rather than the 30s default. I mutation-checked every one of them — removing any single wiring turns the test from ~150ms into the 10s ceiling:
sdkmetric.WithTimeouton the readersdklog.WithExportTimeouton the processorexportTimeoutForExportTimeoutin the logs strategyExportTimeoutin the metrics strategyPlus table-driven precedence coverage for all five tiers, signal independence (one signal's variables must not retime another's), and a test pinning the literal variable names in one place, since the other cases reference them through the struct.
Also tidies two things left in #377's tests: the ingest server now releases its handler on teardown instead of parking a goroutine until the binary exits, and the silent gRPC peer closes connections from a single cleanup rather than calling
t.Cleanupfrom its accept loop.taskandtask license-checkpass. Coverage:telemetry/providers62.6% → 73.9% (now over the 70% graduation bar),telemetry/providers/otlp83.3% → 84.3%.🤖 Generated with Claude Code