Skip to content
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

feat(nestjs): Change nest sdk setup #12920

Merged
merged 67 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
5963dbe
Add nest error handler setup to nest SDK
nicohrubec Jul 9, 2024
d4ca10a
Add otel dependency to nest
nicohrubec Jul 9, 2024
d9588ef
Update import
nicohrubec Jul 9, 2024
edcc9dc
Update sentry version
nicohrubec Jul 9, 2024
76eee81
Merge branch 'develop' into nh/improve-nestjs-error-handling
nicohrubec Jul 10, 2024
3778ea5
Update dependencies
nicohrubec Jul 10, 2024
dd5f558
Fix lints
nicohrubec Jul 10, 2024
b9d22c2
Update yarn.lock
nicohrubec Jul 10, 2024
18cba0a
Merge branch 'develop' into nh/improve-nestjs-error-handling
lforst Jul 10, 2024
d27f688
Update dependency
nicohrubec Jul 10, 2024
380657e
Revert yarn.lock
nicohrubec Jul 10, 2024
ae5dc1f
Update yarn.lock
nicohrubec Jul 10, 2024
fd1e084
Revert yarn.lock
nicohrubec Jul 10, 2024
5a134ba
Update dependency
nicohrubec Jul 10, 2024
2795344
Merge branch 'develop' into nh/improve-nestjs-error-handling
nicohrubec Jul 10, 2024
72e4f8e
Merge branch 'develop' into nh/improve-nestjs-error-handling
nicohrubec Jul 11, 2024
dbf33fc
Bsaeline
nicohrubec Jul 11, 2024
98363a3
.
nicohrubec Jul 11, 2024
75e8da3
Fix tests
nicohrubec Jul 11, 2024
eab3357
Update
nicohrubec Jul 11, 2024
683dce7
.
nicohrubec Jul 11, 2024
ff07588
Updates
nicohrubec Jul 11, 2024
c89c13c
Create root module: Broken so far
nicohrubec Jul 15, 2024
149f1ae
Build works now
nicohrubec Jul 15, 2024
27fad22
Move interceptor to separate class
nicohrubec Jul 15, 2024
49fe07d
Move interceptor to separate class now fr
nicohrubec Jul 15, 2024
c56b363
Revert test
nicohrubec Jul 15, 2024
53e40b3
Lint
nicohrubec Jul 15, 2024
72aead3
Update decorators
nicohrubec Jul 15, 2024
8804071
Fix capture exception
nicohrubec Jul 16, 2024
14e5439
Fix does not send error test
nicohrubec Jul 16, 2024
ca4ba13
Remove some logs
nicohrubec Jul 16, 2024
b095279
Fix test: Does not handle expected exception if exception is thrown i…
nicohrubec Jul 16, 2024
da0fffd
Rename test module to example module in nest test application
nicohrubec Jul 16, 2024
6eb6fc5
Put comment back in that got lost
nicohrubec Jul 16, 2024
ae1d6d6
.
nicohrubec Jul 16, 2024
b50c3cb
Add debug logs
nicohrubec Jul 16, 2024
f6f2ff5
Use node nestIntegration
nicohrubec Jul 16, 2024
215deee
More debug logs
nicohrubec Jul 17, 2024
aae09ba
Fix e2e tests I think
nicohrubec Jul 17, 2024
ac28e4b
Merge branch 'develop' into nh/nestjs-root-module
nicohrubec Jul 17, 2024
56d3e8f
Add eslintignore
nicohrubec Jul 17, 2024
11adb8f
Rename example module back to test module
nicohrubec Jul 17, 2024
116f0db
Remove logs
nicohrubec Jul 17, 2024
ada0ecc
Merge develop
nicohrubec Jul 18, 2024
6bfbdf0
Update nest setup to root module in tests
nicohrubec Jul 18, 2024
0170f14
Put in nestjs sample applications testing old setup
nicohrubec Jul 18, 2024
e19f434
Lint
nicohrubec Jul 18, 2024
17e4237
Move decorators to class definition + add docstrings and notes
nicohrubec Jul 18, 2024
b11ecd2
Remove compiler options again from package
nicohrubec Jul 18, 2024
5b23ae6
Rename example module
nicohrubec Jul 19, 2024
72d0031
Add test with local filter
nicohrubec Jul 19, 2024
07533a7
Test: Send uncaught exception to sentry if thrown in module with glob…
nicohrubec Jul 19, 2024
a0dcd4f
Add transaction test
nicohrubec Jul 19, 2024
ce3322a
Testing wrong registration order
nicohrubec Jul 19, 2024
220a943
Add compiler option to verify nest works in subexport configured apps
nicohrubec Jul 19, 2024
0edd4d1
Merge branch 'develop' into nh/nestjs-root-module
nicohrubec Jul 19, 2024
da2b952
More specific test names
nicohrubec Jul 23, 2024
b3b6d14
Move exports below decorators
nicohrubec Jul 23, 2024
2eb4bdc
Remove duplicated //
nicohrubec Jul 23, 2024
357a274
DEBUG_BUILD
nicohrubec Jul 23, 2024
46edc34
Update nest README
nicohrubec Jul 23, 2024
345b558
Rename to SentryModule
nicohrubec Jul 23, 2024
7908cb2
.
nicohrubec Jul 23, 2024
8273956
Update supported nest versions
nicohrubec Jul 23, 2024
9466308
Update README
nicohrubec Jul 23, 2024
9524ac9
Update README
nicohrubec Jul 23, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,8 @@ jobs:
'generic-ts3.8',
'node-fastify',
'node-hapi',
'node-nestjs-basic',
'node-nestjs-distributed-tracing',
'nestjs-basic',
'nestjs-distributed-tracing',
'nestjs-with-submodules',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Module } from '@nestjs/common';
import { ScheduleModule } from '@nestjs/schedule';
import { SentryModule } from '@sentry/nestjs/setup';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
imports: [ScheduleModule.forRoot()],
imports: [SentryModule.forRoot(), ScheduleModule.forRoot()],
controllers: [AppController],
providers: [AppService],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@
import './instrument';

// Import other modules
import { BaseExceptionFilter, HttpAdapterHost, NestFactory } from '@nestjs/core';
import * as Sentry from '@sentry/nestjs';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

const PORT = 3030;

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

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

await app.listen(PORT);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
"noFallthroughCasesInSwitch": false,
"moduleResolution": "Node16"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import './instrument';

// Import other modules
import { BaseExceptionFilter, HttpAdapterHost, NestFactory } from '@nestjs/core';
import * as Sentry from '@sentry/nestjs';
import { NestFactory } from '@nestjs/core';
import { TraceInitiatorModule } from './trace-initiator.module';
import { TraceReceiverModule } from './trace-receiver.module';

Expand All @@ -12,10 +11,6 @@ const TRACE_RECEIVER_PORT = 3040;

async function bootstrap() {
const trace_initiator_app = await NestFactory.create(TraceInitiatorModule);

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

await trace_initiator_app.listen(TRACE_INITIATOR_PORT);

const trace_receiver_app = await NestFactory.create(TraceReceiverModule);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Module } from '@nestjs/common';
import { SentryModule } from '@sentry/nestjs/setup';
import { TraceInitiatorController } from './trace-initiator.controller';
import { TraceInitiatorService } from './trace-initiator.service';

@Module({
imports: [],
imports: [SentryModule.forRoot()],
controllers: [TraceInitiatorController],
providers: [TraceInitiatorService],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { Module } from '@nestjs/common';
import { SentryModule } from '@sentry/nestjs/setup';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ExampleModule } from './example-module/example.module';
import { ExampleModuleGlobalFilterWrongRegistrationOrder } from './example-module-global-filter-wrong-registration-order/example.module';
import { ExampleModuleGlobalFilter } from './example-module-global-filter/example.module';
import { ExampleModuleLocalFilter } from './example-module-local-filter/example.module';

@Module({
imports: [ExampleModule],
imports: [
ExampleModuleGlobalFilterWrongRegistrationOrder,
SentryModule.forRoot(),
ExampleModuleGlobalFilter,
ExampleModuleLocalFilter,
],
controllers: [AppController],
providers: [AppService],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Controller, Get } from '@nestjs/common';
import { ExampleExceptionWrongRegistrationOrder } from './example.exception';

@Controller('example-module-wrong-order')
export class ExampleController {
constructor() {}

@Get('/expected-exception')
getCaughtException(): string {
throw new ExampleExceptionWrongRegistrationOrder();
}

@Get('/unexpected-exception')
getUncaughtException(): string {
throw new Error(`This is an uncaught exception!`);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class ExampleExceptionWrongRegistrationOrder extends Error {
constructor() {
super('Something went wrong in the example module!');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ArgumentsHost, BadRequestException, Catch } from '@nestjs/common';
import { BaseExceptionFilter } from '@nestjs/core';
import { ExampleExceptionWrongRegistrationOrder } from './example.exception';

@Catch(ExampleExceptionWrongRegistrationOrder)
export class ExampleExceptionFilterWrongRegistrationOrder extends BaseExceptionFilter {
catch(exception: unknown, host: ArgumentsHost) {
if (exception instanceof ExampleExceptionWrongRegistrationOrder) {
return super.catch(new BadRequestException(exception.message), host);
}
return super.catch(exception, host);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Module } from '@nestjs/common';
import { APP_FILTER } from '@nestjs/core';
import { ExampleController } from './example.controller';
import { ExampleExceptionFilterWrongRegistrationOrder } from './example.filter';

@Module({
imports: [],
controllers: [ExampleController],
providers: [
{
provide: APP_FILTER,
useClass: ExampleExceptionFilterWrongRegistrationOrder,
},
],
})
export class ExampleModuleGlobalFilterWrongRegistrationOrder {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Controller, Get } from '@nestjs/common';
import * as Sentry from '@sentry/nestjs';
import { ExampleException } from './example.exception';

@Controller('example-module')
export class ExampleController {
constructor() {}

@Get('/expected-exception')
getCaughtException(): string {
throw new ExampleException();
}

@Get('/unexpected-exception')
getUncaughtException(): string {
throw new Error(`This is an uncaught exception!`);
}

@Get('/transaction')
testTransaction() {
Sentry.startSpan({ name: 'test-span' }, () => {
Sentry.startSpan({ name: 'child-span' }, () => {});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ import { ExampleExceptionFilter } from './example.filter';
},
],
})
export class ExampleModule {}
export class ExampleModuleGlobalFilter {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Controller, Get, UseFilters } from '@nestjs/common';
import { LocalExampleException } from './example.exception';
import { LocalExampleExceptionFilter } from './example.filter';

@Controller('example-module-local-filter')
@UseFilters(LocalExampleExceptionFilter)
export class ExampleControllerLocalFilter {
constructor() {}

@Get('/expected-exception')
getCaughtException() {
throw new LocalExampleException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class LocalExampleException extends Error {
constructor() {
super('Something went wrong in the example module with local filter!');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ArgumentsHost, BadRequestException, Catch } from '@nestjs/common';
import { BaseExceptionFilter } from '@nestjs/core';
import { LocalExampleException } from './example.exception';

@Catch(LocalExampleException)
export class LocalExampleExceptionFilter extends BaseExceptionFilter {
catch(exception: unknown, host: ArgumentsHost) {
if (exception instanceof LocalExampleException) {
return super.catch(new BadRequestException(exception.message), host);
}
return super.catch(exception, host);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { ExampleControllerLocalFilter } from './example.controller';

@Module({
imports: [],
controllers: [ExampleControllerLocalFilter],
providers: [],
})
export class ExampleModuleLocalFilter {}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@
import './instrument';

// Import other modules
import { BaseExceptionFilter, HttpAdapterHost, NestFactory } from '@nestjs/core';
import * as Sentry from '@sentry/nestjs';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

const PORT = 3030;

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

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

await app.listen(PORT);
}

Expand Down
Loading
Loading