Skip to content

feat(bun): Add @sentry/bun/light entry point without OpenTelemetry#20622

Draft
MathurAditya724 wants to merge 3 commits intodevelopfrom
issue-19886-bun-light-entry-point
Draft

feat(bun): Add @sentry/bun/light entry point without OpenTelemetry#20622
MathurAditya724 wants to merge 3 commits intodevelopfrom
issue-19886-bun-light-entry-point

Conversation

@MathurAditya724
Copy link
Copy Markdown
Member

Adds a @sentry/bun/light entry point that eliminates the ~150ms import overhead and ~24MB of OTel packages for CLI tools and non-server Bun applications. Uses AsyncLocalStorage for context propagation instead of OpenTelemetry, and sets Bun-specific runtime metadata (name: 'bun', version: Bun.version).

What this changes

  • New packages/bun/src/light/ directory with BunLightClient, init, getDefaultIntegrations, and initWithoutDefaultIntegrations
  • BunLightClient extends LightNodeClient and overrides runtime/platform metadata to reflect Bun
  • makeFetchTransport is the default transport (uses global fetch())
  • SDK metadata tagged as sentry.javascript.bun
  • No bunServerIntegration or OTel auto-instrumentation in defaults
  • package.json updated with ./light export map and @sentry/node-core direct dependency
  • rollup.npm.config.mjs updated to include src/light/index.ts as an entry point

What's complete

  • BunLightClient with correct Bun runtime metadata
  • init / initWithoutDefaultIntegrations functions
  • Full re-export of common Sentry APIs from @sentry/core and @sentry/node-core/light
  • Tests for basic functionality, runtime metadata, and default transport
  • All 40 existing bun tests still pass

What's incomplete or uncertain

  • The BunLightClient constructor mutates getOptions() after super() to override the Node.js runtime set by LightNodeClient. This is a workaround for LightNodeClient hardcoding runtime: { name: 'node' }. A cleaner approach would be to have LightNodeClient accept runtime overrides, but that's a separate change.
  • The debug option handling omits the DEBUG_BUILD guard (the bun package has no debug-build.ts). This means debug.enable() is always called when debug: true, even in non-debug bundles.
  • No processSessionIntegration in defaults (it's not exported from @sentry/node-core/light).
  • typesVersions does not include the ./light sub-path (consistent with @sentry/node-core which also omits it).

Followups

  • Consider adding processSessionIntegration to @sentry/node-core/light exports
  • Consider adding a debug-build.ts to the bun package for proper debug bundle handling
  • E2E tests for the light entry point

Testing

Ran bun test in packages/bun/ — 40 pass, 0 fail.

Closes #19886

MathurAditya724 and others added 2 commits May 2, 2026 05:25
Adds a new `@sentry/bun/light` entry point that mirrors what
`@sentry/node-core/light` does for Node.js: it uses AsyncLocalStorage
for context propagation instead of OpenTelemetry, eliminating the ~150ms
import overhead and ~24MB of OTel packages for CLI tools and other
non-server Bun applications.

The new entry point provides:
- `BunLightClient` extending `LightNodeClient` with Bun-specific
  runtime metadata (name: 'bun', version: Bun.version)
- `makeFetchTransport` as the default transport (uses global fetch())
- SDK metadata tagged as 'sentry.javascript.bun'
- All common Sentry APIs (captureException, startSpan, setTag, etc.)
- No bunServerIntegration or OTel auto-instrumentation in defaults

Fixes #19886

Co-Authored-By: claude-sonnet-4-6 <noreply@anthropic.com>
- Convert rollup externals to a function matching dependency subpaths
  so @sentry/node-core/light stays external (fixes import-in-the-middle
  resolution error)
- Set moduleResolution to Node16 in tsconfig so TypeScript resolves
  @sentry/node-core/light subpath exports
- Use type assertion in LightNodeClient for platform/runtime overrides
  since NodeClientOptions doesn't include ServerRuntimeClientOptions fields
- Remove BunLightClient wrapper in favor of passing platform/runtime
  through options directly to LightNodeClient
@MathurAditya724
Copy link
Copy Markdown
Member Author

fix-ci: starting attempt 1

fix-ci: result — pushed 21c597a5

Root causes:

  1. Rollup build:transpile error@sentry/node-core/light was not treated as external. The base rollup config externalizes exact dependency names (e.g. @sentry/node-core) but not subpath imports (e.g. @sentry/node-core/light). Rollup's node-resolve plugin resolved the subpath to its physical files, pulling in import-in-the-middle transitively.

  2. TypeScript build:types error — The base tsconfig uses moduleResolution: "node" which cannot resolve package.json exports subpaths. @sentry/node-core/light is defined via the exports field, requiring Node16 module resolution.

  3. BunLightClient type errorsNodeClientOptions doesn't have platform or runtime (those are on ServerRuntimeClientOptions). The original LightNodeClient hardcodes them.

Fixes:

  • Converted rollup external array to a function that matches dependency subpaths (id === dep || id.startsWith(dep + '/'))
  • Added module: "Node16" and moduleResolution: "Node16" to bun's tsconfig
  • Removed BunLightClient wrapper — pass platform/runtime through options instead
  • Added type assertion in LightNodeClient constructor for platform/runtime reads
  • Added preserveModules: true and exports: 'named' to match node-core's rollup pattern

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 2, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 26.16 kB - -
@sentry/browser - with treeshaking flags 24.63 kB - -
@sentry/browser (incl. Tracing) 44.13 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 46.34 kB - -
@sentry/browser (incl. Tracing, Profiling) 49.08 kB - -
@sentry/browser (incl. Tracing, Replay) 83.48 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 72.96 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 88.15 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 100.8 kB - -
@sentry/browser (incl. Feedback) 43.4 kB - -
@sentry/browser (incl. sendFeedback) 30.96 kB - -
@sentry/browser (incl. FeedbackAsync) 36.14 kB - -
@sentry/browser (incl. Metrics) 27.44 kB - -
@sentry/browser (incl. Logs) 27.59 kB - -
@sentry/browser (incl. Metrics & Logs) 28.28 kB - -
@sentry/react 27.9 kB - -
@sentry/react (incl. Tracing) 46.36 kB - -
@sentry/vue 31.03 kB - -
@sentry/vue (incl. Tracing) 45.96 kB - -
@sentry/svelte 26.18 kB - -
CDN Bundle 28.85 kB - -
CDN Bundle (incl. Tracing) 46.91 kB - -
CDN Bundle (incl. Logs, Metrics) 30.27 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 48.03 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 69.35 kB - -
CDN Bundle (incl. Tracing, Replay) 84.07 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 85.14 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 89.86 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 90.96 kB - -
CDN Bundle - uncompressed 84.55 kB - -
CDN Bundle (incl. Tracing) - uncompressed 140.16 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 88.75 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 143.62 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 212.71 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 257.96 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 261.41 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 271.66 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 275.1 kB - -
@sentry/nextjs (client) 48.85 kB - -
@sentry/sveltekit (client) 44.58 kB - -
@sentry/node-core 59.06 kB +0.02% +9 B 🔺
@sentry/node 170.35 kB +0.01% +9 B 🔺
@sentry/node - without tracing 96.92 kB +0.01% +9 B 🔺
@sentry/aws-serverless 113.78 kB +0.03% +31 B 🔺
@sentry/cloudflare (withSentry) - minified 164.96 kB - -
@sentry/cloudflare (withSentry) 417.1 kB - -

View base workflow run

@MathurAditya724
Copy link
Copy Markdown
Member Author

fix-ci: starting attempt

CI failure: Check file formatting job failed — oxfmt flagged packages/bun/src/light/sdk.ts.
Root cause: _init function signature was formatted as multi-line; oxfmt requires it on a single line.
Fix: Running oxfmt packages/bun/src/light/sdk.ts --write.
Other failure: E2E nextjs-16-cf-workers (canary) Test (optional) — Wrangler dev crash, infra issue, unrelated to PR.

@MathurAditya724
Copy link
Copy Markdown
Member Author

fix-ci: result

Fixed Check file formatting failure by running oxfmt on packages/bun/src/light/sdk.ts — the _init function signature was reformatted from multi-line to single line.

The optional E2E nextjs-16-cf-workers (canary) failure is an infra issue (Wrangler dev crash) — not related to this PR.

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.

feat(bun): Add @sentry/bun/light entry point without OpenTelemetry

1 participant