Skip to content

chore(opentelemetry): Add worker as export | sort exports#21859

Open
JPeer264 wants to merge 1 commit into
developfrom
jp/add-worker
Open

chore(opentelemetry): Add worker as export | sort exports#21859
JPeer264 wants to merge 1 commit into
developfrom
jp/add-worker

Conversation

@JPeer264

Copy link
Copy Markdown
Member

In the future we need to import from @sentry/opentelemetry. As there is now a browser export we go into that path, based on the wrangler's build preferences. As of now, the browser entrypoint is only here to print a warning - which would also happen on Cloudflare.

In order to use the correct entrypoint in Cloudflare the worker entry has been added.


On top I also sorted the exports to match the other package.jsons. Instead of import -> node -> default it is now node -> import (so it is one depth less)

@JPeer264 JPeer264 requested a review from Lms24 June 30, 2026 09:48
@JPeer264 JPeer264 self-assigned this Jun 30, 2026
@JPeer264 JPeer264 requested a review from a team as a code owner June 30, 2026 09:48
@JPeer264 JPeer264 requested review from andreiborza and mydea and removed request for a team June 30, 2026 09:49
Comment on lines +24 to +34
"node": {
"import": "./build/esm/index.js",
"require": "./build/cjs/index.js"
},
"require": {
"node": {
"types": "./build/types/index.d.ts",
"default": "./build/cjs/index.js"
},
"browser": {
"types": "./build/types/index.d.ts",
"default": "./build/cjs/index.browser.js"
},
"types": "./build/types/index.d.ts",
"default": "./build/cjs/index.js"
"worker": {
"import": "./build/esm/index.js",
"require": "./build/cjs/index.js"
},
"browser": {
"import": "./build/esm/index.browser.js",
"require": "./build/cjs/index.browser.js"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The exports order in package.json is incorrect. Generic import/require conditions appear before the browser condition, causing bundlers to select the Node.js build for browser environments.
Severity: HIGH

Suggested Fix

Reorder the exports conditions in package.json to place specific environment conditions (browser, worker, node) before the generic import and require fallbacks. This ensures that environment-specific bundlers select the correct entry point. For example, the browser condition should be evaluated before the top-level import condition.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/opentelemetry/package.json#L21-L34

Potential issue: The `exports` map in `package.json` has an incorrect condition order.
Generic conditions `import` and `require` are listed before specific environment
conditions like `browser`. According to Node.js resolution rules, the first matching
condition is used. This means browser bundlers will match the generic `import` condition
and receive the Node.js-specific build (`./build/esm/index.js`). This build imports
`node:async_hooks`, which is not available in browsers, leading to runtime errors. The
intended browser-specific build, which provides a safe stub for Node.js APIs, will be
ignored.

Did we get this right? 👍 / 👎 to inform future reviews.

Comment on lines +22 to +23
"import": "./build/esm/index.js",
"require": "./build/cjs/index.js",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this not lead to these being picked over the node/browser/worker ones? 🤔 should these not be below those to be picked as fallbacks...?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically what the clanker found below :D

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.62 kB - -
@sentry/browser - with treeshaking flags 26.05 kB - -
@sentry/browser (incl. Tracing) 46.07 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.82 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.84 kB - -
@sentry/browser (incl. Tracing, Replay) 85.31 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.91 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.99 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.67 kB - -
@sentry/browser (incl. Feedback) 44.8 kB - -
@sentry/browser (incl. sendFeedback) 32.42 kB - -
@sentry/browser (incl. FeedbackAsync) 37.55 kB - -
@sentry/browser (incl. Metrics) 28.68 kB - -
@sentry/browser (incl. Logs) 28.93 kB - -
@sentry/browser (incl. Metrics & Logs) 29.61 kB - -
@sentry/react 29.41 kB - -
@sentry/react (incl. Tracing) 48.38 kB - -
@sentry/vue 32.85 kB - -
@sentry/vue (incl. Tracing) 47.93 kB - -
@sentry/svelte 27.64 kB - -
CDN Bundle 30.02 kB - -
CDN Bundle (incl. Tracing) 48.02 kB - -
CDN Bundle (incl. Logs, Metrics) 31.58 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.35 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.79 kB - -
CDN Bundle (incl. Tracing, Replay) 85.51 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.79 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.32 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.56 kB - -
CDN Bundle - uncompressed 89.42 kB - -
CDN Bundle (incl. Tracing) - uncompressed 145.35 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.12 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 149.32 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.66 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.36 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268.32 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 278.06 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 282.01 kB - -
@sentry/nextjs (client) 50.76 kB - -
@sentry/sveltekit (client) 46.46 kB - -
@sentry/core/server 77.75 kB - -
@sentry/core/browser 64.06 kB - -
@sentry/node-core 61.62 kB +0.25% +151 B 🔺
@sentry/node 123.72 kB +0.74% +900 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB - -
@sentry/node/light 50.45 kB - -
@sentry/node - without tracing 74.08 kB +1.2% +875 B 🔺
@sentry/aws-serverless 84.97 kB +1.05% +876 B 🔺
@sentry/cloudflare (withSentry) - minified 180.62 kB - -
@sentry/cloudflare (withSentry) 446.93 kB - -

View base workflow run

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