Skip to content

fix(telemetry): bound metric and log export, and honor OTel timeout env vars - #379

Merged
aponcedeleonch merged 1 commit into
mainfrom
feat/otlp-export-timeout-all-signals
Oct 15, 2026
Merged

aponcedeleonch merged 1 commit into
mainfrom
feat/otlp-export-timeout-all-signals

Conversation

@reyortiz3

Copy link
Copy Markdown
Contributor

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:

Signal Exporter default Processor/reader default Before After
Traces 10s 30s (BatchSpanProcessor) fixed in #377 —
Metrics otlpmetrichttp 10s NewPeriodicReader 30s unbounded bounded
Logs otlploghttp 10s NewBatchProcessor 30s unbounded bounded

So 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 (NewHTTPConfig calls ApplyHTTPEnvConfigs before the option loop; NewBatchSpanProcessor reads 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.

ExportTimeout now resolves in descending precedence:

  1. Config.ExportTimeout, when positive
  2. the signal's exporter variable (OTEL_EXPORTER_OTLP_{TRACES,METRICS,LOGS}_TIMEOUT)
  3. OTEL_EXPORTER_OTLP_TIMEOUT
  4. the signal's processor variable (OTEL_BSP_EXPORT_TIMEOUT, OTEL_METRIC_EXPORT_TIMEOUT, OTEL_BLRP_EXPORT_TIMEOUT)
  5. 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_TIMEOUT also 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.

ExportTimeout is also now documented as covering all three signals rather than traces only. That follows the existing Protocol / TracesProtocol precedent in providers.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:

Wiring removed Result
sdkmetric.WithTimeout on the reader FAIL, 10.00s
sdklog.WithExportTimeout on the processor FAIL, 10.00s
env tiers in exportTimeoutFor 16 FAIL
ExportTimeout in the logs strategy FAIL, 10.00s
ExportTimeout in the metrics strategy FAIL, 10.00s

Plus 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.Cleanup from its accept loop.

task and task license-check pass. Coverage: telemetry/providers 62.6% → 73.9% (now over the 70% graduation bar), telemetry/providers/otlp 83.3% → 84.3%.

🤖 Generated with Claude Code

…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 aponcedeleonch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread telemetry/providers/otlp/timeout.go Resolved
Comment thread telemetry/providers/otlp/timeout.go Resolved
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
aponcedeleonch merged commit 3f7cd59 into main Oct 15, 2026
6 checks passed
@aponcedeleonch
aponcedeleonch deleted the feat/otlp-export-timeout-all-signals branch October 15, 2026 11:58
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants