Feat: Add OTel trace context propagation to AuthBridge#497
Conversation
|
Warning Review limit reached
More reviews will be available in 53 minutes. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThis PR adds OpenTelemetry distributed tracing to authbridge. A new otelbridge module conditionally initializes tracing from environment variables and provides trace context extraction/injection helpers. Two plugins (JWT validation and token exchange) integrate trace propagation into their request handling. The application entry point wires OTel initialization with proper lifecycle management. ChangesOpenTelemetry Tracing Support
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
3011057 to
139dcbd
Compare
AuthBridge sits in the request path but currently breaks trace continuity. This adds propagator setup so traceparent headers flow through inbound → outbound without being dropped. Gated on OTEL_EXPORTER_OTLP_ENDPOINT — zero behavioral change when unset. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Parul Singh <parsingh@redhat.com>
139dcbd to
8f9fe4f
Compare
Ladas
left a comment
There was a problem hiding this comment.
Code Review + Security Review
What it does
Adds W3C Trace Context propagation to AuthBridge so traceparent / tracestate headers survive the inbound→outbound authentication path. Three integration points:
otelbridge.Init()— initializes OTel TracerProvider with OTLP HTTP exporter, gated onOTEL_EXPORTER_OTLP_ENDPOINT. Returns no-op when unset — zero behavioral change by default.- JWT validation plugin —
ExtractTraceContext()on inbound request, populatingctxwith the caller's trace/span. - Token exchange plugin —
ExtractTraceContext()on outbound request, thenInjectTraceContext()after token replacement to propagate the trace ID downstream.
Code quality
- Clean separation:
otelbridgepackage handles all OTel setup and W3C propagation. Plugins only callExtract/Inject. Init()returns a(shutdown, error)tuple — correct lifecycle pattern for OTel SDK.- Propagator is
propagation.TraceContext{}(W3C standard) — correct choice for HTTP. - Service name falls back to
"authbridge"whenOTEL_SERVICE_NAMEis unset. - Tests cover: no-endpoint no-op, endpoint initialization, extract/inject round-trip, trace ID preservation. Good coverage.
Security Review
No security issues found.
-
No credentials exposed. The OTel exporter reads
OTEL_EXPORTER_OTLP_ENDPOINTfrom env — no secrets in code. The OTLP HTTP exporter uses the standard OTel SDK env vars for auth (OTEL_EXPORTER_OTLP_HEADERS), which is the correct pattern. -
No header leakage.
ExtractTraceContextreadstraceparent/tracestateonly (W3C propagator).InjectTraceContextwritestraceparent/tracestateonly. No auth headers (Authorization, cookies) are touched by the OTel propagation layer. -
Trace context injection placement is correct. In
tokenexchange/plugin.go,InjectTraceContextis called on theActionReplaceTokenbranch AFTER the token is set in theAuthorizationheader. This means the trace propagation doesn't interfere with or override the auth header — they operate on different header keys. -
No new network surface. The OTLP HTTP exporter connects to the configured endpoint (typically
otel-collectorwithin the cluster). WhenOTEL_EXPORTER_OTLP_ENDPOINTis unset, no connections are made. No new ports, routes, or ingress. -
log.Fatalfon OTel init failure — this is appropriate for a sidecar process. If the operator explicitly configures tracing and it fails to initialize, crashing early is better than silently dropping traces. -
Dependency additions are standard. OTel SDK v1.43.0,
otlptracehttpexporter,cenkalti/backoff/v5(transitive). All are widely-used, well-maintained.
Minor observations (non-blocking)
-
The test
TestInit_NoEndpointchecks thatTraceContextpropagator is NOT set when endpoint is unset. This is correct but fragile — if a previous test in the same process set it (e.g.,TestInit_WithEndpoint), the global state would leak. The tests work because Go runs them in declaration order andTestInit_NoEndpointruns first. Considert.Cleanupto reset the global propagator, or accept the ordering dependency. -
go.sumdiff is large but mechanical — dependency version bumps from adding OTel SDK.
APPROVE — clean, well-tested, correct security posture.
Summary
Test plan
Assisted-By: Claude (Anthropic AI) noreply@anthropic.com
Summary by CodeRabbit
OTEL_EXPORTER_OTLP_ENDPOINTandOTEL_SERVICE_NAMEenvironment variables for OTLP trace collection