Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions static/app/gettingStartedDocs/node/nestjs.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,18 @@ describe('Nest.js onboarding docs', function () {

// Includes import statement
const allMatches = screen.getAllByText(
textWithMarkupMatcher(/import \* as Sentry from "@sentry\/nestjs"/)
textWithMarkupMatcher(/import \{ SentryModule } from '@sentry\/nestjs\/setup'/)
);
allMatches.forEach(match => {
expect(match).toBeInTheDocument();
});
});

it('includes error handler', () => {
it('includes root module', () => {
renderWithOnboardingLayout(docs);

expect(
screen.getByText(
textWithMarkupMatcher(
/Sentry\.setupNestErrorHandler\(app, new BaseExceptionFilter\(httpAdapter\)\)/
)
)
screen.getByText(textWithMarkupMatcher(/SentryModule\.forRoot\(\)/))
).toBeInTheDocument();
});

Expand Down
54 changes: 43 additions & 11 deletions static/app/gettingStartedDocs/node/nestjs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
getImportInstrumentSnippet,
getInstallConfig,
getSdkInitSnippet,
getSentryImportSnippet,
} from 'sentry/utils/gettingStartedDocs/node';

type Params = DocsParams;
Expand All @@ -28,26 +27,39 @@ const getSdkSetupSnippet = () => `
${getImportInstrumentSnippet('esm')}

// All other imports below
${getSentryImportSnippet('nestjs', 'esm')}
import { BaseExceptionFilter, HttpAdapterHost, NestFactory } from '@nestjs/core';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);

const { httpAdapter } = app.get(HttpAdapterHost);
Sentry.setupNestErrorHandler(app, new BaseExceptionFilter(httpAdapter));

await app.listen(3000);
}

bootstrap();
`;

const getAppModuleSnippet = () => `
import { Module } from '@nestjs/common';
import { SentryModule } from '@sentry/nestjs/setup';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
imports: [
SentryModule.forRoot(),
// ...other modules
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
`;

const getVerifySnippet = () => `
app.use(async function () {
@Get("/debug-sentry")
getError() {
throw new Error("My first Sentry error!");
});
}
`;

const onboarding: OnboardingConfig = {
Expand Down Expand Up @@ -84,11 +96,10 @@ const onboarding: OnboardingConfig = {
},
{
description: tct(
'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].',
'Import [code1:instrument.js/mjs] in your [code2:main.ts/js] file:',
{
code1: <code />,
code2: <code />,
code3: <code />,
docs: (
<ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/nestjs/install/" />
),
Expand All @@ -104,6 +115,27 @@ const onboarding: OnboardingConfig = {
},
],
},
{
description: tct(
'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.',
{
code1: <code />,
code2: <code />,
docs: (
<ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/nestjs/install/" />
),
}
),
code: [
{
label: 'JavaScript',
value: 'javascript',
language: 'javascript',
filename: 'app.module.(js|ts)',
code: getAppModuleSnippet(),
},
],
},
],
},
getUploadSourceMapsStep({
Expand Down