Skip to content

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

Merged
JPeer264 merged 3 commits into
developfrom
jp/add-worker
Jul 7, 2026
Merged

chore(opentelemetry): Add worker as export | sort exports#21859
JPeer264 merged 3 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 Lms24June 30, 2026 09:48
@JPeer264JPeer264 self-assigned this Jun 30, 2026
@JPeer264
JPeer264 requested a review from a team as a code ownerJune 30, 2026 09:48
@JPeer264
JPeer264 requested review from andreiborza and mydea and removed request for a teamJune 30, 2026 09:49
Comment threadpackages/opentelemetry/package.json
Comment threadpackages/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
MemberAuthor

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
MemberAuthor

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-actionsBot 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.

PathSize% ChangeChange
@sentry/browser27.59 kB--
@sentry/browser - with treeshaking flags26.03 kB--
@sentry/browser (incl. Tracing)46.27 kB+0.05%+23 B 🔺
@sentry/browser (incl. Tracing + Span Streaming)48.03 kB+0.05%+20 B 🔺
@sentry/browser (incl. Tracing, Profiling)51.03 kB+0.04%+17 B 🔺
@sentry/browser (incl. Tracing, Replay)85.56 kB+0.04%+27 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags75.17 kB+0.04%+30 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas)90.26 kB+0.03%+24 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback)102.91 kB+0.02%+18 B 🔺
@sentry/browser (incl. Feedback)44.76 kB--
@sentry/browser (incl. sendFeedback)32.38 kB--
@sentry/browser (incl. FeedbackAsync)37.51 kB--
@sentry/browser (incl. Metrics)28.67 kB--
@sentry/browser (incl. Logs)28.91 kB--
@sentry/browser (incl. Metrics & Logs)29.59 kB--
@sentry/react29.38 kB--
@sentry/react (incl. Tracing)48.53 kB+0.04%+15 B 🔺
@sentry/vue33.03 kB--
@sentry/vue (incl. Tracing)48.16 kB+0.11%+50 B 🔺
@sentry/svelte27.61 kB--
CDN Bundle30 kB--
CDN Bundle (incl. Tracing)48.26 kB+0.04%+19 B 🔺
CDN Bundle (incl. Logs, Metrics)31.57 kB--
CDN Bundle (incl. Tracing, Logs, Metrics)49.57 kB+0.07%+31 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics)70.81 kB--
CDN Bundle (incl. Tracing, Replay)85.73 kB-0.01%-6 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics)87.04 kB+0.01%+4 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback)91.55 kB+0.03%+22 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics)92.83 kB+0.02%+12 B 🔺
CDN Bundle - uncompressed89.35 kB--
CDN Bundle (incl. Tracing) - uncompressed145.99 kB+0.03%+31 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed94.05 kB--
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed149.96 kB+0.03%+31 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed218.75 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed265.16 kB+0.02%+31 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed269.12 kB+0.02%+31 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed278.86 kB+0.02%+31 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed282.81 kB+0.02%+31 B 🔺
@sentry/nextjs (client)50.94 kB-0.01%-2 B 🔽
@sentry/sveltekit (client)46.68 kB+0.06%+26 B 🔺
@sentry/core/server78.38 kB--
@sentry/core/browser64.72 kB--
@sentry/node-core63.21 kB--
@sentry/node123.7 kB+0.01%+1 B 🔺
@sentry/node (incl. diagnostics channel injection)129.62 kB+0.01%+1 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection)69.95 kB--
@sentry/node/light50.72 kB--
@sentry/node - without tracing74.82 kB--
@sentry/aws-serverless85.6 kB+0.01%+1 B 🔺
@sentry/cloudflare (withSentry) - minified181.68 kB--
@sentry/cloudflare (withSentry)449.39 kB--

View base workflow run

@JPeer264
JPeer264 requested a review from mydeaJuly 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.jsonexports 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
MemberAuthor

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
MemberAuthor

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

@github-actions

Copy link
Copy Markdown
Contributor

👋 @mydea, @Lms24, @andreiborza — Please review this PR when you get a chance!

Comment threadpackages/opentelemetry/package.json Outdated
Comment on lines +34 to +35
"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.

l: I think we can add a default condition around these, wdyt?

I recently learned this is considered best practise (#21472)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Very interesting. First I thought this is the same, but there is indeed some difference: https://nodejs.org/api/packages.html#conditional-exports

Maybe worth to add it everywhere just in case 🤔

@Lms24

Lms24 commented Jul 6, 2026

Copy link
Copy Markdown
Member

(Sorry for the late review!)

Comment threadpackages/opentelemetry/package.json
@JPeer264
JPeer264 merged commit 9ca357f into developJul 7, 2026
300 checks passed
@JPeer264
JPeer264 deleted the jp/add-worker branch July 7, 2026 20:24
Sign up for freeto 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.

3 participants

@JPeer264@Lms24@mydea