Skip to content

feat(nats): add OTel span instrumentation#6

Open
bramwelt wants to merge 4 commits into
mainfrom
feat/LFXV2-1743-nats-tracing
Open

feat(nats): add OTel span instrumentation#6
bramwelt wants to merge 4 commits into
mainfrom
feat/LFXV2-1743-nats-tracing

Conversation

@bramwelt

Copy link
Copy Markdown
Contributor

Summary

  • Adds natsHeaderCarrier type implementing propagation.TextMapCarrier for NATS header-based trace context propagation
  • Wraps Request() with a SpanKindClient span that injects trace context into outbound NATS message headers
  • Changes QueueSubscribe() handler signature to func(ctx context.Context, msg *nats.Msg) and adds SpanKindConsumer span that extracts trace context from inbound message headers; updates all 3 call sites in subscriptions.go
  • Wraps ForwardEmail and JWT JWKS HTTP clients with otelhttp.NewTransport for outbound HTTP tracing

Issue: LFXV2-1743

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings June 23, 2026 23:41
@bramwelt bramwelt requested a review from a team as a code owner June 23, 2026 23:41
Comment thread go.mod

Copilot AI 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.

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 natsHeaderCarrier to inject/extract trace context via NATS message headers.
  • Instruments NATS Request() (client span + context injection) and QueueSubscribe() handlers (consumer span + context extraction), updating subscription call sites accordingly.
  • Wraps ForwardEmail and Auth0 JWKS HTTP clients with otelhttp.NewTransport and 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.

Comment thread go.mod Outdated
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>
Comment thread go.mod
Comment thread go.mod
Comment thread go.mod
- 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>
Copilot AI review requested due to automatic review settings June 24, 2026 16:31
@bramwelt

Copy link
Copy Markdown
Contributor Author

Review Feedback Addressed

Commit: 1fcd6d3

Changes Made

  • internal/infrastructure/nats/tracing.go: Added nil guard to natsHeaderCarrier.Set() to prevent panic on nil map assignment (per copilot-pull-request-reviewer)

No Change Needed

  • go.mod: OTel version mix between core SDK and contrib modules — intentional, different Go modules with independent release cadences (flagged by copilot-pull-request-reviewer)
  • go.mod (×4): BSD-3-Clause + Google patent license — standard transitive deps from OpenTelemetry SDK, does not affect LFX MIT-licensed code (flagged by github-license-compliance)

Threads Resolved

5 of 5 unresolved threads addressed.

Copilot AI 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.

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.

Comment thread internal/infrastructure/observability/otel.go
@bramwelt

Copy link
Copy Markdown
Contributor Author

Review Feedback Addressed (Round 2)

No Change Needed

  • internal/infrastructure/observability/otel.go: autoexport handles OTEL_METRICS_EXPORTER=none and OTEL_LOGS_EXPORTER=none with no-op implementations — no unexpected connections or startup failures. Exporters not explicitly set in the Helm chart will use the autoexport default ("otlp"), which is correct for a production service. (flagged by copilot-pull-request-reviewer)

Threads Resolved

1 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>
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