From 9b5cf261700f774f3610e182f43f92edb20489d7 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Tue, 9 Jul 2024 12:26:03 +0200 Subject: [PATCH] fix(node): Ensure `autoSessionTracking` is enabled by default (#12790) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I noticed that we were not actually enabling auto session tracking correctly in node, because we did not check on the correct `options` object 😬 --- .../node-integration-tests/suites/anr/test.ts | 1 + .../suites/esm/warn-esm/test.ts | 6 +- .../handle-error-scope-data-loss/test.ts | 2 - .../handle-error-tracesSampleRate-0/test.ts | 2 +- .../test.ts | 2 +- .../suites/express/multiple-init/test.ts | 1 - .../common-infix-parameterized/test.ts | 2 +- .../multiple-routers/common-infix/test.ts | 2 +- .../test.ts | 2 +- .../common-prefix-parameterized/test.ts | 2 +- .../test.ts | 2 +- .../test.ts | 2 +- .../multiple-routers/common-prefix/test.ts | 2 +- .../multiple-routers/complex-router/test.ts | 6 +- .../middle-layer-parameterized/test.ts | 2 +- .../express/span-isolationScope/test.ts | 1 - .../suites/express/tracing/test.ts | 4 - .../suites/express/tracing/withError/test.ts | 2 +- .../suites/express/without-tracing/test.ts | 1 - .../suites/proxy/test.ts | 1 - .../suites/public-api/LocalVariables/test.ts | 19 +- .../crashed-session-aggregate/test.ts | 3 +- .../errored-session-aggregate/test.ts | 3 +- .../sessions/exited-session-aggregate/test.ts | 3 +- .../suites/tracing/connect/test.ts | 4 +- .../error-active-span-unsampled/test.ts | 2 +- .../envelope-header/error-active-span/test.ts | 2 +- .../tracing/envelope-header/error/test.ts | 1 - .../envelope-header/transaction-route/test.ts | 1 - .../envelope-header/transaction-url/test.ts | 1 - .../envelope-header/transaction/test.ts | 1 - .../suites/tracing/httpIntegration/test.ts | 2 - .../suites/tracing/maxSpans/test.ts | 1 - .../requests/fetch-breadcrumbs/test.ts | 1 - .../requests/fetch-noSampleRate/test.ts | 1 - .../fetch-sampled-no-active-span/test.ts | 1 - .../tracing/requests/fetch-unsampled/test.ts | 1 - .../tracing/requests/http-breadcrumbs/test.ts | 1 - .../requests/http-noSampleRate/test.ts | 1 - .../http-sampled-no-active-span/test.ts | 1 - .../tracing/requests/http-unsampled/test.ts | 1 - .../node-integration-tests/utils/runner.ts | 12 +- packages/node/src/sdk/index.ts | 8 +- .../node/test/integrations/express.test.ts | 2 +- packages/node/test/sdk/init.test.ts | 214 +++++++++++------- 45 files changed, 180 insertions(+), 152 deletions(-) diff --git a/dev-packages/node-integration-tests/suites/anr/test.ts b/dev-packages/node-integration-tests/suites/anr/test.ts index fcd9f121ed34..c3cb935532b1 100644 --- a/dev-packages/node-integration-tests/suites/anr/test.ts +++ b/dev-packages/node-integration-tests/suites/anr/test.ts @@ -110,6 +110,7 @@ conditionalTest({ min: 16 })('should report ANR when event loop blocked', () => test('With session', done => { createRunner(__dirname, 'basic-session.js') .withMockSentryServer() + .unignore('session') .expect({ session: { status: 'abnormal', diff --git a/dev-packages/node-integration-tests/suites/esm/warn-esm/test.ts b/dev-packages/node-integration-tests/suites/esm/warn-esm/test.ts index e52f8b915f86..25f90460e2b9 100644 --- a/dev-packages/node-integration-tests/suites/esm/warn-esm/test.ts +++ b/dev-packages/node-integration-tests/suites/esm/warn-esm/test.ts @@ -13,7 +13,7 @@ test("warns if using ESM on Node.js versions that don't support `register()`", a return; } - const runner = createRunner(__dirname, 'server.mjs').ignore('session', 'sessions', 'event').start(); + const runner = createRunner(__dirname, 'server.mjs').ignore('event').start(); await runner.makeRequest('get', '/test/success'); @@ -26,7 +26,7 @@ test('does not warn if using ESM on Node.js versions that support `register()`', return; } - const runner = createRunner(__dirname, 'server.mjs').ignore('session', 'sessions', 'event').start(); + const runner = createRunner(__dirname, 'server.mjs').ignore('event').start(); await runner.makeRequest('get', '/test/success'); @@ -34,7 +34,7 @@ test('does not warn if using ESM on Node.js versions that support `register()`', }); test('does not warn if using CJS', async () => { - const runner = createRunner(__dirname, 'server.js').ignore('session', 'sessions', 'event').start(); + const runner = createRunner(__dirname, 'server.js').ignore('event').start(); await runner.makeRequest('get', '/test/success'); diff --git a/dev-packages/node-integration-tests/suites/express/handle-error-scope-data-loss/test.ts b/dev-packages/node-integration-tests/suites/express/handle-error-scope-data-loss/test.ts index f1bb9a1229b1..ecf69671b9f4 100644 --- a/dev-packages/node-integration-tests/suites/express/handle-error-scope-data-loss/test.ts +++ b/dev-packages/node-integration-tests/suites/express/handle-error-scope-data-loss/test.ts @@ -15,7 +15,6 @@ afterAll(() => { */ test('withScope scope is NOT applied to thrown error caught by global handler', done => { const runner = createRunner(__dirname, 'server.ts') - .ignore('session', 'sessions') .expect({ event: { exception: { @@ -53,7 +52,6 @@ test('withScope scope is NOT applied to thrown error caught by global handler', */ test('isolation scope is applied to thrown error caught by global handler', done => { const runner = createRunner(__dirname, 'server.ts') - .ignore('session', 'sessions') .expect({ event: { exception: { diff --git a/dev-packages/node-integration-tests/suites/express/handle-error-tracesSampleRate-0/test.ts b/dev-packages/node-integration-tests/suites/express/handle-error-tracesSampleRate-0/test.ts index f76edf06bedb..955d725ae0c5 100644 --- a/dev-packages/node-integration-tests/suites/express/handle-error-tracesSampleRate-0/test.ts +++ b/dev-packages/node-integration-tests/suites/express/handle-error-tracesSampleRate-0/test.ts @@ -6,7 +6,7 @@ afterAll(() => { test('should capture and send Express controller error with txn name if tracesSampleRate is 0', done => { const runner = createRunner(__dirname, 'server.ts') - .ignore('session', 'sessions', 'transaction') + .ignore('transaction') .expect({ event: { exception: { diff --git a/dev-packages/node-integration-tests/suites/express/handle-error-tracesSampleRate-unset/test.ts b/dev-packages/node-integration-tests/suites/express/handle-error-tracesSampleRate-unset/test.ts index c48a3b1f9444..cb43073fa994 100644 --- a/dev-packages/node-integration-tests/suites/express/handle-error-tracesSampleRate-unset/test.ts +++ b/dev-packages/node-integration-tests/suites/express/handle-error-tracesSampleRate-unset/test.ts @@ -6,7 +6,7 @@ afterAll(() => { test('should capture and send Express controller error if tracesSampleRate is not set.', done => { const runner = createRunner(__dirname, 'server.ts') - .ignore('session', 'sessions', 'transaction') + .ignore('transaction') .expect({ event: { exception: { diff --git a/dev-packages/node-integration-tests/suites/express/multiple-init/test.ts b/dev-packages/node-integration-tests/suites/express/multiple-init/test.ts index 76f630128aa5..f654fc361442 100644 --- a/dev-packages/node-integration-tests/suites/express/multiple-init/test.ts +++ b/dev-packages/node-integration-tests/suites/express/multiple-init/test.ts @@ -6,7 +6,6 @@ afterAll(() => { test('allows to call init multiple times', done => { const runner = createRunner(__dirname, 'server.ts') - .ignore('session', 'sessions') .expect({ event: { exception: { diff --git a/dev-packages/node-integration-tests/suites/express/multiple-routers/common-infix-parameterized/test.ts b/dev-packages/node-integration-tests/suites/express/multiple-routers/common-infix-parameterized/test.ts index f7dc3a74cf2d..e7b9edabbfc8 100644 --- a/dev-packages/node-integration-tests/suites/express/multiple-routers/common-infix-parameterized/test.ts +++ b/dev-packages/node-integration-tests/suites/express/multiple-routers/common-infix-parameterized/test.ts @@ -6,7 +6,7 @@ afterAll(() => { test('should construct correct url with common infixes with multiple parameterized routers.', done => { createRunner(__dirname, 'server.ts') - .ignore('transaction', 'session', 'sessions') + .ignore('transaction') .expect({ event: { message: 'Custom Message', transaction: 'GET /api/v1/user/:userId' } }) .start(done) .makeRequest('get', '/api/v1/user/3212'); diff --git a/dev-packages/node-integration-tests/suites/express/multiple-routers/common-infix/test.ts b/dev-packages/node-integration-tests/suites/express/multiple-routers/common-infix/test.ts index 2a38c4c8838a..52d6b631bea2 100644 --- a/dev-packages/node-integration-tests/suites/express/multiple-routers/common-infix/test.ts +++ b/dev-packages/node-integration-tests/suites/express/multiple-routers/common-infix/test.ts @@ -6,7 +6,7 @@ afterAll(() => { test('should construct correct url with common infixes with multiple routers.', done => { createRunner(__dirname, 'server.ts') - .ignore('transaction', 'session', 'sessions') + .ignore('transaction') .expect({ event: { message: 'Custom Message', transaction: 'GET /api2/v1/test' } }) .start(done) .makeRequest('get', '/api2/v1/test'); diff --git a/dev-packages/node-integration-tests/suites/express/multiple-routers/common-prefix-parameterized-reverse/test.ts b/dev-packages/node-integration-tests/suites/express/multiple-routers/common-prefix-parameterized-reverse/test.ts index d5a839d739b0..5fabe5b92df6 100644 --- a/dev-packages/node-integration-tests/suites/express/multiple-routers/common-prefix-parameterized-reverse/test.ts +++ b/dev-packages/node-integration-tests/suites/express/multiple-routers/common-prefix-parameterized-reverse/test.ts @@ -6,7 +6,7 @@ afterAll(() => { test('should construct correct urls with multiple parameterized routers (use order reversed).', done => { createRunner(__dirname, 'server.ts') - .ignore('transaction', 'session', 'sessions') + .ignore('transaction') .expect({ event: { message: 'Custom Message', transaction: 'GET /api/v1/user/:userId' } }) .start(done) .makeRequest('get', '/api/v1/user/1234/'); diff --git a/dev-packages/node-integration-tests/suites/express/multiple-routers/common-prefix-parameterized/test.ts b/dev-packages/node-integration-tests/suites/express/multiple-routers/common-prefix-parameterized/test.ts index fbe805e39bc1..bab934f54522 100644 --- a/dev-packages/node-integration-tests/suites/express/multiple-routers/common-prefix-parameterized/test.ts +++ b/dev-packages/node-integration-tests/suites/express/multiple-routers/common-prefix-parameterized/test.ts @@ -6,7 +6,7 @@ afterAll(() => { test('should construct correct urls with multiple parameterized routers.', done => { createRunner(__dirname, 'server.ts') - .ignore('transaction', 'session', 'sessions') + .ignore('transaction') .expect({ event: { message: 'Custom Message', transaction: 'GET /api/v1/user/:userId' } }) .start(done) .makeRequest('get', '/api/v1/user/1234/'); diff --git a/dev-packages/node-integration-tests/suites/express/multiple-routers/common-prefix-same-length-parameterized copy/test.ts b/dev-packages/node-integration-tests/suites/express/multiple-routers/common-prefix-same-length-parameterized copy/test.ts index e97ff2edeced..94d363f4faa4 100644 --- a/dev-packages/node-integration-tests/suites/express/multiple-routers/common-prefix-same-length-parameterized copy/test.ts +++ b/dev-packages/node-integration-tests/suites/express/multiple-routers/common-prefix-same-length-parameterized copy/test.ts @@ -6,7 +6,7 @@ afterAll(() => { test('should construct correct url with multiple parameterized routers of the same length (use order reversed).', done => { createRunner(__dirname, 'server.ts') - .ignore('transaction', 'session', 'sessions') + .ignore('transaction') .expect({ event: { message: 'Custom Message', transaction: 'GET /api/v1/:userId' } }) .start(done) .makeRequest('get', '/api/v1/1234/'); diff --git a/dev-packages/node-integration-tests/suites/express/multiple-routers/common-prefix-same-length-parameterized/test.ts b/dev-packages/node-integration-tests/suites/express/multiple-routers/common-prefix-same-length-parameterized/test.ts index e1bc0c9ffd3b..373b2c102c4c 100644 --- a/dev-packages/node-integration-tests/suites/express/multiple-routers/common-prefix-same-length-parameterized/test.ts +++ b/dev-packages/node-integration-tests/suites/express/multiple-routers/common-prefix-same-length-parameterized/test.ts @@ -6,7 +6,7 @@ afterAll(() => { test('should construct correct url with multiple parameterized routers of the same length.', done => { createRunner(__dirname, 'server.ts') - .ignore('transaction', 'session', 'sessions') + .ignore('transaction') .expect({ event: { message: 'Custom Message', transaction: 'GET /api/v1/:userId' } }) .start(done) .makeRequest('get', '/api/v1/1234/'); diff --git a/dev-packages/node-integration-tests/suites/express/multiple-routers/common-prefix/test.ts b/dev-packages/node-integration-tests/suites/express/multiple-routers/common-prefix/test.ts index 6ae3ddd6e0d5..ea217bf6bc05 100644 --- a/dev-packages/node-integration-tests/suites/express/multiple-routers/common-prefix/test.ts +++ b/dev-packages/node-integration-tests/suites/express/multiple-routers/common-prefix/test.ts @@ -6,7 +6,7 @@ afterAll(() => { test('should construct correct urls with multiple routers.', done => { createRunner(__dirname, 'server.ts') - .ignore('transaction', 'session', 'sessions') + .ignore('transaction') .expect({ event: { message: 'Custom Message', transaction: 'GET /api/v1/test' } }) .start(done) .makeRequest('get', '/api/v1/test'); diff --git a/dev-packages/node-integration-tests/suites/express/multiple-routers/complex-router/test.ts b/dev-packages/node-integration-tests/suites/express/multiple-routers/complex-router/test.ts index a544095982c7..606120248e35 100644 --- a/dev-packages/node-integration-tests/suites/express/multiple-routers/complex-router/test.ts +++ b/dev-packages/node-integration-tests/suites/express/multiple-routers/complex-router/test.ts @@ -28,7 +28,7 @@ conditionalTest({ min: 16 })('complex-router', () => { }; createRunner(__dirname, 'server.ts') - .ignore('event', 'session', 'sessions') + .ignore('event') .expect({ transaction: EXPECTED_TRANSACTION as any }) .start(done) .makeRequest('get', '/api/api/v1/sub-router/users/123/posts/456'); @@ -54,7 +54,7 @@ conditionalTest({ min: 16 })('complex-router', () => { }; createRunner(__dirname, 'server.ts') - .ignore('event', 'session', 'sessions') + .ignore('event') .expect({ transaction: EXPECTED_TRANSACTION as any }) .start(done) .makeRequest('get', '/api/api/v1/sub-router/users/123/posts/456?param=1'); @@ -80,7 +80,7 @@ conditionalTest({ min: 16 })('complex-router', () => { }; createRunner(__dirname, 'server.ts') - .ignore('event', 'session', 'sessions') + .ignore('event') .expect({ transaction: EXPECTED_TRANSACTION as any }) .start(done) .makeRequest('get', '/api/api/v1/sub-router/users/123/posts/456/?param=1'); diff --git a/dev-packages/node-integration-tests/suites/express/multiple-routers/middle-layer-parameterized/test.ts b/dev-packages/node-integration-tests/suites/express/multiple-routers/middle-layer-parameterized/test.ts index f6548ed161b9..4a6ae304af14 100644 --- a/dev-packages/node-integration-tests/suites/express/multiple-routers/middle-layer-parameterized/test.ts +++ b/dev-packages/node-integration-tests/suites/express/multiple-routers/middle-layer-parameterized/test.ts @@ -27,7 +27,7 @@ conditionalTest({ min: 16 })('middle-layer-parameterized', () => { }; createRunner(__dirname, 'server.ts') - .ignore('event', 'session', 'sessions') + .ignore('event') .expect({ transaction: EXPECTED_TRANSACTION as any }) .start(done) .makeRequest('get', '/api/v1/users/123/posts/456'); diff --git a/dev-packages/node-integration-tests/suites/express/span-isolationScope/test.ts b/dev-packages/node-integration-tests/suites/express/span-isolationScope/test.ts index b6954e426a1d..2e2b6945526e 100644 --- a/dev-packages/node-integration-tests/suites/express/span-isolationScope/test.ts +++ b/dev-packages/node-integration-tests/suites/express/span-isolationScope/test.ts @@ -6,7 +6,6 @@ afterAll(() => { test('correctly applies isolation scope to span', done => { createRunner(__dirname, 'server.ts') - .ignore('session', 'sessions') .expect({ transaction: { transaction: 'GET /test/isolationScope', diff --git a/dev-packages/node-integration-tests/suites/express/tracing/test.ts b/dev-packages/node-integration-tests/suites/express/tracing/test.ts index e590520838c2..44852233ed67 100644 --- a/dev-packages/node-integration-tests/suites/express/tracing/test.ts +++ b/dev-packages/node-integration-tests/suites/express/tracing/test.ts @@ -8,7 +8,6 @@ describe('express tracing', () => { describe('CJS', () => { test('should create and send transactions for Express routes and spans for middlewares.', done => { createRunner(__dirname, 'server.js') - .ignore('session', 'sessions') .expect({ transaction: { contexts: { @@ -51,7 +50,6 @@ describe('express tracing', () => { test('should set a correct transaction name for routes specified in RegEx', done => { createRunner(__dirname, 'server.js') - .ignore('session', 'sessions') .expect({ transaction: { transaction: 'GET /\\/test\\/regex/', @@ -80,7 +78,6 @@ describe('express tracing', () => { 'should set a correct transaction name for routes consisting of arrays of routes for %p', ((segment: string, done: () => void) => { createRunner(__dirname, 'server.js') - .ignore('session', 'sessions') .expect({ transaction: { transaction: 'GET /test/array1,/\\/test\\/array[2-9]/', @@ -117,7 +114,6 @@ describe('express tracing', () => { ['arr/requiredPath/optionalPath/lastParam'], ])('should handle more complex regexes in route arrays correctly for %p', ((segment: string, done: () => void) => { createRunner(__dirname, 'server.js') - .ignore('session', 'sessions') .expect({ transaction: { transaction: 'GET /test/arr/:id,/\\/test\\/arr[0-9]*\\/required(path)?(\\/optionalPath)?\\/(lastParam)?/', diff --git a/dev-packages/node-integration-tests/suites/express/tracing/withError/test.ts b/dev-packages/node-integration-tests/suites/express/tracing/withError/test.ts index f164bdd0caab..4dd004ad2239 100644 --- a/dev-packages/node-integration-tests/suites/express/tracing/withError/test.ts +++ b/dev-packages/node-integration-tests/suites/express/tracing/withError/test.ts @@ -8,7 +8,7 @@ describe('express tracing experimental', () => { describe('CJS', () => { test('should apply the scope transactionName to error events', done => { createRunner(__dirname, 'server.js') - .ignore('session', 'sessions', 'transaction') + .ignore('transaction') .expect({ event: { exception: { 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 73d6a322ed28..236c978dcd9a 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 @@ -6,7 +6,6 @@ afterAll(() => { test('correctly applies isolation scope even without tracing', done => { const runner = createRunner(__dirname, 'server.ts') - .ignore('session', 'sessions') .expect({ event: { transaction: 'GET /test/isolationScope/1', diff --git a/dev-packages/node-integration-tests/suites/proxy/test.ts b/dev-packages/node-integration-tests/suites/proxy/test.ts index dc709f5251c6..cc2fc0b83404 100644 --- a/dev-packages/node-integration-tests/suites/proxy/test.ts +++ b/dev-packages/node-integration-tests/suites/proxy/test.ts @@ -7,7 +7,6 @@ afterAll(() => { test('proxies sentry requests', done => { createRunner(__dirname, 'basic.js') .withMockSentryServer() - .ignore('session') .expect({ event: { message: 'Hello, via proxy!', diff --git a/dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts b/dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts index c63fe2daf5df..7076388b9d29 100644 --- a/dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts +++ b/dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts @@ -41,7 +41,6 @@ conditionalTest({ min: 18 })('LocalVariables integration', () => { test('Should not include local variables by default', done => { createRunner(__dirname, 'no-local-variables.js') - .ignore('session') .expect({ event: event => { for (const frame of event.exception?.values?.[0]?.stacktrace?.frames || []) { @@ -53,10 +52,7 @@ conditionalTest({ min: 18 })('LocalVariables integration', () => { }); test('Should include local variables when enabled', done => { - createRunner(__dirname, 'local-variables.js') - .ignore('session') - .expect({ event: EXPECTED_LOCAL_VARIABLES_EVENT }) - .start(done); + createRunner(__dirname, 'local-variables.js').expect({ event: EXPECTED_LOCAL_VARIABLES_EVENT }).start(done); }); test('Should include local variables when instrumenting via --require', done => { @@ -64,29 +60,22 @@ conditionalTest({ min: 18 })('LocalVariables integration', () => { createRunner(__dirname, 'local-variables-no-sentry.js') .withFlags(`--require=${requirePath}`) - .ignore('session') .expect({ event: EXPECTED_LOCAL_VARIABLES_EVENT }) .start(done); }); test('Should include local variables with ESM', done => { - createRunner(__dirname, 'local-variables-caught.mjs') - .ignore('session') - .expect({ event: EXPECTED_LOCAL_VARIABLES_EVENT }) - .start(done); + createRunner(__dirname, 'local-variables-caught.mjs').expect({ event: EXPECTED_LOCAL_VARIABLES_EVENT }).start(done); }); conditionalTest({ min: 19 })('Node v19+', () => { test('Should not import inspector when not in use', done => { - createRunner(__dirname, 'deny-inspector.mjs').ensureNoErrorOutput().ignore('session').start(done); + createRunner(__dirname, 'deny-inspector.mjs').ensureNoErrorOutput().start(done); }); }); test('Includes local variables for caught exceptions when enabled', done => { - createRunner(__dirname, 'local-variables-caught.js') - .ignore('session') - .expect({ event: EXPECTED_LOCAL_VARIABLES_EVENT }) - .start(done); + createRunner(__dirname, 'local-variables-caught.js').expect({ event: EXPECTED_LOCAL_VARIABLES_EVENT }).start(done); }); test('Should not leak memory', done => { diff --git a/dev-packages/node-integration-tests/suites/sessions/crashed-session-aggregate/test.ts b/dev-packages/node-integration-tests/suites/sessions/crashed-session-aggregate/test.ts index a94d7c46dba0..6e8a86e627d9 100644 --- a/dev-packages/node-integration-tests/suites/sessions/crashed-session-aggregate/test.ts +++ b/dev-packages/node-integration-tests/suites/sessions/crashed-session-aggregate/test.ts @@ -11,7 +11,8 @@ test('should aggregate successful and crashed sessions', async () => { }); const runner = createRunner(__dirname, 'server.ts') - .ignore('transaction', 'event', 'session') + .ignore('transaction', 'event') + .unignore('sessions') .expectError() .expect({ sessions: { diff --git a/dev-packages/node-integration-tests/suites/sessions/errored-session-aggregate/test.ts b/dev-packages/node-integration-tests/suites/sessions/errored-session-aggregate/test.ts index da9733690507..383bfca96062 100644 --- a/dev-packages/node-integration-tests/suites/sessions/errored-session-aggregate/test.ts +++ b/dev-packages/node-integration-tests/suites/sessions/errored-session-aggregate/test.ts @@ -11,7 +11,8 @@ test('should aggregate successful, crashed and erroneous sessions', async () => }); const runner = createRunner(__dirname, 'server.ts') - .ignore('transaction', 'event', 'session') + .ignore('transaction', 'event') + .unignore('sessions') .expectError() .expect({ sessions: { diff --git a/dev-packages/node-integration-tests/suites/sessions/exited-session-aggregate/test.ts b/dev-packages/node-integration-tests/suites/sessions/exited-session-aggregate/test.ts index ba42536a3bbf..23b80109fa43 100644 --- a/dev-packages/node-integration-tests/suites/sessions/exited-session-aggregate/test.ts +++ b/dev-packages/node-integration-tests/suites/sessions/exited-session-aggregate/test.ts @@ -11,7 +11,8 @@ test('should aggregate successful sessions', async () => { }); const runner = createRunner(__dirname, 'server.ts') - .ignore('transaction', 'event', 'session') + .ignore('transaction', 'event') + .unignore('sessions') .expectError() .expect({ sessions: { diff --git a/dev-packages/node-integration-tests/suites/tracing/connect/test.ts b/dev-packages/node-integration-tests/suites/tracing/connect/test.ts index 08e96e691c6f..e343e6edf6fd 100644 --- a/dev-packages/node-integration-tests/suites/tracing/connect/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/connect/test.ts @@ -47,7 +47,7 @@ describe('connect auto-instrumentation', () => { test('CJS - should capture errors in `connect` middleware.', done => { createRunner(__dirname, 'scenario.js') - .ignore('transaction', 'session', 'sessions') + .ignore('transaction') .expectError() .expect({ event: EXPECTED_EVENT }) .start(done) @@ -56,7 +56,7 @@ describe('connect auto-instrumentation', () => { test('CJS - should report errored transactions.', done => { createRunner(__dirname, 'scenario.js') - .ignore('event', 'session', 'sessions') + .ignore('event') .expect({ transaction: { transaction: 'GET /error' } }) .expectError() .start(done) diff --git a/dev-packages/node-integration-tests/suites/tracing/envelope-header/error-active-span-unsampled/test.ts b/dev-packages/node-integration-tests/suites/tracing/envelope-header/error-active-span-unsampled/test.ts index b4d971654ea0..c962bc36800d 100644 --- a/dev-packages/node-integration-tests/suites/tracing/envelope-header/error-active-span-unsampled/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/envelope-header/error-active-span-unsampled/test.ts @@ -2,7 +2,7 @@ import { createRunner } from '../../../../utils/runner'; test('envelope header for error event during active unsampled span is correct', done => { createRunner(__dirname, 'scenario.ts') - .ignore('session', 'sessions', 'transaction') + .ignore('transaction') .expectHeader({ event: { trace: { diff --git a/dev-packages/node-integration-tests/suites/tracing/envelope-header/error-active-span/test.ts b/dev-packages/node-integration-tests/suites/tracing/envelope-header/error-active-span/test.ts index 0e425ac58d55..f81364dec824 100644 --- a/dev-packages/node-integration-tests/suites/tracing/envelope-header/error-active-span/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/envelope-header/error-active-span/test.ts @@ -2,7 +2,7 @@ import { createRunner } from '../../../../utils/runner'; test('envelope header for error event during active span is correct', done => { createRunner(__dirname, 'scenario.ts') - .ignore('session', 'sessions', 'transaction') + .ignore('transaction') .expectHeader({ event: { trace: { diff --git a/dev-packages/node-integration-tests/suites/tracing/envelope-header/error/test.ts b/dev-packages/node-integration-tests/suites/tracing/envelope-header/error/test.ts index e45e18baa29a..87229650bfb4 100644 --- a/dev-packages/node-integration-tests/suites/tracing/envelope-header/error/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/envelope-header/error/test.ts @@ -2,7 +2,6 @@ import { createRunner } from '../../../../utils/runner'; test('envelope header for error events is correct', done => { createRunner(__dirname, 'scenario.ts') - .ignore('session', 'sessions') .expectHeader({ event: { trace: { diff --git a/dev-packages/node-integration-tests/suites/tracing/envelope-header/transaction-route/test.ts b/dev-packages/node-integration-tests/suites/tracing/envelope-header/transaction-route/test.ts index b64ef4ff55ed..a9d7a3ac04e8 100644 --- a/dev-packages/node-integration-tests/suites/tracing/envelope-header/transaction-route/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/envelope-header/transaction-route/test.ts @@ -2,7 +2,6 @@ import { createRunner } from '../../../../utils/runner'; test('envelope header for transaction event of route correct', done => { createRunner(__dirname, 'scenario.ts') - .ignore('session', 'sessions') .expectHeader({ transaction: { trace: { diff --git a/dev-packages/node-integration-tests/suites/tracing/envelope-header/transaction-url/test.ts b/dev-packages/node-integration-tests/suites/tracing/envelope-header/transaction-url/test.ts index 80f187165614..2656835cd98d 100644 --- a/dev-packages/node-integration-tests/suites/tracing/envelope-header/transaction-url/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/envelope-header/transaction-url/test.ts @@ -2,7 +2,6 @@ import { createRunner } from '../../../../utils/runner'; test('envelope header for transaction event with source=url correct', done => { createRunner(__dirname, 'scenario.ts') - .ignore('session', 'sessions') .expectHeader({ transaction: { trace: { diff --git a/dev-packages/node-integration-tests/suites/tracing/envelope-header/transaction/test.ts b/dev-packages/node-integration-tests/suites/tracing/envelope-header/transaction/test.ts index 10ef348dfaf0..436c7d7adf2e 100644 --- a/dev-packages/node-integration-tests/suites/tracing/envelope-header/transaction/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/envelope-header/transaction/test.ts @@ -2,7 +2,6 @@ import { createRunner } from '../../../../utils/runner'; test('envelope header for transaction event is correct', done => { createRunner(__dirname, 'scenario.ts') - .ignore('session', 'sessions') .expectHeader({ transaction: { trace: { diff --git a/dev-packages/node-integration-tests/suites/tracing/httpIntegration/test.ts b/dev-packages/node-integration-tests/suites/tracing/httpIntegration/test.ts index 69551480ef25..6be5d36e2ee3 100644 --- a/dev-packages/node-integration-tests/suites/tracing/httpIntegration/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/httpIntegration/test.ts @@ -14,7 +14,6 @@ describe('httpIntegration', () => { } createRunner(__dirname, 'server.js') - .ignore('session', 'sessions') .expect({ transaction: { contexts: { @@ -56,7 +55,6 @@ describe('httpIntegration', () => { test('allows to pass experimental config through to integration', done => { createRunner(__dirname, 'server-experimental.js') - .ignore('session', 'sessions') .expect({ transaction: { contexts: { diff --git a/dev-packages/node-integration-tests/suites/tracing/maxSpans/test.ts b/dev-packages/node-integration-tests/suites/tracing/maxSpans/test.ts index 9bc623b12200..2554a9b790b6 100644 --- a/dev-packages/node-integration-tests/suites/tracing/maxSpans/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/maxSpans/test.ts @@ -8,7 +8,6 @@ test('it limits spans to 1000', done => { } createRunner(__dirname, 'scenario.ts') - .ignore('session', 'sessions') .expect({ transaction: { transaction: 'parent', diff --git a/dev-packages/node-integration-tests/suites/tracing/requests/fetch-breadcrumbs/test.ts b/dev-packages/node-integration-tests/suites/tracing/requests/fetch-breadcrumbs/test.ts index f410f8209110..2c238c9ecd15 100644 --- a/dev-packages/node-integration-tests/suites/tracing/requests/fetch-breadcrumbs/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/requests/fetch-breadcrumbs/test.ts @@ -10,7 +10,6 @@ conditionalTest({ min: 18 })('outgoing fetch', () => { createRunner(__dirname, 'scenario.ts') .withEnv({ SERVER_URL }) .ensureNoErrorOutput() - .ignore('session', 'sessions') .expect({ event: { breadcrumbs: [ diff --git a/dev-packages/node-integration-tests/suites/tracing/requests/fetch-noSampleRate/test.ts b/dev-packages/node-integration-tests/suites/tracing/requests/fetch-noSampleRate/test.ts index 2de3dcfea66b..f69f4f54c56d 100644 --- a/dev-packages/node-integration-tests/suites/tracing/requests/fetch-noSampleRate/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/requests/fetch-noSampleRate/test.ts @@ -34,7 +34,6 @@ conditionalTest({ min: 18 })('outgoing fetch', () => { createRunner(__dirname, 'scenario.ts') .withEnv({ SERVER_URL }) .ensureNoErrorOutput() - .ignore('session', 'sessions') .expect({ event: { exception: { diff --git a/dev-packages/node-integration-tests/suites/tracing/requests/fetch-sampled-no-active-span/test.ts b/dev-packages/node-integration-tests/suites/tracing/requests/fetch-sampled-no-active-span/test.ts index 40e14fe648f8..8b9ff1486565 100644 --- a/dev-packages/node-integration-tests/suites/tracing/requests/fetch-sampled-no-active-span/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/requests/fetch-sampled-no-active-span/test.ts @@ -29,7 +29,6 @@ conditionalTest({ min: 18 })('outgoing fetch', () => { .then(SERVER_URL => { createRunner(__dirname, 'scenario.ts') .withEnv({ SERVER_URL }) - .ignore('session', 'sessions') .expect({ event: { exception: { diff --git a/dev-packages/node-integration-tests/suites/tracing/requests/fetch-unsampled/test.ts b/dev-packages/node-integration-tests/suites/tracing/requests/fetch-unsampled/test.ts index 0b0ceeaa499c..016881f47399 100644 --- a/dev-packages/node-integration-tests/suites/tracing/requests/fetch-unsampled/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/requests/fetch-unsampled/test.ts @@ -29,7 +29,6 @@ conditionalTest({ min: 18 })('outgoing fetch', () => { .then(SERVER_URL => { createRunner(__dirname, 'scenario.ts') .withEnv({ SERVER_URL }) - .ignore('session', 'sessions') .expect({ event: { exception: { diff --git a/dev-packages/node-integration-tests/suites/tracing/requests/http-breadcrumbs/test.ts b/dev-packages/node-integration-tests/suites/tracing/requests/http-breadcrumbs/test.ts index e6f44c7953f8..aab8338d0a35 100644 --- a/dev-packages/node-integration-tests/suites/tracing/requests/http-breadcrumbs/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/requests/http-breadcrumbs/test.ts @@ -8,7 +8,6 @@ test('outgoing http requests create breadcrumbs', done => { createRunner(__dirname, 'scenario.ts') .withEnv({ SERVER_URL }) .ensureNoErrorOutput() - .ignore('session', 'sessions') .expect({ event: { breadcrumbs: [ diff --git a/dev-packages/node-integration-tests/suites/tracing/requests/http-noSampleRate/test.ts b/dev-packages/node-integration-tests/suites/tracing/requests/http-noSampleRate/test.ts index 570d9f4865a6..b6766442683e 100644 --- a/dev-packages/node-integration-tests/suites/tracing/requests/http-noSampleRate/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/requests/http-noSampleRate/test.ts @@ -32,7 +32,6 @@ test('outgoing http requests are correctly instrumented without tracesSampleRate createRunner(__dirname, 'scenario.ts') .withEnv({ SERVER_URL }) .ensureNoErrorOutput() - .ignore('session', 'sessions') .expect({ event: { exception: { diff --git a/dev-packages/node-integration-tests/suites/tracing/requests/http-sampled-no-active-span/test.ts b/dev-packages/node-integration-tests/suites/tracing/requests/http-sampled-no-active-span/test.ts index ee0151cd6297..9f18f050b929 100644 --- a/dev-packages/node-integration-tests/suites/tracing/requests/http-sampled-no-active-span/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/requests/http-sampled-no-active-span/test.ts @@ -31,7 +31,6 @@ test('outgoing sampled http requests without active span are correctly instrumen .then(SERVER_URL => { createRunner(__dirname, 'scenario.ts') .withEnv({ SERVER_URL }) - .ignore('session', 'sessions') .expect({ event: { exception: { diff --git a/dev-packages/node-integration-tests/suites/tracing/requests/http-unsampled/test.ts b/dev-packages/node-integration-tests/suites/tracing/requests/http-unsampled/test.ts index c860958622fa..be4a2f542875 100644 --- a/dev-packages/node-integration-tests/suites/tracing/requests/http-unsampled/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/requests/http-unsampled/test.ts @@ -31,7 +31,6 @@ test('outgoing http requests are correctly instrumented when not sampled', done .then(SERVER_URL => { createRunner(__dirname, 'scenario.ts') .withEnv({ SERVER_URL }) - .ignore('session', 'sessions') .expect({ event: { exception: { diff --git a/dev-packages/node-integration-tests/utils/runner.ts b/dev-packages/node-integration-tests/utils/runner.ts index 9d0eb8a64b25..6e663cd13d75 100644 --- a/dev-packages/node-integration-tests/utils/runner.ts +++ b/dev-packages/node-integration-tests/utils/runner.ts @@ -164,7 +164,8 @@ export function createRunner(...paths: string[]) { const expectedEnvelopes: Expected[] = []; let expectedEnvelopeHeaders: ExpectedEnvelopeHeader[] | undefined = undefined; const flags: string[] = []; - const ignored: EnvelopeItemType[] = []; + // By default, we ignore session & sessions + const ignored: EnvelopeItemType[] = ['session', 'sessions']; let withEnv: Record = {}; let withSentryServer = false; let dockerOptions: DockerOptions | undefined; @@ -209,6 +210,15 @@ export function createRunner(...paths: string[]) { ignored.push(...types); return this; }, + unignore: function (...types: EnvelopeItemType[]) { + for (const t of types) { + const pos = ignored.indexOf(t); + if (pos > -1) { + ignored.splice(pos, 1); + } + } + return this; + }, withDockerCompose: function (options: DockerOptions) { dockerOptions = options; return this; diff --git a/packages/node/src/sdk/index.ts b/packages/node/src/sdk/index.ts index 4c30ba2bd2cf..2ac62a2b5b91 100644 --- a/packages/node/src/sdk/index.ts +++ b/packages/node/src/sdk/index.ts @@ -113,12 +113,12 @@ export function initWithoutDefaultIntegrations(options: NodeOptions | undefined * Initialize Sentry for Node, without performance instrumentation. */ function _init( - options: NodeOptions | undefined = {}, + _options: NodeOptions | undefined = {}, getDefaultIntegrationsImpl: (options: Options) => Integration[], ): NodeClient { - const clientOptions = getClientOptions(options, getDefaultIntegrationsImpl); + const options = getClientOptions(_options, getDefaultIntegrationsImpl); - if (clientOptions.debug === true) { + if (options.debug === true) { if (DEBUG_BUILD) { logger.enable(); } else { @@ -139,7 +139,7 @@ function _init( const scope = getCurrentScope(); scope.update(options.initialScope); - const client = new NodeClient(clientOptions); + const client = new NodeClient(options); // The client is on the current scope, from where it generally is inherited getCurrentScope().setClient(client); diff --git a/packages/node/test/integrations/express.test.ts b/packages/node/test/integrations/express.test.ts index 592ab7677db0..3071dce968d5 100644 --- a/packages/node/test/integrations/express.test.ts +++ b/packages/node/test/integrations/express.test.ts @@ -74,7 +74,7 @@ describe('expressErrorHandler()', () => { }); it('autoSessionTracking is enabled + requestHandler is not used -> does not set requestSession status on Crash', done => { - const options = getDefaultNodeClientOptions({ autoSessionTracking: false, release: '3.3' }); + const options = getDefaultNodeClientOptions({ autoSessionTracking: true, release: '3.3' }); client = new NodeClient(options); setCurrentClient(client); diff --git a/packages/node/test/sdk/init.test.ts b/packages/node/test/sdk/init.test.ts index 235cb8d23b86..49246f4284ae 100644 --- a/packages/node/test/sdk/init.test.ts +++ b/packages/node/test/sdk/init.test.ts @@ -1,6 +1,6 @@ import type { Integration } from '@sentry/types'; -import { getClient } from '../../src/'; +import { getClient, getIsolationScope } from '../../src/'; import * as auto from '../../src/integrations/tracing'; import { init } from '../../src/sdk'; import { NodeClient } from '../../src/sdk/client'; @@ -34,112 +34,162 @@ describe('init()', () => { jest.clearAllMocks(); }); - it("doesn't install default integrations if told not to", () => { - init({ dsn: PUBLIC_DSN, defaultIntegrations: false }); + describe('integrations', () => { + it("doesn't install default integrations if told not to", () => { + init({ dsn: PUBLIC_DSN, defaultIntegrations: false }); - const client = getClient(); + const client = getClient(); - expect(client?.getOptions()).toEqual( - expect.objectContaining({ - integrations: [], - }), - ); + expect(client?.getOptions()).toEqual( + expect.objectContaining({ + integrations: [], + }), + ); - expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(0); - }); + expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(0); + }); - it('installs merged default integrations, with overrides provided through options', () => { - const mockDefaultIntegrations = [ - new MockIntegration('Some mock integration 2.1'), - new MockIntegration('Some mock integration 2.2'), - ]; + it('installs merged default integrations, with overrides provided through options', () => { + const mockDefaultIntegrations = [ + new MockIntegration('Some mock integration 2.1'), + new MockIntegration('Some mock integration 2.2'), + ]; - const mockIntegrations = [ - new MockIntegration('Some mock integration 2.1'), - new MockIntegration('Some mock integration 2.3'), - ]; + const mockIntegrations = [ + new MockIntegration('Some mock integration 2.1'), + new MockIntegration('Some mock integration 2.3'), + ]; - init({ dsn: PUBLIC_DSN, integrations: mockIntegrations, defaultIntegrations: mockDefaultIntegrations }); + init({ dsn: PUBLIC_DSN, integrations: mockIntegrations, defaultIntegrations: mockDefaultIntegrations }); - expect(mockDefaultIntegrations[0]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(0); - expect(mockDefaultIntegrations[1]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); - expect(mockIntegrations[0]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); - expect(mockIntegrations[1]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); - expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(0); - }); + expect(mockDefaultIntegrations[0]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(0); + expect(mockDefaultIntegrations[1]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); + expect(mockIntegrations[0]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); + expect(mockIntegrations[1]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); + expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(0); + }); - it('installs integrations returned from a callback function', () => { - const mockDefaultIntegrations = [ - new MockIntegration('Some mock integration 3.1'), - new MockIntegration('Some mock integration 3.2'), - ]; - - const newIntegration = new MockIntegration('Some mock integration 3.3'); - - init({ - dsn: PUBLIC_DSN, - defaultIntegrations: mockDefaultIntegrations, - integrations: integrations => { - const newIntegrations = [...integrations]; - newIntegrations[1] = newIntegration; - return newIntegrations; - }, + it('installs integrations returned from a callback function', () => { + const mockDefaultIntegrations = [ + new MockIntegration('Some mock integration 3.1'), + new MockIntegration('Some mock integration 3.2'), + ]; + + const newIntegration = new MockIntegration('Some mock integration 3.3'); + + init({ + dsn: PUBLIC_DSN, + defaultIntegrations: mockDefaultIntegrations, + integrations: integrations => { + const newIntegrations = [...integrations]; + newIntegrations[1] = newIntegration; + return newIntegrations; + }, + }); + + expect(mockDefaultIntegrations[0]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); + expect(mockDefaultIntegrations[1]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(0); + expect(newIntegration.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); + expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(0); }); - expect(mockDefaultIntegrations[0]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); - expect(mockDefaultIntegrations[1]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(0); - expect(newIntegration.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); - expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(0); + it('installs performance default instrumentations if tracing is enabled', () => { + const autoPerformanceIntegration = new MockIntegration('Some mock integration 4.4'); + + mockAutoPerformanceIntegrations.mockReset().mockImplementation(() => [autoPerformanceIntegration]); + + const mockIntegrations = [ + new MockIntegration('Some mock integration 4.1'), + new MockIntegration('Some mock integration 4.3'), + ]; + + init({ + dsn: PUBLIC_DSN, + integrations: mockIntegrations, + enableTracing: true, + }); + + expect(mockIntegrations[0]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); + expect(mockIntegrations[1]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); + expect(autoPerformanceIntegration.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); + expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(1); + + const client = getClient(); + expect(client?.getOptions()).toEqual( + expect.objectContaining({ + integrations: expect.arrayContaining([mockIntegrations[0], mockIntegrations[1], autoPerformanceIntegration]), + }), + ); + }); }); - it('installs performance default instrumentations if tracing is enabled', () => { - const autoPerformanceIntegration = new MockIntegration('Some mock integration 4.4'); + describe('OpenTelemetry', () => { + it('sets up OpenTelemetry by default', () => { + init({ dsn: PUBLIC_DSN }); + + const client = getClient(); - mockAutoPerformanceIntegrations.mockReset().mockImplementation(() => [autoPerformanceIntegration]); + expect(client?.traceProvider).toBeDefined(); + }); - const mockIntegrations = [ - new MockIntegration('Some mock integration 4.1'), - new MockIntegration('Some mock integration 4.3'), - ]; + it('allows to opt-out of OpenTelemetry setup', () => { + init({ dsn: PUBLIC_DSN, skipOpenTelemetrySetup: true }); - init({ - dsn: PUBLIC_DSN, - integrations: mockIntegrations, - enableTracing: true, + const client = getClient(); + + expect(client?.traceProvider).not.toBeDefined(); }); + }); + + it('returns intiated client', () => { + const client = init({ dsn: PUBLIC_DSN, skipOpenTelemetrySetup: true }); - expect(mockIntegrations[0]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); - expect(mockIntegrations[1]?.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); - expect(autoPerformanceIntegration.setupOnce as jest.Mock).toHaveBeenCalledTimes(1); - expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(1); - - const client = getClient(); - expect(client?.getOptions()).toEqual( - expect.objectContaining({ - integrations: expect.arrayContaining([mockIntegrations[0], mockIntegrations[1], autoPerformanceIntegration]), - }), - ); + expect(client).toBeInstanceOf(NodeClient); }); - it('sets up OpenTelemetry by default', () => { - init({ dsn: PUBLIC_DSN }); + describe('autoSessionTracking', () => { + it('does not track session by default if no release is set', () => { + // On CI, we always infer the release, so this does not work + if (process.env.CI) { + return; + } + init({ dsn: PUBLIC_DSN }); - const client = getClient(); + const session = getIsolationScope().getSession(); + expect(session).toBeUndefined(); + }); - expect(client?.traceProvider).toBeDefined(); - }); + it('tracks session by default if release is set', () => { + init({ dsn: PUBLIC_DSN, release: '1.2.3' }); - it('allows to opt-out of OpenTelemetry setup', () => { - init({ dsn: PUBLIC_DSN, skipOpenTelemetrySetup: true }); + const session = getIsolationScope().getSession(); + expect(session).toBeDefined(); + }); - const client = getClient(); + it('does not track session if no release is set even if autoSessionTracking=true', () => { + // On CI, we always infer the release, so this does not work + if (process.env.CI) { + return; + } - expect(client?.traceProvider).not.toBeDefined(); - }); + init({ dsn: PUBLIC_DSN, autoSessionTracking: true }); - it('returns intiated client', () => { - const client = init({ dsn: PUBLIC_DSN, skipOpenTelemetrySetup: true }); + const session = getIsolationScope().getSession(); + expect(session).toBeUndefined(); + }); - expect(client).toBeInstanceOf(NodeClient); + it('does not track session if autoSessionTracking=false', () => { + init({ dsn: PUBLIC_DSN, autoSessionTracking: false, release: '1.2.3' }); + + const session = getIsolationScope().getSession(); + expect(session).toBeUndefined(); + }); + + it('tracks session by default if autoSessionTracking=true & release is set', () => { + init({ dsn: PUBLIC_DSN, release: '1.2.3', autoSessionTracking: true }); + + const session = getIsolationScope().getSession(); + expect(session).toBeDefined(); + }); }); });