Skip to content

refactor: remove ensureSampled, use natural OTel root spans#7

Merged
ankurs merged 3 commits into
mainfrom
remove-ensure-sampled
Apr 27, 2026
Merged

refactor: remove ensureSampled, use natural OTel root spans#7
ankurs merged 3 commits into
mainfrom
remove-ensure-sampled

Conversation

@ankurs
Copy link
Copy Markdown
Member

@ankurs ankurs commented Apr 27, 2026

Summary

  • Remove ensureSampled hack that injected a fake remote sampled span context to force ParentBased samplers to always sample worker spans
  • The Tracing() middleware now lets NewInternalSpan create a natural OTel root span per tick, with sampling governed by the global TracerProvider's sampler
  • Remove associated tests (TestEnsureSampled*) and unused imports

Test plan

  • make test passes (all tests green with -race)
  • make lint clean (golangci-lint + govulncheck)

Summary by CodeRabbit

  • Refactor
    • Simplified tracing middleware by removing forced trace sampling logic for worker spans.
    • Removed obsolete trace sampling unit tests.

…r ticks

The Tracing middleware previously injected a fake remote sampled span
context to force ParentBased samplers to always sample worker spans.
Remove this hack and let NewInternalSpan create a natural root span
per tick, with sampling governed by the global TracerProvider's sampler.
Copilot AI review requested due to automatic review settings April 27, 2026 04:45
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

Warning

Rate limit exceeded

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

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ 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: 572bd09a-b3d3-4891-9f2f-41aafa400c65

📥 Commits

Reviewing files that changed from the base of the PR and between 715239e and 91227d5.

📒 Files selected for processing (2)
  • middleware/README.md
  • middleware/tracing.go
📝 Walkthrough

Walkthrough

The tracing middleware is simplified by removing the ensureSampled helper function and associated sampling logic. Worker span sampling decisions are now delegated entirely to the global OpenTelemetry TracerProvider sampler, and the middleware no longer modifies the context before span creation.

Changes

Cohort / File(s) Summary
Tracing Middleware Simplification
middleware/tracing.go, middleware/tracing_test.go
Removes ensureSampled helper and crypto/rand-based TraceID/SpanID generation/injection logic. Middleware now relies on OpenTelemetry TracerProvider sampler for sampling decisions. Corresponding unit tests for ensureSampled behavior are removed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 The sampler now decides what's traced,
No forcing hands, just nature's taste,
Less code to wrangle, clean and light,
The telemetry flows just right! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the main change: removing the ensureSampled function and switching to natural OpenTelemetry root spans. This accurately summarizes the primary refactoring work across both modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 remove-ensure-sampled

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

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@middleware/tracing.go`:
- Around line 12-14: Docstring for the exported Tracing() function was changed
to mention "natural OTel root spans / global sampler"; run the documentation
task to regenerate the public README so the published docs match the updated
docstring by running the project's doc generation (make doc which invokes
gomarkdoc), verify README.md updates reflect the new wording for Tracing(), and
commit the regenerated README.md alongside your change.
🪄 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: 1b1a85f8-5062-40b1-88cd-7a0a3834ee68

📥 Commits

Reviewing files that changed from the base of the PR and between 3626332 and 715239e.

📒 Files selected for processing (2)
  • middleware/tracing.go
  • middleware/tracing_test.go
💤 Files with no reviewable changes (1)
  • middleware/tracing_test.go

Comment thread middleware/tracing.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

This PR removes the ensureSampled span-context injection so worker-cycle spans are created as “natural” spans (without a synthetic sampled remote parent), allowing sampling decisions to be governed by the configured global OpenTelemetry TracerProvider sampler.

Changes:

  • Removed ensureSampled logic (and its crypto/rand usage) from the Tracing() middleware.
  • Updated Tracing() documentation to reflect sampler-governed behavior.
  • Removed TestEnsureSampled* tests and related unused imports.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
middleware/tracing.go Stops forcing sampling via injected remote span context; relies on global OTel sampler and updates comments accordingly.
middleware/tracing_test.go Removes tests and imports that only validated the deleted ensureSampled helper.

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

Comment thread middleware/tracing.go Outdated
@ankurs ankurs merged commit 790585f into main Apr 27, 2026
4 checks passed
@ankurs ankurs deleted the remove-ensure-sampled branch April 27, 2026 05:11
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