Skip to content

fix: correctly disable the sdk sampling when no endpoint is defined#1865

Merged
shrugs merged 3 commits intomainfrom
fix/noop-spans
Apr 2, 2026
Merged

fix: correctly disable the sdk sampling when no endpoint is defined#1865
shrugs merged 3 commits intomainfrom
fix/noop-spans

Conversation

@shrugs
Copy link
Copy Markdown
Collaborator

@shrugs shrugs commented Apr 2, 2026

  • disables the allocation of otel spans when the OTEL_EXPORTER_OTLP_ENDPOINT doesn't exist

Copilot AI review requested due to automatic review settings April 2, 2026 17:38
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 2, 2026

⚠️ No Changeset found

Latest commit: 554da73

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@shrugs shrugs marked this pull request as ready for review April 2, 2026 17:38
@shrugs shrugs requested a review from a team as a code owner April 2, 2026 17:38
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated (UTC)
admin.ensnode.io Skipped Skipped Apr 2, 2026 6:01pm
ensnode.io Skipped Skipped Apr 2, 2026 6:01pm
ensrainbow.io Skipped Skipped Apr 2, 2026 6:01pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

Warning

Rate limit exceeded

@shrugs has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 34 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 7 minutes and 34 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2e56cf39-4d3f-4003-a8c5-a5e675fbe892

📥 Commits

Reviewing files that changed from the base of the PR and between 6e2c1c0 and 554da73.

📒 Files selected for processing (1)
  • apps/ensapi/src/lib/instrumentation/index.ts
📝 Walkthrough

Walkthrough

OpenTelemetry instrumentation configuration was refactored to replace conditional span processor assembly with fixed BatchSpanProcessor configuration, introduce sampling control via AlwaysOnSampler/AlwaysOffSampler based on environment variables, and simplify debug logging gating. Server startup warm-up comments were clarified without functional changes.

Changes

Cohort / File(s) Summary
Server Startup Documentation
apps/ensapi/src/index.ts
Simplified warm-up behavior comments; removed detailed SWR cache proxy initialization explanation while retaining explicit indexingStatusCache.read() call.
OpenTelemetry Instrumentation
apps/ensapi/src/lib/instrumentation/index.ts
Replaced conditional span processor array logic with fixed BatchSpanProcessor(OTLPTraceExporter) configuration; introduced sampling control via AlwaysOnSampler (when endpoint exists) or AlwaysOffSampler (fallback); refactored debug logging gating to use OTEL_DEBUG environment variable via boolean variable instead of direct conditional check.

Possibly related PRs

Poem

🐰 A trace through the code, now cleaner and bright,
With samplers deciding what's on and what's off,
The warm-up still hops, processors stand tight,
Our burrow of telemetry's ready to scoff! ✨


🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is significantly incomplete. It contains only a single bullet point when the template requires multiple sections including Summary, Why, Testing, Notes for Reviewer, and a Pre-Review Checklist. Expand the description to include all required template sections: Summary (1-3 bullets), Why (with GitHub issue links if relevant), Testing (how it was tested), Notes for Reviewer (optional but recommended), and the Pre-Review Checklist with blocking items.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: disabling SDK sampling when no endpoint is defined, which aligns with the core objective of the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 fix/noop-spans

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.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 2, 2026

Greptile Summary

This PR fixes telemetry overhead when no OTLP endpoint is configured by switching from a conditionally-added BatchSpanProcessor to a constant AlwaysOffSampler/AlwaysOnSampler pair that gates span recording at the sampler level.

Key changes:

  • Introduces enabled (driven by OTEL_EXPORTER_OTLP_ENDPOINT) and debug (driven by OTEL_DEBUG) boolean flags for clarity.
  • When enabled is false, AlwaysOffSampler is used so no spans are ever recorded or exported.
  • BatchSpanProcessor + OTLPTraceExporter are now always constructed regardless of enabled, which is a minor style concern — the exporter defaults to http://localhost:4318/v1/traces and will be flushed/shut down at process exit even when disabled (see inline comment).
  • The comment in apps/ensapi/src/index.ts describing the indexing-status cache warm-up was condensed; behaviour is unchanged.

Confidence Score: 5/5

  • Safe to merge; the sampler correctly disables span recording when no endpoint is defined and no data is lost or exported.
  • All findings are P2 (unnecessary object allocation). The functional goal — disabling spans when OTEL_EXPORTER_OTLP_ENDPOINT is absent — is correctly achieved by AlwaysOffSampler. The minor style concern about still constructing the exporter does not affect correctness.
  • apps/ensapi/src/lib/instrumentation/index.ts — consider conditionally omitting the BatchSpanProcessor when disabled.

Important Files Changed

Filename Overview
apps/ensapi/src/lib/instrumentation/index.ts Replaces conditional BatchSpanProcessor with AlwaysOffSampler to gate tracing; exporter is now always instantiated even when disabled, creating a minor unnecessary-allocation concern on shutdown.
apps/ensapi/src/index.ts Comment-only simplification of the indexing status cache warm-up explanation; no behavioral change.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[sdk.start] --> B{OTEL_EXPORTER_OTLP_ENDPOINT set?}
    B -- yes --> C[AlwaysOnSampler\nspans recorded]
    B -- no  --> D[AlwaysOffSampler\nspans dropped]
    C --> E[BatchSpanProcessor]
    D --> E
    E --> F[OTLPTraceExporter\nalways constructed]
    F -- enabled=true --> G[HTTP POST to OTLP endpoint]
    F -- enabled=false --> H[No spans reach exporter\n queue always empty]
Loading

Reviews (1): Last reviewed commit: "Merge branch 'main' into fix/noop-spans" | Re-trigger Greptile

Copy link
Copy Markdown
Contributor

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

Updates ENSApi’s OpenTelemetry setup so tracing can be effectively disabled when OTEL_EXPORTER_OTLP_ENDPOINT is not provided, reducing span creation overhead in non-instrumented deployments.

Changes:

  • Add an enabled flag derived from OTEL_EXPORTER_OTLP_ENDPOINT and use it to switch between AlwaysOnSampler / AlwaysOffSampler.
  • Refactor OTel debug logging toggle into a debug boolean.
  • Simplify the startup cache-warming comment in the main server entrypoint.

Reviewed changes

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

File Description
apps/ensapi/src/lib/instrumentation/index.ts Introduces endpoint-driven enable/disable behavior via sampler configuration and refactors tracing setup.
apps/ensapi/src/index.ts Comment-only change clarifying cache warm-up at startup.

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

Copy link
Copy Markdown
Contributor

@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 `@apps/ensapi/src/lib/instrumentation/index.ts`:
- Around line 27-33: The span processor and exporter (BatchSpanProcessor,
OTLPTraceExporter) are still being instantiated even when telemetry is disabled;
update the instrumentation setup so that when enabled is false you do not
construct BatchSpanProcessor/OTLPTraceExporter — e.g., build spanProcessors as
enabled ? [new BatchSpanProcessor(new OTLPTraceExporter(), {...})] : [] (or
undefined) while keeping sampler: enabled ? new AlwaysOnSampler() : new
AlwaysOffSampler(); this avoids allocating exporter/processor when
AlwaysOffSampler will drop all spans.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8f9cec9b-e57f-4173-bf17-f28b884858ed

📥 Commits

Reviewing files that changed from the base of the PR and between 61d76b5 and 6e2c1c0.

📒 Files selected for processing (2)
  • apps/ensapi/src/index.ts
  • apps/ensapi/src/lib/instrumentation/index.ts

@vercel vercel bot temporarily deployed to Preview – ensnode.io April 2, 2026 18:01 Inactive
@vercel vercel bot temporarily deployed to Preview – admin.ensnode.io April 2, 2026 18:01 Inactive
@vercel vercel bot temporarily deployed to Preview – ensrainbow.io April 2, 2026 18:01 Inactive
@shrugs shrugs merged commit 35ac122 into main Apr 2, 2026
18 checks passed
@shrugs shrugs deleted the fix/noop-spans branch April 2, 2026 18:05
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