-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(js): Add docs to use SDK with ESM without
--import
(#10053)
- Loading branch information
Showing
4 changed files
with
87 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
docs/platforms/javascript/common/install/esm-without-import.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
title: ESM without CLI Flag | ||
sidebar_order: 11 | ||
description: "Learn about running Sentry in an ESM application, without the --import flag." | ||
supported: | ||
- javascript.node | ||
- javascript.connect | ||
- javascript.express | ||
- javascript.fastify | ||
- javascript.koa | ||
--- | ||
|
||
<Alert> | ||
Are you unsure if you should use this installation method? Review our | ||
[installation methods](../). | ||
</Alert> | ||
|
||
When running your application in ESM mode, you will most likely want to <PlatformLink to="/install/esm">follow the ESM instructions</PlatformLink>. However, if you want to avoid using the `--import` command line option, for example if you have no way of configuring a CLI flag, you can also follow an alternative setup that involves importing the `instrument.mjs` file directly in your application. | ||
|
||
<Alert level='warning' title='Restrictions of this installation method'> | ||
This installation method has a fundamental restriction: It only supports limited performance instrumentation. Only basic `http` instrumentation will work, and no DB or framework-specific instrumentation will be available. | ||
|
||
Because of this, we recommend using this only if the `--import` flag is not an option for you. | ||
|
||
</Alert> | ||
|
||
You need to create a file named `instrument.mjs` that imports and initializes Sentry: | ||
|
||
<SignInNote /> | ||
|
||
```javascript {tabTitle:ESM} {filename: instrument.mjs} | ||
import * as Sentry from "@sentry/node"; | ||
|
||
// Ensure to call this before importing any other modules! | ||
Sentry.init({ | ||
dsn: "___PUBLIC_DSN___", | ||
|
||
// Add Performance Monitoring by setting tracesSampleRate | ||
// We recommend adjusting this value in production | ||
tracesSampleRate: 1.0, | ||
}); | ||
``` | ||
|
||
You need to import the `instrument.mjs` file before importing any other modules in your application. This is necessary to ensure that Sentry can automatically instrument all modules in your application: | ||
|
||
```javascript {filename: app.mjs} | ||
// Import this first! | ||
import "./instrument"; | ||
|
||
// Now import other modules | ||
import http from "http"; | ||
|
||
// Your application code goes here | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters