-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(node): Document SEA setup #17752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
746ddd1
81b104f
2da352b
e312160
0bb3b0e
a2221e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,12 @@ This installation method has the fundamental restriction that only native Node.j | |
|
|
||
| As a result, the Sentry SDK will not capture data from database calls, queues, ORMs, third-party libraries, or other framework-specific data. | ||
|
|
||
| We recommend using this only if the `--import` flag is not an option for you. | ||
| We recommend using these setups only if the `--import` flag is not an option for you. | ||
|
|
||
| This restriction applies when your application statically imports | ||
| `instrument.mjs` from the same ESM module graph. If you use a Node.js Single | ||
| Executable Application (SEA), use the <PlatformLink to="/install/esm-without-import/#nodejs-single-executable-applications">SEA | ||
| bootstrap setup</PlatformLink> instead. | ||
|
|
||
| </Alert> | ||
|
|
||
|
|
@@ -55,3 +60,49 @@ import http from "http"; | |
|
|
||
| // Your application code goes here | ||
| ``` | ||
|
|
||
| ## Node.js Single Executable Applications | ||
|
|
||
| Node.js Single Executable Applications (SEA) may not load your Sentry instrumentation early enough, so you need to package a small bootstrap file as the SEA main instead of packaging your app entrypoint directly. | ||
|
|
||
| The bootstrap imports Sentry first, then imports your real app entrypoint: | ||
|
|
||
| ```javascript {filename: sea-main.cjs} | ||
| (async () => { | ||
| await import("./instrument.mjs"); | ||
| await import("./app.mjs"); | ||
| })(); | ||
| ``` | ||
|
sentry[bot] marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The Suggested FixAdd a Prompt for AI Agent |
||
|
|
||
| Keep your Sentry setup in `instrument.mjs`: | ||
|
|
||
| ```javascript {tabTitle:ESM} {filename: instrument.mjs} | ||
| import * as Sentry from "@sentry/node"; | ||
|
|
||
| Sentry.init({ | ||
| dsn: "___PUBLIC_DSN___", | ||
| tracesSampleRate: 1.0, | ||
| }); | ||
| ``` | ||
|
|
||
| Then configure SEA to use the bootstrap as its main script and disable code | ||
| cache: | ||
|
|
||
| ```json {filename: sea-config.json} | ||
| { | ||
| "main": "sea-main.cjs", | ||
| "output": "sea-prep.blob", | ||
| "disableExperimentalSEAWarning": true, | ||
| "useSnapshot": false, | ||
| "useCodeCache": false | ||
| } | ||
| ``` | ||
|
|
||
| This setup lets the Sentry SDK register ESM instrumentation hooks before your | ||
| application imports instrumented modules, such as Express or database clients. | ||
| Your instrumentation file and app entrypoint can stay ESM. The verified | ||
| bootstrap pattern shown here uses CommonJS only for the small SEA main. | ||
|
|
||
| Node.js SEA support is still evolving, including how embedded ESM entrypoints | ||
| are configured. The important requirement is startup order: load Sentry before | ||
| loading the application modules you want Sentry to instrument. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove your changes from this alert because it now lives in the "Static import" section