Repository navigation
feat(telemetry): add sampler override and exact traces endpoint - #383
Conversation
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]>
…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]>
1689af9 to
2e4c2fc
Compare
JAORMX
left a comment
There was a problem hiding this comment.
Panel review covering OpenTelemetry semantics and operational practices, API/correctness, and security. Requesting changes for the two concrete issues noted inline: exact endpoint paths can be changed on the wire, and raw endpoint URLs can expose credentials in diagnostics.
The sampler override, backwards-compatible default, scheme-driven TLS, and signal-specific endpoint isolation look appropriate. Non-blocking telemetry guidance: document that overriding an unsampled remote parent can produce traces with missing upstream parents, and that sampling every span does not make usage/cost accounting lossless; authoritative billing needs durable, idempotent records. Empty timeout environment variables should also be treated as unset rather than diagnosed as invalid.
All six CI checks passed for this revision; no local tests or linters were run. The existing partial-construction cleanup issue is not treated as a blocker for this PR.
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]>
JAORMX
left a comment
There was a problem hiding this comment.
Re-ran the panel review against 3623a08 covering OpenTelemetry behavior, API/correctness, and security. Both previous blockers are resolved: endpoint validation rejects paths the SDK would rewrite, with RequestURI regression coverage; validation errors and provider diagnostics no longer disclose the raw traces URL, userinfo is rejected, and sentinel-secret tests cover logs and returned errors. The sampler caveats and empty timeout environment handling are also addressed. No remaining merge-blocking findings. All six checks are green for this revision; no local tests or linters were run.
What
Two hardcoded behaviours in the tracer built by
providers.NewCompositeProviderkeep spans from reaching some destinations:otlp/tracing.goalways usedParentBased(TraceIDRatioBased(SamplingRate)). An upstream proxy that samples at a low rate and forwards an unsampled W3Ctraceparentmakes every downstream span non-sampled, whatever the service's own rate. Behind a proxy sampling at 5%, ~95% of the service's spans are dropped, including ones it needs exported on every request (e.g. spans carrying usage or cost data)./v1/tracesto the endpoint path, so exact-path ingest routes (e.g.https://ingest.example.com/v2/telemetry/<sink>) were unreachable.How
providers.WithSampler(sdktrace.Sampler)→otlp.Config.Sampler. Used as given when non-nil, andSamplingRateis then ignored. Nil keeps today'sParentBased(TraceIDRatioBased(rate))exactly, so existing callers see no change. Callers can pass e.g.ParentBased(ratio, WithRemoteParentNotSampled(ratio))to keep sampling locally under an unsampled remote parent.providers.WithTracesEndpoint(url)→otlp.Config.TracesEndpoint. Over http/protobuf it goes verbatim tootlptracehttp.WithEndpointURL: no/v1/tracessuffix, and the scheme decides TLS.OTLPEndpoint.OTLPEndpointunset (traces-only). The strategy selector treats either endpoint as a traces destination, and metrics/logs stay no-op.WithProtocolorWithTracesProtocol) it's a config error, since exact paths are an HTTP concept.WithHeadersandWithCACertPathstill apply.Two choices worth a look:
Insecureis not applied toTracesEndpoint. It describesOTLPEndpoint, and applying it on top would downgrade anhttps://traces URL to plain HTTP.WithEndpointURLlogs an unparseable URL and carries on with its defaults, silently drops userinfo and the query, and rebuilds the request from the decoded path (so%2Freaches the wire as/), so any of those would send traces somewhere other than where the caller pointed them. Credentials belong inWithHeaders.Follow-ups from the #379 review
The second commit addresses the two nits left on #379:
env.Readerrather thanos.LookupEnv.otlp.Configgains anEnvReaderfield that falls back to the OS environment when nil, the same pattern asnetworking.ValidatingTransport.otel.Handle, matching the SDK.Testing
All against
httptestservers recording request paths:TracesEndpointis posted to at exactly/v2/telemetry/sink-abc, while metrics go toOTLPEndpoint+/v1/metricsand the collector sees no traces. Assertions use the receivedRequestURI, not the decoded path, and cover a trailing slash, a preserved escape and the root.OTLPEndpoint, and the meter and logger providers are no-op.https://TracesEndpointwithInsecureset still uses TLS (verified the test fails ifInsecureleaks through).TracesEndpointerrors throughNewCompositeProvider, plus a table of invalid URLs (userinfo, query, escaped slash, trimmed trailing space, unparseable).NewCompositeProvider.EnvReaderis consulted instead of the process environment, and unusable values are reported through the OTel error handler while valid and absent ones are not.go test -race ./telemetry/...,go vet ./...,golangci-lint(v2.14.0) andtask license-checkpass.🤖 Generated with Claude Code