GeezerVison is showing github.com — Support different JS runtimes · Issue #5611 · getsentry/sentry-javascript
Support different JS runtimes #5611DescriptionProblem Statement
The Sentry SDK should work with WinterCG-compatible runtimes other than NodeJS. We should build new SDKs for these platforms, or figure out how to adapt our Node SDK to fit them.
The spec: https://github.com/wintercg/proposal-common-minimum-api
There are also other JS runtimes we can take a look at:
Solution Brainstorm
If you are interested in this, please comment on the individual issues linked above! Reacted by Onur Temizkan, Aaron Hammer, Luca Forstner, Joon Park, Niklas, Yves Riedener, Varun Arora, Aaron Adams, Bae Junehyeon, Sung Jeon and 9 more Activitytimfish commented on Sep 9, 2022 timfish commented on Sep 16, 2022 The first step in supporting other runtimes is getting core, hub, types and utils compiling without dom/node types:
- - Move
@sentry/hub code to @sentry/core and keep @sentry/hub as a stub re-exporting types from core so it's not a breaking change
- -
getGlobalObject should be replaced with something more universal like this from core-js. globalThis is the global in WinterCG and browsers/node have supported it for a while too
- - Remove
DOM and node TypeScript lib types from packages that shouldn't be using them
At this point, core, hub and types are compiling without DOM/node lib types.
However, utils still requires DOM and node lib types to build successfully.
To rectify this, all runtime specific code should be moved to the runtime packages:
- - Move all browser specific code from
@sentry/utils to @sentry/browser/utils
- - Move
supportsErrorEvent, supportsDOMError, supportsDOMException, supportsFetch, supportsNativeFetch, supportsReferrerPolicy and supportsHistory to @sentry/browser
- - Move some functions (like
getLocationHref and getDomElement) from browser.ts to @sentry/browser
- - Move everything in
instrument.ts to @sentry/browser
- ❌ This is an issue due to
addInstrumentationHandler usage in tracing
- - Move all node specific code from
@sentry/utils to @sentry/node
- - Move everything in
node.ts to @sentry/node
- ❌ Moving
dynamicRequire is an issue since it's used in tracing
The above can done without technically making breaking changes since we make no guarantees about @sentry/utils, but it will impact downstream SDKs that make use of some of the moved functions.
The major downside to moving these utilities to the browser/node packages and exporting them at the root is that they would become public API methods (for downstream SDKs to use) and with that comes stability guarantees.
It would be less of a maintenance headache to either:
- Move them to new packages (like
@sentry/browser-utils) or package export (@sentry/browser/utils)
- Wrap them in an
internal object export that we make no stability promises about
@sentry/tracing
There are a few issues above where @sentry/tracing relies on code from @sentry/utils which will get moved to browser/node. This will result in tracing depending on both browser/node. This can further be fixed by splitting the tracing code #5815. lforst commented on Sep 26, 2022
How about having these as named exports? @sentry/tracing, @sentry/tracing/browser and @sentry/tracing/node?
Shouldn't it be @sentry/browser/tracing instead of @sentry/tracing/browser? So we can depend on @sentry/browser from within @sentry/browser/tracing. Maning the tracing submodule in @sentry/browser is just an extension of @sentry/browser. (I worded that kinda confusing but I think it gets the point across).
Also, I'd just have all tracing functionality in @sentry/node by default, so there wouldn't be any need for @sentry/node/tracing. Reacted by Tim Fish and Varun Arora timfish commented on Sep 26, 2022 Yep, I need to update the above ramblings.
There's a more recent issue for the tracing changes.
Also, I'd just have all tracing functionality in @sentry/node by default, so there wouldn't be any need for @sentry/node/tracing.
Would we want to add all the hub extensions by default too?
We wouldn't want to run _autoloadDatabaseIntegrations in the Electron SDK because it hits app startup time significantly! lforst commented on Sep 26, 2022 changed the title [-]Support different JS runtimes[/-] [+]WinterCG - Support different JS runtimes[/+] on Oct 5, 2022AbhiPrasad commented on Oct 7, 2022 ContributorAuthor More actions We had a discussion internally about the global object changes - @timfish could we look into if we can just use globalThis? timfish commented on Oct 7, 2022
could we look into if we can just use globalThis?
Eventually, but we'll need to wait for Node.js v12 to be our MSV.

And the Sentry supported browsers suggests we need to support Android 4.4 and IE10/11 so these would need to be polyfilled.

That means we can probably remove the window and self lines from this:
|
const GLOBAL = |
|
(typeof globalThis == 'object' && isGlobalObj(globalThis)) || |
|
// eslint-disable-next-line no-restricted-globals |
|
(typeof window == 'object' && isGlobalObj(window)) || |
|
(typeof self == 'object' && isGlobalObj(self)) || |
|
(typeof global == 'object' && isGlobalObj(global)) || |
|
(function (this: any) { |
|
return this; |
|
})() || |
|
{}; |
lobsterkatie commented on Oct 7, 2022 LOL

Looks like we haven't updated this page in quite a long time. (EDIT: Heh. Turns out July-me already discovered that: getsentry/sentry-docs#5351)
I can say for sure we don't need to worry about Android 4.4. I did a quick google, and the first version which can handle, for example, object spread is Android 8. For IE11, we've already told people that they have to use one of our ES5 bundles, to which we could add a polyfill if necessary. But the Node 10 business is definitely a bigger blocker. I like your idea of at least removing the browser-specific parts. AbhiPrasad commented on Oct 13, 2022 ContributorAuthor More actions We merged in #5831, could we rebase the rest of the PRs @timfish? KrisBraun commented on May 7, 2023 🤞 for Cloudflare Pages support, which should be nearly identical to Cloudflare Workers, just with different handlers. lforst commented on May 8, 2023 Reacted by Kris Braun, Cole Sanderson, Nico Schett and Ollie W Reacted by Wendell Misiedjan and Ollie W Reacted by Kevin Kipp, Varun Arora, Cole Sanderson, Wendell Misiedjan and Ollie W huw commented on Jul 31, 2023 I’ve updated my Cloudflare Workers Gist for Toucan v3.2.0 and Remix v2. It’s a lot more complicated & hacky now thanks to Remix v2, but still very possible. Please reply there if you have any questions :) AbhiPrasad commented on Aug 2, 2024 ContributorAuthor More actions With @sentry/cloudflare being available in 8.22.0 and us having SDKs for @sentry/vercel-edge, @sentry/bun, @sentry/deno + exposing a bunch of APIs via @sentry/core, I think we can close this issue - we support every major non-node runtime, and we have all the building blocks via generic JS APIs in the SDKs for you to support any custom runtime you wish.
The one's left on the list are:
but right now these are not high priority for us. We'll tackle them slowly over the next couple quarters (PRs are always welcome though!) Reacted by psytrx Reacted by psytrx Reacted by Mosaad, psytrx and Varun Arora
MetadataMetadataStatusShow more project fields
DevelopmentNo branches or pull requestsIssue actions
|