Skip to content

feat(telemetry): add sampler override and exact traces endpoint - #383

Merged
aponcedeleonch merged 3 commits into
mainfrom
feat/otlp-sampler-traces-endpoint
Oct 15, 2026
Merged

aponcedeleonch merged 3 commits into
mainfrom
feat/otlp-sampler-traces-endpoint

Conversation

@aponcedeleonch

@aponcedeleonch aponcedeleonch commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Builds on #377 and #379 (both merged), so one release carries all three.

What

Two hardcoded behaviours in the tracer built by providers.NewCompositeProvider keep spans from reaching some destinations:

  1. otlp/tracing.go always used ParentBased(TraceIDRatioBased(SamplingRate)). An upstream proxy that samples at a low rate and forwards an unsampled W3C traceparent makes 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).
  2. The HTTP trace exporter always appended /v1/traces to 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, and SamplingRate is then ignored. Nil keeps today's ParentBased(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 to otlptracehttp.WithEndpointURL: no /v1/traces suffix, and the scheme decides TLS.
    • Overrides the traces signal only. Metrics and logs keep OTLPEndpoint.
    • Works with OTLPEndpoint unset (traces-only). The strategy selector treats either endpoint as a traces destination, and metrics/logs stay no-op.
    • With a gRPC traces protocol (via WithProtocol or WithTracesProtocol) it's a config error, since exact paths are an HTTP concept.
    • WithHeaders and WithCACertPath still apply.

Two choices worth a look:

  • Insecure is not applied to TracesEndpoint. It describes OTLPEndpoint, and applying it on top would downgrade an https:// traces URL to plain HTTP.
  • The URL is validated up front: http/https scheme, host present, no userinfo, query or fragment, and a path the exporter can send exactly as written. The SDK's WithEndpointURL logs an unparseable URL and carries on with its defaults, silently drops userinfo and the query, and rebuilds the request from the decoded path (so %2F reaches the wire as /), so any of those would send traces somewhere other than where the caller pointed them. Credentials belong in WithHeaders.
  • The traces endpoint URL never appears in errors or logs, since its path, query or userinfo can carry a credential. Logs and error wrappers show only its scheme and host.

Follow-ups from the #379 review

The second commit addresses the two nits left on #379:

  • The OTel timeout variables are read through env.Reader rather than os.LookupEnv. otlp.Config gains an EnvReader field that falls back to the OS environment when nil, the same pattern as networking.ValidatingTransport.
  • A timeout variable that is set but unparseable or non-positive still falls through to the next tier, and is now also reported via otel.Handle, matching the SDK.

Testing

All against httptest servers recording request paths:

  • Sampler: a never-sample sampler exports nothing even at rate 1.0; a remote-not-sampled override yields sampled, exported spans under an unsampled remote parent; a nil sampler keeps sampling root spans and keeps following an unsampled remote parent.
  • TracesEndpoint is posted to at exactly /v2/telemetry/sink-abc, while metrics go to OTLPEndpoint + /v1/metrics and the collector sees no traces. Assertions use the received RequestURI, not the decoded path, and cover a trailing slash, a preserved escape and the root.
  • Traces-only: export works with no OTLPEndpoint, and the meter and logger providers are no-op.
  • An https:// TracesEndpoint with Insecure set still uses TLS (verified the test fails if Insecure leaks through).
  • gRPC + TracesEndpoint errors through NewCompositeProvider, plus a table of invalid URLs (userinfo, query, escaped slash, trimmed trailing space, unparseable).
  • Sentinel-secret checks: a credential in the path, query or userinfo never reaches the returned error or the debug logs, through NewCompositeProvider.
  • Timeout variables: an injected EnvReader is 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) and task license-check pass.

🤖 Generated with Claude Code

Base automatically changed from feat/otlp-export-timeout-all-signals to main October 15, 2026 11:58
aponcedeleonch and others added 2 commits October 15, 2026 15:00
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]>
@aponcedeleonch
aponcedeleonch force-pushed the feat/otlp-sampler-traces-endpoint branch from 1689af9 to 2e4c2fc Compare October 15, 2026 12:01

@JAORMX JAORMX left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread telemetry/providers/otlp/tracing.go Resolved
Comment thread telemetry/providers/otlp/endpoint.go Resolved
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 JAORMX left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@aponcedeleonch
aponcedeleonch merged commit 964aa6a into main Oct 15, 2026
6 checks passed
@aponcedeleonch
aponcedeleonch deleted the feat/otlp-sampler-traces-endpoint branch October 15, 2026 12:27
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