feat(telemetry): propagate W3C traceparent from parent process#352
Merged
lizhengfeng101 merged 1 commit intoJul 14, 2026
Merged
Conversation
- Add ContextWithTraceParentFromEnv to extract TRACEPARENT env var and inject upstream span context via OTel TextMapPropagator. - Register TraceContext+Baggage composite propagator in Init(). - Wire trace parent propagation into review and scan entry points. - Add tests for valid, absent, disabled, and malformed TRACEPARENT.
Contributor
|
✅ OpenCodeReview: No comments generated. Looks good to me. |
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.
Description
When OCR is invoked by a parent process (e.g. Claude Code), the parent sets a
TRACEPARENTenvironment variable following the W3C Trace Context specification. Previously, OCR always started a new root trace, making it impossible to correlate OCR spans with the caller's trace.This PR adds
ContextWithTraceParentFromEnv()which reads theTRACEPARENTenv var and injects the upstream span context into the Go context via the OTelTextMapPropagator. Both thereviewandscancommands now use this function so their spans become children of the upstream trace. ATraceContext + Baggagecomposite propagator is registered duringInit()to support extraction.Type of Change
How Has This Been Tested?
make testpasses locallyAdded
TestContextWithTraceParentFromEnv_Extracts— verifies a valid TRACEPARENT is extracted and child spans inherit the upstream trace ID.Added
TestContextWithTraceParentFromEnv_AbsentOrDisabled— verifies no span context is injected when telemetry is disabled or TRACEPARENT is unset.Added
TestContextWithTraceParentFromEnv_Malformed— verifies malformed TRACEPARENT values are gracefully ignored (no panic, no invalid span context).All tests pass with
go test -shuffle=on.Checklist
go fmt,go vet)Related Issues
N/A