GeezerVison is showing github.com — feat(nestjs): Change nest sdk setup by nicohrubec · Pull Request #12920 · getsentry/sentry-javascript
Conversation
nicohrubec
commented
Jul 15, 2024
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
- Adds a new nest root module that can be used to setup the Nest SDK as a replacement for the existing setup (with a function). Instead of calling
setupNestErrorHandler in the main.ts file, users can now add SentryModule.forRoot() (feedback about the name is definitely welcome) as an import in their main app module. This approach is much more native to nest than what we used so far. This root module is introduced in the setup.ts file.
- This root module is exported with a submodule export
@sentry/nestjs/setup, because the SDK now depends on nestjs directly and without this the nest instrumentation does not work anymore, since nest gets imported before Sentry.init gets called, which disables the otel nest instrumentation.
- Judging from the e2e tests it seems that this new approach also resolves some issues the previous implementation had, specifically this issue seems to be resolved. The e2e test that was in place, just documented the current (wrong) behavior. So I updated the test to reflect the new (correct) behavior.
- I updated all the test applications to use the new approach but kept a copy of the nestjs-basic and nestjs-distributed-tracing with the old setup (now named node-nestjs-basic and node-nestjs-distributed-tracing respectively) so we can still verify that the old setup (which a lot of people use) still keeps working going forward.
- Updated/New tests in this PR:
- Sends unexpected exception to Sentry if thrown in Submodule
- Does not send expected exception to Sentry if thrown in Submodule and caught by a global exception filter
- Does not send expected exception to Sentry if thrown in Submodule and caught by a local exception filter
- Sends expected exception to Sentry if thrown from submodule registered before Sentry
- To accomodate the new tests I added several submodules in the nestjs-with-submodules test-application. These are overall similarly but have important distinctions:
- example-module-local-filter: Submodule with a local filter registered using
@UseFilters on the controller.
- example-module-global-filter: Submodule with a global filter registered using APP_FILTER in the submodule definition.
- example-module-global-filter-wrong-registration-order: Also has a global filter set with APP_FILTER, but is registered in the root module as first submodule, even before the SentryIntegration is initialized. This case does not work properly in the new setup (Sentry should be set first), so this module is used for tests documenting this behavior.
- Also set "moduleResolution": "Node16" in the nestjs-basic sample app to ensure our submodule-export workaround works in both, default and sub-path-export-compatible TS configs as was suggested here.
Sorry, this PR got a bit long (but most of it is copying existing test applications into new folders).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
size-limit report 📦
| Path |
Size |
| @sentry/browser |
22.31 KB (0%) |
| @sentry/browser (incl. Tracing) |
33.72 KB (0%) |
| @sentry/browser (incl. Tracing, Replay) |
69.81 KB (0%) |
| @sentry/browser (incl. Tracing, Replay) - with treeshaking flags |
63.15 KB (0%) |
| @sentry/browser (incl. Tracing, Replay with Canvas) |
74.21 KB (0%) |
| @sentry/browser (incl. Tracing, Replay, Feedback) |
86.52 KB (0%) |
| @sentry/browser (incl. Tracing, Replay, Feedback, metrics) |
88.4 KB (0%) |
| @sentry/browser (incl. metrics) |
26.62 KB (0%) |
| @sentry/browser (incl. Feedback) |
38.98 KB (0%) |
| @sentry/browser (incl. sendFeedback) |
26.93 KB (0%) |
| @sentry/browser (incl. FeedbackAsync) |
31.54 KB (0%) |
| @sentry/react |
25.08 KB (0%) |
| @sentry/react (incl. Tracing) |
36.8 KB (0%) |
| @sentry/vue |
26.45 KB (0%) |
| @sentry/vue (incl. Tracing) |
35.61 KB (0%) |
| @sentry/svelte |
22.44 KB (0%) |
| CDN Bundle |
23.52 KB (0%) |
| CDN Bundle (incl. Tracing) |
35.5 KB (0%) |
| CDN Bundle (incl. Tracing, Replay) |
69.9 KB (0%) |
| CDN Bundle (incl. Tracing, Replay, Feedback) |
75.17 KB (0%) |
| CDN Bundle - uncompressed |
69 KB (0%) |
| CDN Bundle (incl. Tracing) - uncompressed |
105.1 KB (0%) |
| CDN Bundle (incl. Tracing, Replay) - uncompressed |
216.88 KB (0%) |
| CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed |
229.6 KB (0%) |
| @sentry/nextjs (client) |
36.66 KB (0%) |
| @sentry/sveltekit (client) |
34.39 KB (0%) |
| @sentry/node |
111.76 KB (0%) |
| @sentry/node - without tracing |
89.21 KB (0%) |
| @sentry/aws-serverless |
98.34 KB (-0.01% 🔽) |
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
nicohrubec
added a commit
to getsentry/sentry
that referenced
this pull request
Jul 30, 2024
related to getsentry/sentry-javascript#12920
There is a new way to setup the nest SDK. Updating the product
onboarding accordingly.
---------
Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
tamir-frenkel
pushed a commit
to tamir-frenkel/sentry
that referenced
this pull request
Nov 30, 2025
related to getsentry/sentry-javascript#12920
There is a new way to setup the nest SDK. Updating the product
onboarding accordingly.
---------
Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
Reviewers
chargome
chargome approved these changes
+1 more reviewer
lforst
lforst approved these changes
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Milestone
No milestone
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.
|