refactor(elysia): drop @elysiajs/opentelemetry dependency#19947
refactor(elysia): drop @elysiajs/opentelemetry dependency#19947
Conversation
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Deps
Other
Bug Fixes 🐛Cloudflare
Core
Deps
Other
Internal Changes 🔧Deps Dev
Nuxt
Other
🤖 This preview updates automatically when you update the PR. |
size-limit report 📦
|
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
Replace @elysiajs/opentelemetry with Elysia's native .trace() and
.wrap() APIs combined with Sentry's own span APIs. This eliminates
the version mismatch issues caused by the OTel plugin's transitive
OpenTelemetry dependencies.
Key changes:
- Use .wrap() to capture/create root spans (Bun creates new server
span, Node.js captures existing HTTP instrumentation span) and
bridge them to .trace() via a WeakMap<Request, Span>
- Use .trace({ as: "global" }) with startInactiveSpan to create
lifecycle phase spans (Request, Parse, Handle, etc.) and child
handler spans (named functions get their name, arrow functions
get 'anonymous')
- Move all SDK logic (request metadata, trace propagation, error
capture) inside .trace() callbacks via onPhaseEnd so no separate
lifecycle hooks are registered (which would show up as handler
spans in the trace)
- Remove clientHooks.ts (no more post-hoc span enrichment or
<unknown> span filtering needed)
- Remove OTel resolution overrides from root package.json
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The size limit bumps were needed for @elysiajs/opentelemetry's transitive OTel dependencies. Now that we dropped the plugin, the limits can go back to the develop baseline. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Import TraceHandler, TraceListener, TraceProcess from elysia instead of defining custom interfaces or casting to any - Add void to floating promises (TraceListener callbacks) - Fix package.json lint/fix scripts to use oxlint instead of eslint Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Restore onRequest, onAfterHandle, onError as real lifecycle hooks (.trace() is observational only — used for span creation, not SDK logic) - Set HTTP error status on root span in onError handler - Update elysia-bun E2E tests: origin auto.http.otel.elysia -> auto.http.elysia - Use /with-middleware/test route for anonymous span test (needs actual handlers) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fd04016 to
7b31215
Compare
There was a problem hiding this comment.
Pull request overview
This PR removes the @elysiajs/opentelemetry dependency from the @sentry/elysia package by re-implementing the required tracing behavior directly using Elysia’s .wrap()/.trace() APIs together with Sentry’s span APIs, and updates tests/e2e fixtures accordingly.
Changes:
- Drop
@elysiajs/opentelemetryfrom Elysia package + e2e test apps, and adjust lockfile/resolutions accordingly. - Rework
withElysia()to create/enrich Elysia lifecycle spans via Sentry APIs (including a WeakMap to bridge async-context gaps). - Update unit + e2e tests to assert the new
originvalue and the new anonymous-handler span naming behavior.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
packages/elysia/src/withElysia.ts |
Replaces OTel plugin usage with direct Elysia .wrap()/.trace() + Sentry span creation and propagation logic. |
packages/elysia/src/clientHooks.ts |
Removes prior client-hook approach which enriched/filtered spans post-facto. |
packages/elysia/test/withElysia.test.ts |
Updates unit tests to reflect .wrap()/.trace() registration instead of registering the OTel plugin. |
packages/elysia/package.json |
Removes @elysiajs/opentelemetry from peer/dev deps; aligns lint scripts with repo oxlint pattern. |
dev-packages/e2e-tests/test-applications/elysia-node/package.json |
Drops @elysiajs/opentelemetry from the Node e2e fixture. |
dev-packages/e2e-tests/test-applications/elysia-bun/package.json |
Drops @elysiajs/opentelemetry from the Bun e2e fixture. |
dev-packages/e2e-tests/test-applications/elysia-node/tests/transactions.test.ts |
Updates assertions for new origin and anonymous-handler span behavior. |
dev-packages/e2e-tests/test-applications/elysia-bun/tests/transactions.test.ts |
Updates assertions for new origin and anonymous-handler span behavior. |
package.json |
Removes OpenTelemetry-related Yarn resolutions entries. |
yarn.lock |
Removes @elysiajs/opentelemetry (and transitives) and reflects updated OTEL dependency graph. |
.size-limit.js |
Adjusts size limits downward to match the new bundle sizes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/elysia/src/withElysia.ts
Outdated
| function setupClientHooksOnce(): void { | ||
| if (isClientHooksSetup) { | ||
| return; | ||
| } | ||
| const client = getClient(); | ||
| if (!client) { | ||
| return; | ||
| } | ||
| isClientHooksSetup = true; | ||
| } |
There was a problem hiding this comment.
setupClientHooksOnce() no longer sets up any client hooks (it only checks getClient() and flips isClientHooksSetup), but it’s still called from withElysia() and the isClientHooksSetup flag is otherwise unused. This looks like leftover scaffolding from the removed clientHooks.ts and adds confusion/overhead—either remove this function + flag entirely, or reintroduce the intended client hook registration here.
Leftover from the removed clientHooks.ts — the function body was empty and the isClientHooksSetup flag was unused. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
JPeer264
left a comment
There was a problem hiding this comment.
LGTM. I think Elysia wasn't released yet right? So this refactor is then not even a breaking change just yet
Mimics
@elysia/opentelemetryown implementation and swaps out OTEL APIs with our own, main reason is I didn't want to lock OTEL deps to specific versions that may break in the wild.This is an exploration, but if all is green then I will consider merging this first into Elysia SDK before release.
closes #18956