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
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ jobs:
- name: Run integration tests
env:
NODE_VERSION: ${{ matrix.node }}
TS_VERSION: ${{ matrix.typescript }}
run: |
cd dev-packages/node-integration-tests
yarn test
Expand Down
5 changes: 5 additions & 0 deletions dev-packages/node-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
},
"dependencies": {
"@hapi/hapi": "^20.3.0",
"@nestjs/core": "^10.3.3",
"@nestjs/common": "^10.3.3",
"@nestjs/platform-express": "^10.3.3",
"@prisma/client": "3.15.2",
"@sentry/node": "7.100.0",
"@sentry/tracing": "7.100.0",
Expand All @@ -50,6 +53,8 @@
"nock": "^13.1.0",
"pg": "^8.7.3",
"proxy": "^2.1.1",
"reflect-metadata": "0.2.1",
"rxjs": "^7.8.1",
"yargs": "^16.2.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* 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-experimental';

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
});

import { Controller, Get, Injectable, Module } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';

const port = 3450;

// 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()
getHello(): string {
return this.appService.getHello();
}
}

@Module({
imports: [],
controllers: [AppController],
providers: [AppService],
})
class AppModule {}

async function init(): Promise<void> {
const app = await NestFactory.create(AppModule);
await app.listen(port);
sendPortToRunner(port);
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises
init();
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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();
});

const CREATION_TRANSACTION = {
transaction: 'Create Nest App',
};

const GET_TRANSACTION = {
transaction: 'GET /',
spans: expect.arrayContaining([
expect.objectContaining({
description: 'GET /',
data: expect.objectContaining({
'nestjs.callback': 'getHello',
'nestjs.controller': 'AppController',
'nestjs.type': 'request_context',
'otel.kind': 'INTERNAL',
'sentry.op': 'http',
}),
}),
]),
};

test('should auto-instrument `nestjs` package', done => {
if (isOldTS) {
// Skipping test on old TypeScript
return done();
}

createRunner(__dirname, 'scenario.ts')
.expect({ transaction: CREATION_TRANSACTION })
.expect({ transaction: GET_TRANSACTION })
.start(done)
.makeRequest('get', '/');
});
});
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",
}
}
Loading