Skip to content

test: verify coldbrew.trace_id OTEL span attribute in SetTraceId#24

Merged
ankurs merged 3 commits intomainfrom
test/otel-trace-id-attribute
Apr 3, 2026
Merged

test: verify coldbrew.trace_id OTEL span attribute in SetTraceId#24
ankurs merged 3 commits intomainfrom
test/otel-trace-id-attribute

Conversation

@ankurs
Copy link
Copy Markdown
Member

@ankurs ankurs commented Apr 3, 2026

Summary

  • TestSetTraceId_SetsOTELAttribute: Verifies attribute is set when SetTraceId resolves a trace ID
  • TestSetTraceId_EarlyReturn_SetsOTELAttribute: Verifies attribute is set even on early return (pre-existing trace ID)
  • TestSetTraceId_NoSpan_NoPanic: Verifies no panic without OTEL span

Uses OTEL SDK test tracer (tracetest.InMemoryExporter) for span capture.

Closes #23

Test plan

  • go test -race ./... passes

Summary by CodeRabbit

  • Chores

    • Updated OpenTelemetry dependencies to v1.43.0 and added additional logging/telemetry components.
  • Tests

    • Added in-memory OpenTelemetry test support and expanded tests for trace ID handling across different input sources and contexts.

Copilot AI review requested due to automatic review settings April 3, 2026 08:37
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fbaa71eb-b89c-49ec-a257-f13bc4a83bcb

📥 Commits

Reviewing files that changed from the base of the PR and between e4074d4 and a66b581.

📒 Files selected for processing (1)
  • notifier/notifier_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • notifier/notifier_test.go

📝 Walkthrough

Walkthrough

Updated OpenTelemetry module versions and added explicit SDK and indirect logging/auto-instrumentation deps; added an in-memory OTEL test tracer helper and expanded tests to verify coldbrew.trace_id is set by SetTraceId() across multiple scenarios.

Changes

Cohort / File(s) Summary
Dependency Updates
go.mod
Bumped go.opentelemetry.io/otel & go.opentelemetry.io/otel/trace to v1.43.0; added direct go.opentelemetry.io/otel/sdk v1.43.0; added indirect deps github.com/go-logr/logr, github.com/go-logr/stdr, go.opentelemetry.io/auto/sdk v1.2.1, and go.opentelemetry.io/otel/metric v1.43.0.
Test infra & coverage
notifier/notifier_test.go
Added setupTestTracer() using sdk/trace/tracetest to install an in-memory TracerProvider for tests; added multiple test cases asserting coldbrew.trace_id span attribute behavior (early-return path, metadata-priority, no-preexisting-ID, and context-without-span).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • PR #22 — Introduced the coldbrew.trace_id span attribute assignment in SetTraceId(); these tests validate that behavior.
  • PR #18 — Replaced OpenTracing extraction with OTEL SpanFromContext; closely related to OTEL handling in notifier and to these tests.

Poem

🐰 I bumped the modules, soft and light,
I spun a tracer for test-time flight,
I set the trace_id on spans so bright,
No panic if spans take the night,
Hopping traces, snug and right. 🥕✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding tests to verify the coldbrew.trace_id OTEL span attribute in SetTraceId.
Linked Issues check ✅ Passed All coding requirements from issue #23 are met: tests verify coldbrew.trace_id attribute is set, metadata-priority is tested, early-return path is covered, and no-span edge case is handled.
Out of Scope Changes check ✅ Passed The go.mod dependency updates support the test implementation but may introduce unrelated changes; however, they are necessary for the OTEL SDK tracing tests.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/otel-trace-id-attribute

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

Adds unit tests to ensure SetTraceId() links the resolved ColdBrew trace ID to the active OpenTelemetry span via the coldbrew.trace_id attribute, including early-return and no-span cases.

Changes:

  • Add OTEL test tracer setup and span-attribute assertions for SetTraceId() behavior.
  • Add a no-span regression test to ensure SetTraceId() does not panic without an active span.
  • Update Go module dependencies to include the OTEL SDK test utilities used by the new tests.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.

File Description
notifier/notifier_test.go Adds OTEL-backed unit tests covering span attribute behavior and no-span safety.
go.mod Bumps OTEL to v1.43.0 and adds OTEL SDK dependency for tests.
go.sum Updates sums for the OTEL version bump and new transitive deps.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread notifier/notifier_test.go
Comment thread notifier/notifier_test.go Outdated
Comment thread notifier/notifier_test.go
Comment thread notifier/notifier_test.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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
go.mod (1)

12-14: Move go.opentelemetry.io/otel/sdk to indirect dependencies.

The SDK package is only imported in notifier/notifier_test.go (test-only code). In Go modules, test-only dependencies should be marked as indirect. Run go mod tidy to automatically handle this.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@go.mod` around lines 12 - 14, The go.mod currently lists
go.opentelemetry.io/otel/sdk as a direct dependency but it is only used in tests
(notifier/notifier_test.go); run `go mod tidy` to move
go.opentelemetry.io/otel/sdk to an indirect dependency (or manually add the //
indirect marker to that require line) so test-only packages are not treated as
direct module requirements, ensuring the module list reflects actual non-test
imports.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@notifier/notifier_test.go`:
- Around line 118-141: TestSetTraceId_EarlyReturn_SetsOTELAttribute has a
duplicate span.End() invocation: the span is ended twice via defer span.End()
and a later explicit span.End(); remove the redundant call by deleting the
explicit span.End() (or the deferred one) so the span is ended exactly once.
Locate the TestSetTraceId_EarlyReturn_SetsOTELAttribute test and remove the
extra span.End() to ensure the tracer span is closed only once.
- Around line 95-116: In TestSetTraceId_SetsOTELAttribute remove the redundant
deferred end of the OTEL span: delete the `defer span.End()` line and keep the
explicit `span.End()` call (in the TestSetTraceId_SetsOTELAttribute test) so the
span is ended just once before calling `exporter.GetSpans()`; this eliminates
the double `span.End()` while retaining deterministic span termination for the
test.

---

Nitpick comments:
In `@go.mod`:
- Around line 12-14: The go.mod currently lists go.opentelemetry.io/otel/sdk as
a direct dependency but it is only used in tests (notifier/notifier_test.go);
run `go mod tidy` to move go.opentelemetry.io/otel/sdk to an indirect dependency
(or manually add the // indirect marker to that require line) so test-only
packages are not treated as direct module requirements, ensuring the module list
reflects actual non-test imports.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ca86c0ae-1b32-477b-b6b5-7d2d7b2de6af

📥 Commits

Reviewing files that changed from the base of the PR and between f456431 and e4074d4.

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

Comment thread notifier/notifier_test.go
Comment thread notifier/notifier_test.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_test.go Outdated
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 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread notifier/notifier_test.go
Comment thread notifier/notifier_test.go
@ankurs ankurs merged commit d378bec into main Apr 3, 2026
11 checks passed
@ankurs ankurs deleted the test/otel-trace-id-attribute branch April 3, 2026 10:41
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.

Add test: verify coldbrew.trace_id OTEL span attribute in SetTraceId

2 participants