Skip to content

Commit

Permalink
test(nestjs): Better e2e test for nest.js (#12075)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mydea committed May 17, 2024
1 parent 2f88a5f commit dc9ed37
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as Sentry from '@sentry/node';

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.E2E_TEST_DSN,
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1,
tracePropagationTargets: ['http://localhost:3030', '/external-allowed'],
});
12 changes: 4 additions & 8 deletions dev-packages/e2e-tests/test-applications/node-nestjs/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Import this first
import './instrument';

// Import other modules
import { BaseExceptionFilter, HttpAdapterHost, NestFactory } from '@nestjs/core';
import * as Sentry from '@sentry/node';
import { AppModule1, AppModule2 } from './app.module';
Expand All @@ -6,14 +10,6 @@ const app1Port = 3030;
const app2Port = 3040;

async function bootstrap() {
Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.E2E_TEST_DSN,
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1,
tracePropagationTargets: ['http://localhost:3030', '/external-allowed'],
});

const app1 = await NestFactory.create(AppModule1);

const { httpAdapter } = app1.get(HttpAdapterHost);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ test('Sends an API route transaction', async ({ baseURL }) => {
trace_id: expect.any(String),
origin: 'manual',
},
{
span_id: expect.any(String),
trace_id: expect.any(String),
data: {
'sentry.origin': 'manual',
component: '@nestjs/core',
'nestjs.version': expect.any(String),
'nestjs.type': 'handler',
'nestjs.callback': 'testTransaction',
'otel.kind': 'INTERNAL',
},
description: 'testTransaction',
parent_span_id: expect.any(String),
start_timestamp: expect.any(Number),
timestamp: expect.any(Number),
status: 'ok',
origin: 'manual',
},
]),
transaction: 'GET /test-transaction',
type: 'transaction',
Expand Down

0 comments on commit dc9ed37

Please sign in to comment.