feat: link ColdBrew trace ID to OTEL span as attribute#22
Conversation
Set coldbrew.trace_id attribute on the OTEL span after resolving the trace ID, connecting the ColdBrew correlation ID to the distributed trace for easier cross-system debugging.
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 29 minutes and 47 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughUpdated dependencies to include OpenTelemetry as a direct requirement and refactored trace ID resolution in the notifier to enforce stricter priority ordering: prefer gRPC metadata, fall back to OTEL span trace ID, then generate UUID. Added OTEL span attribute assignment for resolved trace ID. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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 |
There was a problem hiding this comment.
Pull request overview
This PR links the ColdBrew correlation/trace ID to the active OpenTelemetry span by setting a coldbrew.trace_id span attribute in SetTraceId(), improving cross-system traceability between app logs/errors and distributed traces.
Changes:
- Update
SetTraceId()to resolve trace ID with clearer precedence (gRPC metadata → OTEL span → UUID). - Set
coldbrew.trace_idas an OTEL span attribute after resolving the trace ID. - Promote
go.opentelemetry.io/otelfrom indirect to direct dependency (needed forattribute).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| notifier/notifier.go | Resolves trace ID with explicit precedence and attaches resolved ID to the OTEL span as an attribute. |
| go.mod | Adds go.opentelemetry.io/otel as a direct dependency to support the new attribute import. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
notifier/notifier.go (1)
537-539:⚠️ Potential issue | 🟠 MajorEarly return skips OTEL linking when trace ID already exists.
At Line 537, returning immediately means
coldbrew.trace_idis never set on the active span for contexts that already carry a trace ID, which defeats the new correlation behavior in those paths.Proposed fix
func SetTraceId(ctx context.Context) context.Context { - if GetTraceId(ctx) != "" { - return ctx - } + if existing := strings.TrimSpace(GetTraceId(ctx)); existing != "" { + if span := oteltrace.SpanFromContext(ctx); span.SpanContext().IsValid() { + span.SetAttributes(otelattr.String("coldbrew.trace_id", existing)) + } + return ctx + } var traceID stringAlso applies to: 565-567
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@notifier/notifier.go` around lines 537 - 539, The early return when GetTraceId(ctx) != "" prevents setting the coldbrew.trace_id attribute on the active span; instead of returning immediately in that branch, fetch the active span from the context (e.g., via trace.SpanFromContext(ctx) or existing span helper) and set the coldbrew.trace_id attribute to GetTraceId(ctx), then return the original ctx. Apply the same change for the second occurrence (the block around lines 565-567): do not skip linking, but set the span attribute when a trace ID already exists and then return.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@notifier/notifier.go`:
- Around line 537-539: The early return when GetTraceId(ctx) != "" prevents
setting the coldbrew.trace_id attribute on the active span; instead of returning
immediately in that branch, fetch the active span from the context (e.g., via
trace.SpanFromContext(ctx) or existing span helper) and set the
coldbrew.trace_id attribute to GetTraceId(ctx), then return the original ctx.
Apply the same change for the second occurrence (the block around lines
565-567): do not skip linking, but set the span attribute when a trace ID
already exists and then return.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 909b8a35-7151-4f22-a5b5-b38692e51698
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (2)
go.modnotifier/notifier.go
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
coldbrew.trace_idattribute on the OTEL span after resolving the trace ID inSetTraceId()Test plan
go test -race ./...passescoldbrew.trace_idappears in OTEL span attributesSummary by CodeRabbit
Release Notes