Skip to content

Commit cea631a

Browse files
feat(nestjs): Update nest setup in onboarding (#74929)
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>
1 parent 3a5b77e commit cea631a

File tree

2 files changed

+46
-18
lines changed

2 files changed

+46
-18
lines changed

static/app/gettingStartedDocs/node/nestjs.spec.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,18 @@ describe('Nest.js onboarding docs', function () {
1818

1919
// Includes import statement
2020
const allMatches = screen.getAllByText(
21-
textWithMarkupMatcher(/import \* as Sentry from "@sentry\/nestjs"/)
21+
textWithMarkupMatcher(/import \{ SentryModule } from '@sentry\/nestjs\/setup'/)
2222
);
2323
allMatches.forEach(match => {
2424
expect(match).toBeInTheDocument();
2525
});
2626
});
2727

28-
it('includes error handler', () => {
28+
it('includes root module', () => {
2929
renderWithOnboardingLayout(docs);
3030

3131
expect(
32-
screen.getByText(
33-
textWithMarkupMatcher(
34-
/Sentry\.setupNestErrorHandler\(app, new BaseExceptionFilter\(httpAdapter\)\)/
35-
)
36-
)
32+
screen.getByText(textWithMarkupMatcher(/SentryModule\.forRoot\(\)/))
3733
).toBeInTheDocument();
3834
});
3935

static/app/gettingStartedDocs/node/nestjs.tsx

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
getImportInstrumentSnippet,
2020
getInstallConfig,
2121
getSdkInitSnippet,
22-
getSentryImportSnippet,
2322
} from 'sentry/utils/gettingStartedDocs/node';
2423

2524
type Params = DocsParams;
@@ -28,26 +27,39 @@ const getSdkSetupSnippet = () => `
2827
${getImportInstrumentSnippet('esm')}
2928
3029
// All other imports below
31-
${getSentryImportSnippet('nestjs', 'esm')}
32-
import { BaseExceptionFilter, HttpAdapterHost, NestFactory } from '@nestjs/core';
30+
import { NestFactory } from '@nestjs/core';
3331
import { AppModule } from './app.module';
3432
3533
async function bootstrap() {
3634
const app = await NestFactory.create(AppModule);
37-
38-
const { httpAdapter } = app.get(HttpAdapterHost);
39-
Sentry.setupNestErrorHandler(app, new BaseExceptionFilter(httpAdapter));
40-
4135
await app.listen(3000);
4236
}
4337
4438
bootstrap();
4539
`;
4640

41+
const getAppModuleSnippet = () => `
42+
import { Module } from '@nestjs/common';
43+
import { SentryModule } from '@sentry/nestjs/setup';
44+
import { AppController } from './app.controller';
45+
import { AppService } from './app.service';
46+
47+
@Module({
48+
imports: [
49+
SentryModule.forRoot(),
50+
// ...other modules
51+
],
52+
controllers: [AppController],
53+
providers: [AppService],
54+
})
55+
export class AppModule {}
56+
`;
57+
4758
const getVerifySnippet = () => `
48-
app.use(async function () {
59+
@Get("/debug-sentry")
60+
getError() {
4961
throw new Error("My first Sentry error!");
50-
});
62+
}
5163
`;
5264

5365
const onboarding: OnboardingConfig = {
@@ -84,11 +96,10 @@ const onboarding: OnboardingConfig = {
8496
},
8597
{
8698
description: tct(
87-
'Make sure to import [code1:instrument.js/mjs] at the top of your [code2:main.ts/js] file. Set up the error handler by passing the [code3:BaseExceptionFilter].',
99+
'Import [code1:instrument.js/mjs] in your [code2:main.ts/js] file:',
88100
{
89101
code1: <code />,
90102
code2: <code />,
91-
code3: <code />,
92103
docs: (
93104
<ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/nestjs/install/" />
94105
),
@@ -104,6 +115,27 @@ const onboarding: OnboardingConfig = {
104115
},
105116
],
106117
},
118+
{
119+
description: tct(
120+
'Then you can add the [code1:SentryModule] as a root module. The [code2:SentryModule] needs to be registered before any other module that should be instrumented by Sentry.',
121+
{
122+
code1: <code />,
123+
code2: <code />,
124+
docs: (
125+
<ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/nestjs/install/" />
126+
),
127+
}
128+
),
129+
code: [
130+
{
131+
label: 'JavaScript',
132+
value: 'javascript',
133+
language: 'javascript',
134+
filename: 'app.module.(js|ts)',
135+
code: getAppModuleSnippet(),
136+
},
137+
],
138+
},
107139
],
108140
},
109141
getUploadSourceMapsStep({

0 commit comments

Comments
 (0)