Skip to content

feat: add enabled option#83

Open
lxy2500798479 wants to merge 1 commit into
elysiajs:mainfrom
lxy2500798479:fix/enabled-option
Open

feat: add enabled option#83
lxy2500798479 wants to merge 1 commit into
elysiajs:mainfrom
lxy2500798479:fix/enabled-option

Conversation

@lxy2500798479

@lxy2500798479 lxy2500798479 commented Jun 1, 2026

Copy link
Copy Markdown

Summary

  • add an enabled option to keep plugin composition stable while disabling telemetry setup
  • skip SDK/span setup entirely when enabled: false
  • document a production-friendly setup with env gating, body capture disabled, and header allow-lists

Closes #79

Behavior

new Elysia().use(
  opentelemetry({
    enabled: process.env.OTEL_ENABLED !== "false",
    serviceName: "api"
  })
)

When disabled, the plugin returns an inert Elysia plugin with the same name and does not start the NodeSDK or register trace hooks.

Tests

  • bun test --preload ./test/test-setup.ts test/core.test.ts
  • bun run build
  • npm run test:node
  • bun test --preload ./test/test-setup.ts currently reaches 62 passing tests, then fails on existing test/integration.test.ts import: Cannot find module @elysiajs/eden while package.json depends on @elysia/eden.

Summary by CodeRabbit

  • New Features

    • Added enabled option to toggle the OpenTelemetry plugin on/off for flexible deployment control
  • Documentation

    • Added production defaults guidance with configuration examples and best-practice recommendations for secure production deployments, including recommendations for body recording settings, header filtering strategies, and environment-based configuration approaches.

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 06d0ff44-e597-4c80-a000-aa6a9ed93890

📥 Commits

Reviewing files that changed from the base of the PR and between b85a5f5 and beaaffa.

📒 Files selected for processing (3)
  • README.md
  • src/index.ts
  • test/core.test.ts

Walkthrough

This PR adds an enabled?: boolean option to the OpenTelemetry plugin, allowing programmatic toggle of telemetry without conditional imports. When disabled, the plugin returns an inert instance and skips all tracing initialization. Documentation and test coverage validate the feature~♡

Changes

Pluggable telemetry enablement

Layer / File(s) Summary
Enable/disable option contract
src/index.ts
ElysiaOpenTelemetryOptions adds enabled?: boolean field; factory destructures it with true default.
Disabled plugin short-circuit
src/index.ts
opentelemetry returns an inert Elysia instance immediately when enabled: false, bypassing all SDK and middleware setup.
Test coverage and production guidance
test/core.test.ts, README.md
New test verifies disabled tracing creates no spans; README adds "Production defaults" section with configuration examples and usage bullets for production telemetry settings.

Sequence Diagram

sequenceDiagram
  participant App as Elysia App
  participant Plugin as opentelemetry plugin
  participant SDK as OpenTelemetry SDK
  
  alt enabled: false
    App->>Plugin: initialize with enabled: false
    Plugin->>App: return inert Elysia instance
    Note over App,Plugin: No tracing setup occurs
  else enabled: true (default)
    App->>Plugin: initialize with enabled: true
    Plugin->>SDK: initialize tracer and spans
    SDK-->>Plugin: tracing ready
    Plugin->>App: wired middleware active
  end
  
  App->>App: handle request
  Note over App: spans captured only if enabled: true
Loading

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • elysiajs/opentelemetry#51: Adds request-level tracing gating via checkIfShouldTrace option, complementing this PR's plugin-level toggle mechanism.

Poem

A switch so neat, you are kind of clever~ ♡(´▽`)
enabled: false stops the span's fever,
No SDK dance when you don't need it ever,
Hehe, guess even trace-happy code needs a breaker~ ˋ_ˊ

🚥 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 'feat: add enabled option' clearly and concisely describes the main change—adding an enabled configuration option to the OpenTelemetry plugin.
Linked Issues check ✅ Passed All coding requirements from issue #79 are met: the enabled option is implemented, it toggles telemetry via plugin configuration, and the plugin returns an inert instance when disabled.
Out of Scope Changes check ✅ Passed The README additions about production defaults are documentation enhancements related to the enabled feature and don't constitute out-of-scope changes.
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

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.

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 "Enabled" argument to the plugin

1 participant