forked from getsentry/sentry-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nestjs): Update scope transaction name with parameterized route (g…
…etsentry#11510) This PR adds scope transactionName updating to our NestJS instrumentation. Similarly to Hapi and Fastify, we can use a framework-native component, an Interceptor, to assign the parameterized route. ref getsentry#10846
- Loading branch information
1 parent
cd7793a
commit b429c86
Showing
13 changed files
with
365 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 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
58 changes: 58 additions & 0 deletions
58
dev-packages/node-integration-tests/suites/tracing/nestjs-errors-no-express/scenario.ts
This file contains 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,58 @@ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-nocheck These are only tests | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
/* eslint-disable @typescript-eslint/explicit-member-accessibility */ | ||
import { loggingTransport, sendPortToRunner } from '@sentry-internal/node-integration-tests'; | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
release: '1.0', | ||
tracesSampleRate: 0, | ||
transport: loggingTransport, | ||
integrations: integrations => integrations.filter(i => i.name !== 'Express'), | ||
debug: true, | ||
}); | ||
|
||
import { Controller, Get, Injectable, Module, Param } from '@nestjs/common'; | ||
import { NestFactory } from '@nestjs/core'; | ||
|
||
const port = 3480; | ||
|
||
// Stop the process from exiting before the transaction is sent | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
setInterval(() => {}, 1000); | ||
|
||
@Injectable() | ||
class AppService { | ||
getHello(): string { | ||
return 'Hello World!'; | ||
} | ||
} | ||
|
||
@Controller() | ||
class AppController { | ||
constructor(private readonly appService: AppService) {} | ||
|
||
@Get('test-exception/:id') | ||
async testException(@Param('id') id: string): void { | ||
Sentry.captureException(new Error(`error with id ${id}`)); | ||
} | ||
} | ||
|
||
@Module({ | ||
imports: [], | ||
controllers: [AppController], | ||
providers: [AppService], | ||
}) | ||
class AppModule {} | ||
|
||
async function init(): Promise<void> { | ||
const app = await NestFactory.create(AppModule); | ||
Sentry.setupNestErrorHandler(app); | ||
await app.listen(port); | ||
sendPortToRunner(port); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
init(); |
39 changes: 39 additions & 0 deletions
39
dev-packages/node-integration-tests/suites/tracing/nestjs-errors-no-express/test.ts
This file contains 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,39 @@ | ||
import { conditionalTest } from '../../../utils'; | ||
import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
|
||
jest.setTimeout(20000); | ||
|
||
const { TS_VERSION } = process.env; | ||
const isOldTS = TS_VERSION && TS_VERSION.startsWith('3.'); | ||
|
||
// This is required to run the test with ts-node and decorators | ||
process.env.TS_NODE_PROJECT = `${__dirname}/tsconfig.json`; | ||
|
||
conditionalTest({ min: 16 })('nestjs auto instrumentation', () => { | ||
afterAll(async () => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
test("should assign scope's transactionName if spans are not sampled and express integration is disabled", done => { | ||
if (isOldTS) { | ||
// Skipping test on old TypeScript | ||
return done(); | ||
} | ||
|
||
createRunner(__dirname, 'scenario.ts') | ||
.expect({ | ||
event: { | ||
exception: { | ||
values: [ | ||
{ | ||
value: 'error with id 456', | ||
}, | ||
], | ||
}, | ||
transaction: 'GET /test-exception/:id', | ||
}, | ||
}) | ||
.start(done) | ||
.makeRequest('get', '/test-exception/456'); | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
dev-packages/node-integration-tests/suites/tracing/nestjs-errors-no-express/tsconfig.json
This file contains 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,9 @@ | ||
{ | ||
"include": ["scenario.ts"], | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"target": "ES2021", | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
dev-packages/node-integration-tests/suites/tracing/nestjs-errors/scenario.ts
This file contains 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,56 @@ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-nocheck These are only tests | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
/* eslint-disable @typescript-eslint/explicit-member-accessibility */ | ||
import { loggingTransport, sendPortToRunner } from '@sentry-internal/node-integration-tests'; | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
release: '1.0', | ||
tracesSampleRate: 0, | ||
transport: loggingTransport, | ||
}); | ||
|
||
import { Controller, Get, Injectable, Module, Param } from '@nestjs/common'; | ||
import { NestFactory } from '@nestjs/core'; | ||
|
||
const port = 3460; | ||
|
||
// Stop the process from exiting before the transaction is sent | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
setInterval(() => {}, 1000); | ||
|
||
@Injectable() | ||
class AppService { | ||
getHello(): string { | ||
return 'Hello World!'; | ||
} | ||
} | ||
|
||
@Controller() | ||
class AppController { | ||
constructor(private readonly appService: AppService) {} | ||
|
||
@Get('test-exception/:id') | ||
async testException(@Param('id') id: string): void { | ||
Sentry.captureException(new Error(`error with id ${id}`)); | ||
} | ||
} | ||
|
||
@Module({ | ||
imports: [], | ||
controllers: [AppController], | ||
providers: [AppService], | ||
}) | ||
class AppModule {} | ||
|
||
async function init(): Promise<void> { | ||
const app = await NestFactory.create(AppModule); | ||
Sentry.setupNestErrorHandler(app); | ||
await app.listen(port); | ||
sendPortToRunner(port); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
init(); |
39 changes: 39 additions & 0 deletions
39
dev-packages/node-integration-tests/suites/tracing/nestjs-errors/test.ts
This file contains 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,39 @@ | ||
import { conditionalTest } from '../../../utils'; | ||
import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
|
||
jest.setTimeout(20000); | ||
|
||
const { TS_VERSION } = process.env; | ||
const isOldTS = TS_VERSION && TS_VERSION.startsWith('3.'); | ||
|
||
// This is required to run the test with ts-node and decorators | ||
process.env.TS_NODE_PROJECT = `${__dirname}/tsconfig.json`; | ||
|
||
conditionalTest({ min: 16 })('nestjs auto instrumentation', () => { | ||
afterAll(async () => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
test("should assign scope's transactionName if spans are not sampled", done => { | ||
if (isOldTS) { | ||
// Skipping test on old TypeScript | ||
return done(); | ||
} | ||
|
||
createRunner(__dirname, 'scenario.ts') | ||
.expect({ | ||
event: { | ||
exception: { | ||
values: [ | ||
{ | ||
value: 'error with id 123', | ||
}, | ||
], | ||
}, | ||
transaction: 'GET /test-exception/:id', | ||
}, | ||
}) | ||
.start(done) | ||
.makeRequest('get', '/test-exception/123'); | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
dev-packages/node-integration-tests/suites/tracing/nestjs-errors/tsconfig.json
This file contains 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,9 @@ | ||
{ | ||
"include": ["scenario.ts"], | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"target": "ES2021", | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
dev-packages/node-integration-tests/suites/tracing/nestjs-no-express/scenario.ts
This file contains 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,58 @@ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-nocheck These are only tests | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
/* eslint-disable @typescript-eslint/explicit-member-accessibility */ | ||
import { loggingTransport, sendPortToRunner } from '@sentry-internal/node-integration-tests'; | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1, | ||
transport: loggingTransport, | ||
integrations: integrations => integrations.filter(i => i.name !== 'Express'), | ||
debug: true, | ||
}); | ||
|
||
import { Controller, Get, Injectable, Module, Param } from '@nestjs/common'; | ||
import { NestFactory } from '@nestjs/core'; | ||
|
||
const port = 3470; | ||
|
||
// Stop the process from exiting before the transaction is sent | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
setInterval(() => {}, 1000); | ||
|
||
@Injectable() | ||
class AppService { | ||
getHello(): string { | ||
return 'Hello World!'; | ||
} | ||
} | ||
|
||
@Controller() | ||
class AppController { | ||
constructor(private readonly appService: AppService) {} | ||
|
||
@Get('test-exception/:id') | ||
async testException(@Param('id') id: string): void { | ||
Sentry.captureException(new Error(`error with id ${id}`)); | ||
} | ||
} | ||
|
||
@Module({ | ||
imports: [], | ||
controllers: [AppController], | ||
providers: [AppService], | ||
}) | ||
class AppModule {} | ||
|
||
async function init(): Promise<void> { | ||
const app = await NestFactory.create(AppModule); | ||
Sentry.setupNestErrorHandler(app); | ||
await app.listen(port); | ||
sendPortToRunner(port); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
init(); |
40 changes: 40 additions & 0 deletions
40
dev-packages/node-integration-tests/suites/tracing/nestjs-no-express/test.ts
This file contains 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,40 @@ | ||
import { conditionalTest } from '../../../utils'; | ||
import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
|
||
jest.setTimeout(20000); | ||
|
||
const { TS_VERSION } = process.env; | ||
const isOldTS = TS_VERSION && TS_VERSION.startsWith('3.'); | ||
|
||
// This is required to run the test with ts-node and decorators | ||
process.env.TS_NODE_PROJECT = `${__dirname}/tsconfig.json`; | ||
|
||
conditionalTest({ min: 16 })('nestjs auto instrumentation', () => { | ||
afterAll(async () => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
test("should assign scope's transactionName if express integration is disabled", done => { | ||
if (isOldTS) { | ||
// Skipping test on old TypeScript | ||
return done(); | ||
} | ||
|
||
createRunner(__dirname, 'scenario.ts') | ||
.ignore('transaction') | ||
.expect({ | ||
event: { | ||
exception: { | ||
values: [ | ||
{ | ||
value: 'error with id 456', | ||
}, | ||
], | ||
}, | ||
transaction: 'GET /test-exception/:id', | ||
}, | ||
}) | ||
.start(done) | ||
.makeRequest('get', '/test-exception/456'); | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
dev-packages/node-integration-tests/suites/tracing/nestjs-no-express/tsconfig.json
This file contains 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,9 @@ | ||
{ | ||
"include": ["scenario.ts"], | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"target": "ES2021", | ||
} | ||
} |
Oops, something went wrong.