Repository navigation
fix(telemetry): bound OTLP trace export with a configurable timeout - #377
Conversation
The trace exporters were built with no timeout, so the SDK's 10s default applied, while the span processor kept its own 30s export budget. Under OTLP/HTTP -- this package's default transport -- the exporter's timeout is the HTTP client's per-request deadline, and a request that trips it is classified retryable and sent again; only the processor's budget bounds that retry. A destination that accepts a batch but answers slower than 10s is therefore handed the same batch twice, and because the retry succeeds nothing is logged on this side. A receiver that counts what it receives then counts those spans twice. That is not hypothetical here: a custom base path on Endpoint is how a caller targets a third-party ingest route, which is exactly the kind of destination that both counts spans and answers slowly. Config gains an optional ExportTimeout, defaulting to 30s when unset, and it is applied to the HTTP exporter, the gRPC exporter and the batch processor together. Giving the processor the same budget is what closes the window: its own default is 30s, so a larger ExportTimeout would otherwise be silently truncated, and it is also what bounds the retry. The field is additive and the default is applied for a zero value, so existing callers keep working without change. Co-Authored-By: Claude Opus 5 <[email protected]>
aponcedeleonch
left a comment
There was a problem hiding this comment.
LGTM. This closes the duplicate-delivery window for every consumer of the composite provider, sprout included.
My only comment is that there's no way to set the value through providers. ExportTimeout is added to otlp.Config, but there's no providers.WithExportTimeout option, and providers_strategy.go builds the config without it. So callers of NewCompositeProvider always get 30s.
On top of that, passing WithTimeout and WithExportTimeout explicitly overrides OTEL_EXPORTER_OTLP_TRACES_TIMEOUT and OTEL_BSP_EXPORT_TIMEOUT, since the SDK applies env first and options after. Today a caller like sprout can tune the timeout through env vars. After this it can't tune it at all. That's fine for an in-cluster collector, but it won't be once a composite-provider caller points at a third-party ingest. A WithExportTimeout provider option wired through the strategy would keep that door open.
ExportTimeout landed on otlp.Config but nothing built that config with it: providers_strategy.go constructs the traces config field by field, so every NewCompositeProvider caller got exactly DefaultExportTimeout with no way to ask for anything else. That gap is sharper than a missing setter. Passing WithTimeout and WithExportTimeout explicitly overrides OTEL_EXPORTER_OTLP_TRACES_TIMEOUT and OTEL_BSP_EXPORT_TIMEOUT, because the SDK applies env config first and options after -- NewHTTPConfig calls ApplyHTTPEnvConfigs before the option loop, and NewBatchSpanProcessor reads the env var only to seed the default it then lets options overwrite. So a composite-provider caller that tuned the export deadline through env vars lost that lever and gained nothing in its place. Config gains ExportTimeout, WithExportTimeout sets it, and the traces strategy passes it through to otlp.Config. The option is a plain setter: a non-positive value stays verbatim and otlp.Config normalizes it, so the provider layer never hides what the caller asked for. The strategy test drives a built provider against an ingest that never answers and asserts the flush gives up on the configured budget. A field assertion would pass with the wiring removed; this one takes 10s instead of 150ms. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Good catch on both counts — I verified them before acting, and they hold:
Fixed in 1b38b55: The strategy test drives a built provider against an ingest that never answers and asserts the flush gives up on the configured budget, rather than asserting the struct field. I checked it fails for the right reason: with the one-line wiring removed it takes 10s instead of 150ms. One thing worth naming that your comment implies but doesn't quite say: the env override also applies to direct That's inherent to overriding a bad SDK default — you can't beat the 10s default without also beating env. If we want to keep the env lever for unset callers, the fix is to read those two vars when
|
aponcedeleonch
left a comment
There was a problem hiding this comment.
LGTM, thanks for wiring WithExportTimeout through the strategy. Driving a real provider against an unresponsive ingest in the test is a nice touch.
One thing to keep in mind for a follow-up. Since the trace path now always passes an explicit timeout, sprout loses the OTel env vars (OTEL_EXPORTER_OTLP_TRACES_TIMEOUT, OTEL_EXPORTER_OTLP_TIMEOUT, OTEL_BSP_EXPORT_TIMEOUT) as soon as it bumps toolhive-core. Its telemetry.Config has no timeout field today, so it'll be stuck on a hard 30s.
There are two ways to reopen that:
- Sprout follow-up: add an
ExportTimeoutfield to sprout'stelemetry.Config, populate it from its own config incmd/sprout/main.go, and passproviders.WithExportTimeout. - toolhive-core follow-up: the one you suggested. When
ExportTimeoutis zero, read the env vars and only fall back to 30s if none are set. That keeps the env lever for every composite-provider caller without code changes, and an explicit option still wins.
I'll leave it up to you which one to pick. Neither blocks this PR.
…nv vars (#379) 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]>
What
The OTLP trace exporters were built with no timeout, so the SDK's 10s default applied, while the batch span processor kept its own 30s export budget.
Under OTLP/HTTP — this package's default transport — the exporter's timeout is the HTTP client's per-request deadline, and a request that trips it is classified retryable and sent again; only the processor's budget bounds that retry. A destination that accepts a batch but answers slower than 10s is therefore handed the same batch twice, and because the retry succeeds nothing is logged on this side. A receiver that counts what it receives then counts those spans twice.
That is not hypothetical here: a custom base path on
Endpointis how a caller targets a third-party ingest route, which is exactly the kind of destination that both counts spans and answers slowly.How
Configgains an optionalExportTimeout, defaulting to 30s when unset or non-positive, applied to the HTTP exporter, the gRPC exporter, and the batch processor together.Giving the processor the same budget is what closes the window: its own default is 30s, so a larger
ExportTimeoutwould otherwise be silently truncated, and it is also what bounds the exporter's retry.The field is additive and the default is applied for a zero value, so existing callers keep working without change.
Scope: traces only
ExportTimeoutis wired to the trace path only, and its doc comment says so. Metrics and logs have the same asymmetry and are deliberately left for a follow-up:otlpmetrichttpDefaultTimeoutis 10s, whilemetrics.gobuildssdkmetric.NewPeriodicReader(exporter)with no options — the reader's own default timeout is 30s. That is the identical exporter-vs-processor gap this PR fixes for traces.logging.gobuilds its exporters with no timeout for the same reason.Widening the field to all three signals is a larger change to a shared
Config, and worth doing on its own. Happy to fold it in here instead if reviewers prefer.Testing
ExportTimeout, so a flipped outcome can only be attributed to it. The permissive run also proves the endpoint is sound, so the strict run's failure is not a dial or handshake error in disguise.ForceFlushagainst an unresponsive ingest honors the configured budget rather than the processor's own 30s.task(lint +go vet+go test -race) andtask license-checkboth pass. Package coverage is 83.3%.🤖 Generated with Claude Code