From 3bf35884c371a49d9295986d8027237f54b7d4d9 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Tue, 14 May 2024 09:16:17 +0200 Subject: [PATCH 1/3] test(node): Add test for express without tracing --- .../suites/express/without-tracing/server.ts | 30 +++++++++++ .../suites/express/without-tracing/test.ts | 50 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 dev-packages/node-integration-tests/suites/express/without-tracing/server.ts create mode 100644 dev-packages/node-integration-tests/suites/express/without-tracing/test.ts diff --git a/dev-packages/node-integration-tests/suites/express/without-tracing/server.ts b/dev-packages/node-integration-tests/suites/express/without-tracing/server.ts new file mode 100644 index 000000000000..8f09e6c5f806 --- /dev/null +++ b/dev-packages/node-integration-tests/suites/express/without-tracing/server.ts @@ -0,0 +1,30 @@ +import { loggingTransport } 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', + transport: loggingTransport, +}); + +import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests'; +import express from 'express'; + +const app = express(); + +Sentry.setTag('global', 'tag'); + +app.get('/test/isolationScope/:id', (req, res) => { + const id = req.params.id; + Sentry.setTag('isolation-scope', 'tag'); + Sentry.setTag(`isolation-scope-${id}`, id); + Sentry.setTag(`isolation-scope-transactionName`, `${Sentry.getIsolationScope().getScopeData().transactionName}`); + + Sentry.captureException(new Error('This is an exception')); + + res.send({}); +}); + +Sentry.setupExpressErrorHandler(app); + +startExpressServerAndSendPortToRunner(app); diff --git a/dev-packages/node-integration-tests/suites/express/without-tracing/test.ts b/dev-packages/node-integration-tests/suites/express/without-tracing/test.ts new file mode 100644 index 000000000000..42a6f63f0007 --- /dev/null +++ b/dev-packages/node-integration-tests/suites/express/without-tracing/test.ts @@ -0,0 +1,50 @@ +import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; + +afterAll(() => { + cleanupChildProcesses(); +}); + +test('correctly applies isolation scope even without tracing', async () => { + const runner = createRunner(__dirname, 'server.ts') + .ignore('session', 'sessions') + .expect({ + event: { + tags: { + global: 'tag', + 'isolation-scope': 'tag', + 'isolation-scope-1': '1', + // We can't properly test non-existance of fields here, so we cast this to a string to test it here + 'isolation-scope-transactionName': 'undefined', + }, + // Request is correctly set + request: { + url: expect.stringContaining('/test/isolationScope/1'), + headers: { + 'user-agent': expect.stringContaining(''), + }, + }, + }, + }) + .expect({ + event: { + tags: { + global: 'tag', + 'isolation-scope': 'tag', + 'isolation-scope-2': '2', + // We can't properly test non-existance of fields here, so we cast this to a string to test it here + 'isolation-scope-transactionName': 'undefined', + }, + // Request is correctly set + request: { + url: expect.stringContaining('/test/isolationScope/2'), + headers: { + 'user-agent': expect.stringContaining(''), + }, + }, + }, + }) + .start(); + + await runner.makeRequest('get', '/test/isolationScope/1'); + await runner.makeRequest('get', '/test/isolationScope/2'); +}); From aff5e9ac6f53dca40753f8d3a7164877af417ed8 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Tue, 14 May 2024 09:29:10 +0200 Subject: [PATCH 2/3] ensure test order is correct --- .../suites/express/without-tracing/test.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/dev-packages/node-integration-tests/suites/express/without-tracing/test.ts b/dev-packages/node-integration-tests/suites/express/without-tracing/test.ts index 42a6f63f0007..85c037dc0df9 100644 --- a/dev-packages/node-integration-tests/suites/express/without-tracing/test.ts +++ b/dev-packages/node-integration-tests/suites/express/without-tracing/test.ts @@ -4,7 +4,7 @@ afterAll(() => { cleanupChildProcesses(); }); -test('correctly applies isolation scope even without tracing', async () => { +test('correctly applies isolation scope even without tracing', done => { const runner = createRunner(__dirname, 'server.ts') .ignore('session', 'sessions') .expect({ @@ -43,8 +43,7 @@ test('correctly applies isolation scope even without tracing', async () => { }, }, }) - .start(); + .start(done); - await runner.makeRequest('get', '/test/isolationScope/1'); - await runner.makeRequest('get', '/test/isolationScope/2'); + runner.makeRequest('get', '/test/isolationScope/1').then(() => runner.makeRequest('get', '/test/isolationScope/2')); }); From bfffe68364b3793614de8145fc4108c29265c908 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Tue, 14 May 2024 10:19:38 +0200 Subject: [PATCH 3/3] fix lint --- .../suites/express/without-tracing/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-packages/node-integration-tests/suites/express/without-tracing/server.ts b/dev-packages/node-integration-tests/suites/express/without-tracing/server.ts index 8f09e6c5f806..6b8af4270430 100644 --- a/dev-packages/node-integration-tests/suites/express/without-tracing/server.ts +++ b/dev-packages/node-integration-tests/suites/express/without-tracing/server.ts @@ -18,7 +18,7 @@ app.get('/test/isolationScope/:id', (req, res) => { const id = req.params.id; Sentry.setTag('isolation-scope', 'tag'); Sentry.setTag(`isolation-scope-${id}`, id); - Sentry.setTag(`isolation-scope-transactionName`, `${Sentry.getIsolationScope().getScopeData().transactionName}`); + Sentry.setTag('isolation-scope-transactionName', `${Sentry.getIsolationScope().getScopeData().transactionName}`); Sentry.captureException(new Error('This is an exception'));