-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: Document eventLoopBlockIntegration integration
#14302
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
132 changes: 132 additions & 0 deletions
132
docs/platforms/javascript/common/configuration/integrations/event-loop-block.mdx
This file contains hidden or 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,132 @@ | ||
| --- | ||
| title: Event Loop Block | ||
| description: "Monitor for blocked event loops in all threads of a Node.js application." | ||
| supported: | ||
| - javascript.node | ||
| - javascript.aws-lambda | ||
| - javascript.azure-functions | ||
| - javascript.connect | ||
| - javascript.express | ||
| - javascript.fastify | ||
| - javascript.gcp-functions | ||
| - javascript.hapi | ||
| - javascript.hono | ||
| - javascript.koa | ||
| - javascript.nestjs | ||
| - javascript.electron | ||
| - javascript.nextjs | ||
| - javascript.nuxt | ||
| - javascript.solidstart | ||
| - javascript.sveltekit | ||
| - javascript.remix | ||
| - javascript.react-router | ||
| - javascript.astro | ||
| - javascript.tanstackstart-react | ||
| --- | ||
|
|
||
| <Alert> | ||
|
|
||
| This integration only works in the Node.js runtime. | ||
|
|
||
| </Alert> | ||
|
|
||
| _Import name: `eventLoopBlockIntegration` from `@sentry/node-native`_ | ||
|
|
||
| The `eventLoopBlockIntegration` can be used to monitor for blocked event loops in all threads of a Node.js application. This integration provides better performance and more comprehensive monitoring compared to the deprecated [`anrIntegration`](./anr). | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| # Using yarn | ||
| yarn add @sentry/node @sentry/node-native | ||
|
|
||
| # Using npm | ||
| npm install --save @sentry/node @sentry/node-native | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| If you instrument your application via the Node.js `--import` flag, Sentry will be started and this instrumentation will be automatically applied to all worker threads. | ||
|
|
||
| `instrument.mjs` | ||
|
|
||
| ```javascript | ||
| import * as Sentry from "@sentry/node"; | ||
| import { eventLoopBlockIntegration } from "@sentry/node-native"; | ||
|
|
||
| Sentry.init({ | ||
| dsn: "__YOUR_DSN__", | ||
| // Capture stack traces when the event loop is blocked for more than 500ms | ||
| integrations: [eventLoopBlockIntegration({ threshold: 500 })], | ||
| }); | ||
| ``` | ||
|
|
||
| `app.mjs` | ||
|
|
||
| ```javascript | ||
| import { Worker } from "worker_threads"; | ||
|
|
||
| const worker = new Worker(new URL("./worker.mjs", import.meta.url)); | ||
|
|
||
| // This main thread will be monitored for blocked event loops | ||
| ``` | ||
|
|
||
| `worker.mjs` | ||
|
|
||
| ```javascript | ||
| // This worker thread will also be monitored for blocked event loops too | ||
| ``` | ||
|
|
||
| Start your application: | ||
|
|
||
| ```bash | ||
| node --import instrument.mjs app.mjs | ||
| ``` | ||
|
|
||
| If a thread is blocked for more than the configured threshold, stack traces will be captured for all threads and sent to Sentry. | ||
|
|
||
| ## Configuration Options | ||
|
|
||
| You can pass a configuration object to the `eventLoopBlockIntegration` to customize the behavior: | ||
|
|
||
| ```typescript | ||
| interface ThreadBlockedIntegrationOptions { | ||
| /** | ||
| * Threshold in milliseconds to trigger an event. | ||
| * | ||
| * Defaults to 1000ms. | ||
| */ | ||
| threshold: number; | ||
| /** | ||
| * Maximum number of blocked events to send per clock hour. | ||
| * | ||
| * Defaults to 1. | ||
| */ | ||
| maxEventsPerHour: number; | ||
| /** | ||
| * Tags to include with blocked events. | ||
| */ | ||
| staticTags: { [key: string]: Primitive }; | ||
| } | ||
| ``` | ||
|
|
||
| ## Example Configuration | ||
|
|
||
| ```javascript | ||
| import * as Sentry from "@sentry/node"; | ||
| import { eventLoopBlockIntegration } from "@sentry/node-native"; | ||
|
|
||
| Sentry.init({ | ||
| dsn: "__YOUR_DSN__", | ||
| integrations: [ | ||
| eventLoopBlockIntegration({ | ||
| threshold: 500, // Trigger after 500ms of blocking | ||
| maxEventsPerHour: 5, // Maximum 5 events per hour | ||
| staticTags: { | ||
| component: "main-thread", | ||
| environment: "production", | ||
| }, | ||
| }), | ||
| ], | ||
| }); | ||
| ``` |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Capturing stack traces is not optional in the new integration