feat(nats): add OTel span instrumentation#6
Open
bramwelt wants to merge 4 commits into
Open
Conversation
Add OTel client spans to Request(), consumer spans to QueueSubscribe() with context-aware handler signature, and otelhttp transport to forwardemail and JWKS HTTP clients. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Issue: LFXV2-1743 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Trevor Bramwell <tbramwell@linuxfoundation.org>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds OpenTelemetry tracing instrumentation around the service’s NATS messaging and key outbound HTTP clients, enabling end-to-end trace context propagation across NATS headers and HTTP requests.
Changes:
- Introduces a
natsHeaderCarrierto inject/extract trace context via NATS message headers. - Instruments NATS
Request()(client span + context injection) andQueueSubscribe()handlers (consumer span + context extraction), updating subscription call sites accordingly. - Wraps ForwardEmail and Auth0 JWKS HTTP clients with
otelhttp.NewTransportand updates OTel-related dependencies.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/infrastructure/nats/tracing.go | Adds natsHeaderCarrier and package tracer used for NATS trace propagation. |
| internal/infrastructure/nats/tracing_test.go | Adds unit tests for the NATS header carrier behavior. |
| internal/infrastructure/nats/client.go | Wraps NATS request/consume flows with spans and injects/extracts context from headers. |
| internal/infrastructure/jwt/parser.go | Instruments JWKS HTTP client transport with otelhttp. |
| internal/infrastructure/forwardemail/client.go | Instruments ForwardEmail HTTP client transport with otelhttp. |
| cmd/forwards-api/service/subscriptions.go | Updates NATS queue subscription handlers to accept a propagated context.Context. |
| go.mod | Adds otelhttp/testify and bumps OTel core modules; introduces mixed OTel minor versions. |
| go.sum | Records checksums for newly added/updated dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replace manual OTLP exporter and propagator setup with autoexport and autoprop. Configuration is now driven entirely by OTEL_* environment variables. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Issue: LFXV2-1743 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Trevor Bramwell <tbramwell@linuxfoundation.org>
- internal/infrastructure/nats/tracing.go: add nil guard to natsHeaderCarrier.Set() to prevent panic on nil map assignment (per copilot[bot]) Resolves 1 review thread. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Issue: LFXV2-1743 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Trevor Bramwell <tbramwell@linuxfoundation.org>
Contributor
Author
Review Feedback AddressedCommit: 1fcd6d3 Changes Made
No Change Needed
Threads Resolved5 of 5 unresolved threads addressed. |
Contributor
Author
Review Feedback Addressed (Round 2)No Change Needed
Threads Resolved1 of 1 unresolved threads addressed. |
Addresses CVEs GO-2026-5020, GO-2026-5006, GO-2026-5017, GO-2026-5019, GO-2026-5021, GO-2026-5023 flagged by grype. All fixed in golang.org/x/crypto v0.52.0. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Issue: LFXV2-1743 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Trevor Bramwell <tbramwell@linuxfoundation.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
natsHeaderCarriertype implementingpropagation.TextMapCarrierfor NATS header-based trace context propagationRequest()with aSpanKindClientspan that injects trace context into outbound NATS message headersQueueSubscribe()handler signature tofunc(ctx context.Context, msg *nats.Msg)and addsSpanKindConsumerspan that extracts trace context from inbound message headers; updates all 3 call sites insubscriptions.gootelhttp.NewTransportfor outbound HTTP tracingIssue: LFXV2-1743
🤖 Generated with Claude Code