Skip to content

feat: link ColdBrew trace ID to OTEL span as attribute#22

Merged
ankurs merged 3 commits intomainfrom
perf/link-trace-id-to-otel-span
Apr 3, 2026
Merged

feat: link ColdBrew trace ID to OTEL span as attribute#22
ankurs merged 3 commits intomainfrom
perf/link-trace-id-to-otel-span

Conversation

@ankurs
Copy link
Copy Markdown
Member

@ankurs ankurs commented Apr 2, 2026

Summary

  • Set coldbrew.trace_id attribute on the OTEL span after resolving the trace ID in SetTraceId()
  • Connects the ColdBrew correlation ID to the distributed trace for easier cross-system debugging
  • Also cleans up conditional ordering in SetTraceId for clarity

Test plan

  • go test -race ./... passes
  • Verify coldbrew.trace_id appears in OTEL span attributes

Summary by CodeRabbit

Release Notes

  • Chores
    • Updated logging library to latest version and removed indirect logging dependencies.
    • Promoted OpenTelemetry to direct dependency for tracing infrastructure.
    • Enhanced trace ID resolution with stricter priority ordering and improved fallback handling.

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.
Copilot AI review requested due to automatic review settings April 2, 2026 18:24
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 2, 2026

Warning

Rate limit exceeded

@ankurs has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 29 minutes and 47 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 72c6ebc8-3886-4f91-a1d0-1cfc5d079b0f

📥 Commits

Reviewing files that changed from the base of the PR and between 3eb643d and fe5d5cb.

📒 Files selected for processing (1)
  • notifier/notifier.go
📝 Walkthrough

Walkthrough

Updated 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

Cohort / File(s) Summary
Dependencies
go.mod
Updated github.com/go-coldbrew/log to v0.2.8, promoted go.opentelemetry.io/otel v1.42.0 from indirect to direct, and removed indirect dependencies github.com/go-kit/log and github.com/go-logfmt/logfmt.
Trace ID Resolution
notifier/notifier.go
Refactored SetTraceId to enforce stricter priority ordering for trace ID resolution (gRPC metadata → OTEL span → UUID fallback) and added logic to set OTEL span attribute coldbrew.trace_id when a valid span exists.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Dependencies aligned, priorities clear,

Trace IDs flow through metadata first, no fear,

OpenTelemetry marks the way,

With gRPC leading, OTEL's play,

A UUID beacon when paths disappear! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: linking the ColdBrew trace ID to OTEL span as an attribute, which is the primary feature introduced in the PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/link-trace-id-to-otel-span

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

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 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_id as an OTEL span attribute after resolving the trace ID.
  • Promote go.opentelemetry.io/otel from indirect to direct dependency (needed for attribute).

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.

Comment thread notifier/notifier.go
Comment thread notifier/notifier.go
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🟠 Major

Early return skips OTEL linking when trace ID already exists.

At Line 537, returning immediately means coldbrew.trace_id is 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 string

Also 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

📥 Commits

Reviewing files that changed from the base of the PR and between c46c89c and 3eb643d.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (2)
  • go.mod
  • notifier/notifier.go

Copy link
Copy Markdown

Copilot AI left a comment

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

Comment thread notifier/notifier.go
Copy link
Copy Markdown

Copilot AI left a comment

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

@ankurs ankurs merged commit f456431 into main Apr 3, 2026
15 checks passed
@ankurs ankurs deleted the perf/link-trace-id-to-otel-span branch April 3, 2026 07:46
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