Skip to content

Commit dc9ed37

Browse files
authored
test(nestjs): Better e2e test for nest.js (#12075)
Our nest e2e test was not fully correct, and did not test the creation of actual nest.js core spans (only http & express spans). This updates the test setup & check to account for this.
1 parent 2f88a5f commit dc9ed37

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as Sentry from '@sentry/node';
2+
3+
Sentry.init({
4+
environment: 'qa', // dynamic sampling bias to keep transactions
5+
dsn: process.env.E2E_TEST_DSN,
6+
tunnel: `http://localhost:3031/`, // proxy server
7+
tracesSampleRate: 1,
8+
tracePropagationTargets: ['http://localhost:3030', '/external-allowed'],
9+
});

dev-packages/e2e-tests/test-applications/node-nestjs/src/main.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Import this first
2+
import './instrument';
3+
4+
// Import other modules
15
import { BaseExceptionFilter, HttpAdapterHost, NestFactory } from '@nestjs/core';
26
import * as Sentry from '@sentry/node';
37
import { AppModule1, AppModule2 } from './app.module';
@@ -6,14 +10,6 @@ const app1Port = 3030;
610
const app2Port = 3040;
711

812
async function bootstrap() {
9-
Sentry.init({
10-
environment: 'qa', // dynamic sampling bias to keep transactions
11-
dsn: process.env.E2E_TEST_DSN,
12-
tunnel: `http://localhost:3031/`, // proxy server
13-
tracesSampleRate: 1,
14-
tracePropagationTargets: ['http://localhost:3030', '/external-allowed'],
15-
});
16-
1713
const app1 = await NestFactory.create(AppModule1);
1814

1915
const { httpAdapter } = app1.get(HttpAdapterHost);

dev-packages/e2e-tests/test-applications/node-nestjs/tests/transactions.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,24 @@ test('Sends an API route transaction', async ({ baseURL }) => {
101101
trace_id: expect.any(String),
102102
origin: 'manual',
103103
},
104+
{
105+
span_id: expect.any(String),
106+
trace_id: expect.any(String),
107+
data: {
108+
'sentry.origin': 'manual',
109+
component: '@nestjs/core',
110+
'nestjs.version': expect.any(String),
111+
'nestjs.type': 'handler',
112+
'nestjs.callback': 'testTransaction',
113+
'otel.kind': 'INTERNAL',
114+
},
115+
description: 'testTransaction',
116+
parent_span_id: expect.any(String),
117+
start_timestamp: expect.any(Number),
118+
timestamp: expect.any(Number),
119+
status: 'ok',
120+
origin: 'manual',
121+
},
104122
]),
105123
transaction: 'GET /test-transaction',
106124
type: 'transaction',

0 commit comments

Comments
 (0)