Skip to content

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

Open
JPeer264 wants to merge 2 commits into
developfrom
jp/add-worker
Open

chore(opentelemetry): Add worker as export | sort exports#21859
JPeer264 wants to merge 2 commits 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

TIL. Didn't know that matters

Comment thread packages/opentelemetry/package.json Outdated
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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh shoot, I wasn't aware that there is a strict order (I thought in JavaScript there is no way to guarantee the order of how it is written)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

moved import and require after all specific imports

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

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.47 kB - -
@sentry/node 122.07 kB - -
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB - -
@sentry/node/light 50.45 kB - -
@sentry/node - without tracing 73.2 kB - -
@sentry/aws-serverless 84.09 kB -0.01% -1 B 🔽
@sentry/cloudflare (withSentry) - minified 180.62 kB - -
@sentry/cloudflare (withSentry) 446.93 kB - -

View base workflow run

@JPeer264 JPeer264 requested a review from mydea July 1, 2026 09:44
},
"types": "./build/types/index.d.ts",
"default": "./build/esm/index.js"
"types": "./build/types/index.d.ts",

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 single types field in package.json provides Node.js types to browser environments, causing a type-runtime mismatch and leading to runtime errors.
Severity: HIGH

Suggested Fix

Revert the package.json exports to use per-environment types fields. Each conditional export (e.g., for browser and node) should have its own types entry pointing to the correct type definition file for that specific environment. This will likely require generating separate type definitions for the browser entrypoint.

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

Potential issue: The `package.json` `exports` map was updated to use a single, top-level
`types` field. This field points to type definitions generated exclusively from the
Node.js entrypoint (`src/index.ts`). However, the package also provides a separate
browser-specific entrypoint (`src/index.browser.ts`) with different exports and
implementations. This creates a type-runtime mismatch for users in a browser
environment. TypeScript will indicate that Node-specific exports, like the full
`SentryAsyncLocalStorageContextManager` class, are available. At runtime, the
browser-specific stub implementation is used, which lacks the methods of the Node
version, leading to runtime errors like "method is not a function".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the only types file we have

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

But in general not a bad comment

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