Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as Sentry from '@sentry/nestjs';

Sentry.init({
traceLifecycle: 'static',
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.E2E_TEST_DSN,
tunnel: `http://localhost:3031/`, // proxy server
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { expect, test } from '@playwright/test';
import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';
import { waitForError, waitForStreamedSpan } from '@sentry-internal/test-utils';

const APP_NAME = 'nestjs-basic-with-graphql';

/**
* Resolves once the request's segment span has been streamed, which is how these specs know the
* request finished and any error it would have produced had its chance to be sent.
*/
function waitForSegmentSpan(name: string): Promise<unknown> {
return waitForStreamedSpan(APP_NAME, span => span.is_segment && span.name === name);
}

test('Sends exception to Sentry', async ({ baseURL }) => {
const errorEventPromise = waitForError('nestjs-basic-with-graphql', event => {
const errorEventPromise = waitForError(APP_NAME, event => {
return !event.type && event.exception?.values?.[0]?.value === 'This is an exception with id 123';
});

Expand Down Expand Up @@ -38,46 +48,42 @@ test('Sends exception to Sentry', async ({ baseURL }) => {
test('Does not send HttpExceptions to Sentry', async ({ baseURL }) => {
let errorEventOccurred = false;

waitForError('nestjs-basic-with-graphql', event => {
waitForError(APP_NAME, event => {
if (!event.type && event.exception?.values?.[0]?.value === 'This is an expected 400 exception with id 123') {
errorEventOccurred = true;
}

return event?.transaction === 'GET /test-expected-400-exception/:id';
});

waitForError('nestjs-basic-with-graphql', event => {
waitForError(APP_NAME, event => {
if (!event.type && event.exception?.values?.[0]?.value === 'This is an expected 500 exception with id 123') {
errorEventOccurred = true;
}

return event?.transaction === 'GET /test-expected-500-exception/:id';
});

const transactionEventPromise400 = waitForTransaction('nestjs-basic-with-graphql', transactionEvent => {
return transactionEvent?.transaction === 'GET /test-expected-400-exception/:id';
});
const segmentSpanPromise400 = waitForSegmentSpan('GET /test-expected-400-exception/:id');

const transactionEventPromise500 = waitForTransaction('nestjs-basic-with-graphql', transactionEvent => {
return transactionEvent?.transaction === 'GET /test-expected-500-exception/:id';
});
const segmentSpanPromise500 = waitForSegmentSpan('GET /test-expected-500-exception/:id');

const response400 = await fetch(`${baseURL}/test-expected-400-exception/123`);
expect(response400.status).toBe(400);

const response500 = await fetch(`${baseURL}/test-expected-500-exception/123`);
expect(response500.status).toBe(500);

await transactionEventPromise400;
await transactionEventPromise500;
await segmentSpanPromise400;
await segmentSpanPromise500;

(await fetch(`${baseURL}/flush`)).text();

expect(errorEventOccurred).toBe(false);
});

test('Sends graphql exception to Sentry', async ({ baseURL }) => {
const errorEventPromise = waitForError('nestjs-basic-with-graphql', event => {
const errorEventPromise = waitForError(APP_NAME, event => {
return !event.type && event.exception?.values?.[0]?.value === 'This is an exception!';
});

Expand Down
Loading