Skip to content
This repository was archived by the owner on Aug 5, 2026. It is now read-only.

otel: inject traceparent on cdc→chart-inspector outbound call - #13

Merged
braghettos merged 1 commit into
mainfrom
otel-outbound-propagation
Jun 29, 2026
Merged

otel: inject traceparent on cdc→chart-inspector outbound call#13
braghettos merged 1 commit into
mainfrom
otel-outbound-propagation

Conversation

@braghettos

Copy link
Copy Markdown
Collaborator

What

Closes the cdc→chart-inspector trace-propagation gap. The cdc's outbound GET {server}/resources call to chart-inspector (internal/chartinspector/chartinspector.go) used a bare http.DefaultClient with no otelhttp instrumentation and no traceparent injection — so the chart-inspector server span was never linked to the active reconcile span by HTTP header (it relied solely on the annotation path). (Note: internal/tools/tracer is a debug RoundTripper, not OTel — untouched.)

Fix

  • Wrap the client transport with go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp NewTransport(http.DefaultTransport), so the request injects the W3C traceparent header (continuing the active reconcile span) and emits a client span.
  • Thread the reconcile ctx through RBACGen.GenerateChartInspector.Resources and build the request with http.NewRequestWithContext(ctx, ...) so the span/headers actually propagate. The metrics wrappers now pass the real reconcile ctx instead of context.Background().
  • Stop mutating the shared http.DefaultClient global (latent bug) — construct a dedicated client.
  • Added otelhttp v0.61.0 as a direct dep (already in go.sum, matching the OTel train); go mod tidy.

Default-off

The otelhttp transport is a cheap pass-through when no global tracer provider is registered. The W3C propagator is installed unconditionally by the runtime, so the cdc→chart-inspector link is established only when tracing is active — the off-path stays effectively no-op.

Verify

go build ./..., go vet ./..., and the affected unit tests (internal/chartinspector, internal/rbacgen) all pass.

🤖 Generated with Claude Code

The cdc's outbound GET {server}/resources call to chart-inspector used a
bare http.DefaultClient with no otelhttp instrumentation and no traceparent
injection, so the chart-inspector server span was never linked to the active
reconcile span by HTTP header (it relied solely on the annotation path).

Wrap the client transport with otelhttp.NewTransport(http.DefaultTransport)
so the request injects the W3C traceparent header (continuing the active
reconcile span) and emits a client span, and thread the reconcile ctx through
RBACGen.Generate → ChartInspector.Resources via http.NewRequestWithContext so
the span/headers actually propagate. Also stop mutating the shared
http.DefaultClient global.

Default-off: the otelhttp transport is a cheap pass-through when no global
tracer provider is registered; the W3C propagator is installed unconditionally
by the runtime, so the link is established only when tracing is active.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FzZJtQ4bEMHuK4CvF6eBuL
@braghettos
braghettos merged commit 44d84ca into main Jun 29, 2026
3 checks passed
@braghettos
braghettos deleted the otel-outbound-propagation branch June 29, 2026 20:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant