Skip to content

[probes.http] Add opt-in OpenTelemetry tracing - #1358

Merged
manugarg merged 1 commit into
cloudprober:mainfrom
cbroglie:otel-http-tracing
Sep 22, 2026
Merged

manugarg merged 1 commit into
cloudprober:mainfrom
cbroglie:otel-http-tracing

Conversation

@cbroglie

@cbroglie cbroglie commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Cloudprober is the client in HTTP probes, so it now starts the root span for each sampled request and exports it to an OTLP collector. This makes probe requests visible in distributed traces and propagates W3C trace context to the target.

Tracing is configured globally via a new top-level tracing block and is off by default. When configured, all tracing-capable probes (HTTP today) are instrumented automatically; there are no per-probe tracing options.

@cbroglie

cbroglie commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Happy to make any tweaks to the config/tracer setup, I just made some arbitrary choices. But the functionality is working as expected in my testing.

@cbroglie
cbroglie force-pushed the otel-http-tracing branch from bdcbb50 to 521e80e Compare June 9, 2026 18:19
@manugarg

Copy link
Copy Markdown
Contributor

@cbroglie I was out on vacation for the last few weeks. I'll take a look at it in the next few days.

@manugarg manugarg 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.

Sorry for the late review.

Comment thread internal/tracing/tracing.go Resolved
Comment thread internal/tracing/tracing.go Resolved
Comment thread probes/http/http.go Resolved
Comment thread internal/tracing/tracing.go Resolved
Comment thread internal/tracing/tracing.go Resolved
Comment thread internal/tracing/proto/config.proto Resolved
Comment thread internal/tracing/tracing.go Resolved
@cbroglie
cbroglie force-pushed the otel-http-tracing branch from 521e80e to a8c78b3 Compare July 17, 2026 21:53
@cbroglie

Copy link
Copy Markdown
Contributor Author

No worries! Addressed the feedback.

@manugarg manugarg 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.

Sorry @cbroglie for late reviews. Review agent came up with a few more things. Looks mostly right to me. Can you please take a look?

Comment thread cloudprober.go Resolved
Comment thread probes/http/http.go Resolved
Comment thread probes/http/http.go Resolved
Comment thread probes/http/http.go Resolved
Comment thread internal/tracing/tracing.go Resolved
Comment thread internal/tracing/proto/config.proto Resolved
@cbroglie

cbroglie commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Sorry for the slow turnaround, but I think everything has been addressed now!

@manugarg manugarg 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.

Thanks for sticking with this @cbroglie, and sorry for another round. I built the branch, ran the full test suite (all green), config-tested the new example, and ran it end-to-end against a fake OTLP/gRPC collector -- spans, resource attributes, and W3C propagation all work as advertised. The earlier feedback is genuinely addressed: propagator validated before the exporter is built, insecure+TLS rejected, WithEndpointURL, the otelsdk split, the noop meter provider, and the latency-breakdown composition test.

A few things still open; the first two are worth fixing before merge.

Response body not closed on read error (can't inline, line isn't in the diff)

probes/http/http.go:370:

respBody, err := io.ReadAll(resp.Body)
if err != nil {
    l.WithAttributes(p.dynamicHeaderAttrs(req)...).Warning(err.Error())
    return err          // body never closed
}

This is a pre-existing connection leak, but tracing turns it into a span leak too: otelhttp's wrappedBody.Read calls span.End() only on io.EOF; a non-EOF error just sets the status, and only Close() ends the span. So every read failure now also leaks an unended span that the batch processor never sees. A defer resp.Body.Close() right after the client.Do error check fixes both. Happy for this to be a separate PR if you'd rather keep this one focused.

Verification notes

  • go test ./... passes on the branch.
  • go run ./cmd/cloudprober -configtest -config_file examples/tracing/cloudprober.cfg passes.
  • End-to-end against a local OTLP/gRPC receiver: resource comes through as env=review host.name=... service.name=cp-verify, client spans are correctly parented roots with probe/target attributes, and traceparent reaches the target.
  • Binary size: 89.6 MB -> 91.0 MB (+1.6%). Fine.

Comment thread internal/tracing/tracing.go Resolved
Comment thread probes/http/http.go Resolved
Comment thread cloudprober.go Resolved
Comment thread go.mod Resolved
Comment thread internal/tracing/tracing.go Resolved
Comment thread cloudprober.go Resolved
Comment thread cloudprober.go Resolved
Comment thread internal/tracing/proto/config.proto Resolved
Comment thread examples/tracing/cloudprober.cfg Resolved

@manugarg manugarg 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.

@cbroglie sorry for the back and forth here (sometimes AI review agents over-litigate).

I'd like to request one more structural change, this time for simplification. Can you please drop the query-param redaction from this PR. It's complex and will not be used much (at least not right away). It may become part of Otel SDK soon and even if we have to add it ourselves, I'd probably implement it reusing the same code.

Concretely, to remove:

  • internal/tracing/redact_exporter.go and redact_exporter_test.go
  • internal/tracing/otelsdk/redact.go
  • redact_query_params_in_traces (field 26) from probes/http/proto/config.proto, plus regen
  • the spanAttrs marker block in probes/http/http.go
  • the newRedactingExporter wrap in tracing.go

Thanks in advance!

Comment thread probes/http/http.go Resolved
Cloudprober is the client in HTTP probes, so it now starts the root span
for each sampled request and exports it to an OTLP collector. This makes
probe requests visible in distributed traces and propagates W3C trace
context to the target.

Tracing is configured globally via a new top-level `tracing` block and is
off by default. When configured, all tracing-capable probes (HTTP today)
are instrumented automatically; there are no per-probe tracing options.
@cbroglie

Copy link
Copy Markdown
Contributor Author

I'd like to request one more structural change, this time for simplification. Can you please drop the query-param redaction from this PR. It's complex and will not be used much (at least not right away).

More than happy to drop that complexity 👍

@manugarg manugarg changed the title [probes.http] add opt-in OpenTelemetry tracing [probes.http] Add opt-in OpenTelemetry tracing Sep 22, 2026
@manugarg
manugarg merged commit e085d1c into cloudprober:main Sep 22, 2026
11 checks passed
@cbroglie
cbroglie deleted the otel-http-tracing branch September 22, 2026 18:29
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