Skip to content

Commit 6038479

Browse files
committed
add test to express 5 version, fix tests
1 parent 5c33fe3 commit 6038479

4 files changed

Lines changed: 56 additions & 3 deletions

File tree

dev-packages/node-integration-tests/suites/express-v5/handle-error-scope-data-loss/server.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ app.get('/test/isolationScope', () => {
2525
throw new Error('isolation_test_error');
2626
});
2727

28+
app.get('/test/withIsolationScope', () => {
29+
Sentry.withIsolationScope(iScope => {
30+
iScope.setTag('with-isolation-scope', 'tag');
31+
throw new Error('with_isolation_scope_test_error');
32+
});
33+
});
34+
2835
Sentry.setupExpressErrorHandler(app);
2936

3037
startExpressServerAndSendPortToRunner(app);

dev-packages/node-integration-tests/suites/express-v5/handle-error-scope-data-loss/test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,49 @@ test('isolation scope is applied to thrown error caught by global handler', asyn
8686
runner.makeRequest('get', '/test/isolationScope', { expectError: true });
8787
await runner.completed();
8888
});
89+
90+
/**
91+
* This test shows that an inner isolation scope, created via `withIsolationScope`, is not applied to the error.
92+
*
93+
* This behaviour occurs because, just like in the test above where we use `getIsolationScope().setTag`,
94+
* this isolation scope again is only valid as long as we're in the callback.
95+
*
96+
* So why _does_ the http isolation scope get applied then? Because express' error handler applies on
97+
* a per-request basis, meaning, it's called while we're inside the isolation scope of the http request,
98+
* created from our `httpIntegration`.
99+
*/
100+
test('withIsolationScope scope is NOT applied to thrown error caught by global handler', async () => {
101+
const runner = createRunner(__dirname, 'server.ts')
102+
.expect({
103+
event: {
104+
exception: {
105+
values: [
106+
{
107+
mechanism: {
108+
type: 'middleware',
109+
handled: false,
110+
},
111+
type: 'Error',
112+
value: 'with_isolation_scope_test_error',
113+
stacktrace: {
114+
frames: expect.arrayContaining([
115+
expect.objectContaining({
116+
function: expect.any(String),
117+
lineno: expect.any(Number),
118+
colno: expect.any(Number),
119+
}),
120+
]),
121+
},
122+
},
123+
],
124+
},
125+
// 'with-isolation-scope' tag is not applied to the event
126+
tags: expect.not.objectContaining({ 'with-isolation-scope': expect.anything() }),
127+
},
128+
})
129+
.start();
130+
131+
runner.makeRequest('get', '/test/withIsolationScope', { expectError: true });
132+
133+
await runner.completed();
134+
});

dev-packages/node-integration-tests/suites/express/handle-error-scope-data-loss/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ app.get('/test/isolationScope', () => {
2828
app.get('/test/withIsolationScope', () => {
2929
Sentry.withIsolationScope(iScope => {
3030
iScope.setTag('with-isolation-scope', 'tag');
31-
throw new Error('isolation_test_error');
31+
throw new Error('with_isolation_scope_test_error');
3232
});
3333
});
3434

dev-packages/node-integration-tests/suites/express/handle-error-scope-data-loss/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ test('withIsolationScope scope is NOT applied to thrown error caught by global h
113113
handled: false,
114114
},
115115
type: 'Error',
116-
value: 'test_error',
116+
value: 'with_isolation_scope_test_error',
117117
stacktrace: {
118118
frames: expect.arrayContaining([
119119
expect.objectContaining({
@@ -132,7 +132,7 @@ test('withIsolationScope scope is NOT applied to thrown error caught by global h
132132
})
133133
.start();
134134

135-
runner.makeRequest('get', '/test/withScope', { expectError: true });
135+
runner.makeRequest('get', '/test/withIsolationScope', { expectError: true });
136136

137137
await runner.completed();
138138
});

0 commit comments

Comments
 (0)