feat(nats): add OTel span instrumentation#16
Open
bramwelt wants to merge 4 commits into
Open
Conversation
Add OTel client spans to Request(), consumer spans to SubscribeWithTransportMessenger(), and otelhttp transport to CDP and Query Service 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>
There was a problem hiding this comment.
Pull request overview
This PR introduces OpenTelemetry (OTel) tracing for outbound/inbound NATS messaging (context propagation + spans) and adds outbound HTTP client tracing for the CDP and Query service clients, improving end-to-end observability across inter-service calls.
Changes:
- Added an OTel
TextMapCarrieradapter fornats.Headerand unit tests for it. - Instrumented NATS request/reply (
SpanKindClient) and subscription message processing (SpanKindConsumer) with context injection/extraction. - Added
otelhttptransport wrapping for default CDP and Query HTTP clients.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/infrastructure/query/client.go | Adds otelhttp.NewTransport to instrument outbound Query Service HTTP requests. |
| internal/infrastructure/cdp/client.go | Adds otelhttp.NewTransport to instrument outbound CDP HTTP requests. |
| internal/infrastructure/nats/client.go | Wraps NATS request/subscribe flows with spans and injects/extracts trace context via headers. |
| internal/infrastructure/nats/tracing.go | Introduces natsHeaderCarrier implementing propagation.TextMapCarrier. |
| internal/infrastructure/nats/tracing_test.go | Adds tests validating natsHeaderCarrier behavior and interface conformance. |
💡 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]) - internal/infrastructure/cdp/client.go: wrap non-nil HTTPClient transport with otelhttp when a custom client is provided (per copilot[bot]) - internal/infrastructure/query/client.go: wrap non-nil HTTPClient transport with otelhttp when a custom client is provided (per copilot[bot]) Resolves 3 review threads. 🤖 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: 314bd61 Changes Made
No Change Needed
Threads Resolved10 of 10 unresolved threads addressed. |
- pkg/utils/otel.go: restore OTEL_TRACES_SAMPLE_RATIO support — parse the env var and wire it into TracerProvider as ParentBased(TraceIDRatioBased(ratio)); the Helm chart injects this var so dropping it silently broke sampling (per copilot[bot]) Resolves 2 review threads. 🤖 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 Addressed (Round 2)Commit: 62256af Changes Made
Threads Resolved2 of 2 unresolved threads addressed. |
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 headersSpanKindConsumerspan toSubscribeWithTransportMessenger()that extracts trace context from inbound message headersotelhttp.NewTransportfor outbound HTTP tracingIssue: LFXV2-1743
🤖 Generated with Claude Code