10000 fix(node): Disable autoSessionTracking if dsn undefined (#3954) · GinMu/sentry-javascript@d3ca7a8 · GitHub
[go: up one dir, main page]

Skip to content

Commit d3ca7a8

Browse files
fix(node): Disable autoSessionTracking if dsn undefined (getsentry#3954)
Co-authored-by: Kamil Ogórek <kamil.ogorek@gmail.com>
1 parent e71454e commit d3ca7a8

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

packages/node/src/sdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export function init(options: NodeOptions = {}): void {
114114
options.environment = process.env.SENTRY_ENVIRONMENT;
115115
}
116116

117-
if (options.autoSessionTracking === undefined) {
117+
if (options.autoSessionTracking === undefined && options.dsn !== undefined) {
118118
options.autoSessionTracking = true;
119119
}
120120

packages/node/test/index.test.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ describe('SentryNode initialization', () => {
377377
defaultIntegrations: [new MockIntegration('bar')],
378378
});
379379
const integrations = (initAndBind as jest.Mock).mock.calls[0][1].defaultIntegrations;
380-
expect(integrations.map(i => i.name)).toEqual(['bar', 'foo']);
380+
expect(integrations.map((i: { name: string }) => i.name)).toEqual(['bar', 'foo']);
381381
});
382382
});
383383

@@ -387,7 +387,7 @@ describe('SentryNode initialization', () => {
387387
defaultIntegrations: [new MockIntegration('baz'), new MockIntegration('qux')],
388388
});
389389
const integrations = (initAndBind as jest.Mock).mock.calls[0][1].defaultIntegrations;
390-
expect(integrations.map(i => i.name)).toEqual(['baz', 'qux', 'foo', 'bar']);
390+
expect(integrations.map((i: { name: string }) => i.name)).toEqual(['baz', 'qux', 'foo', 'bar']);
391391
});
392392
});
393393

@@ -401,4 +401,25 @@ describe('SentryNode initialization', () => {
401401
});
402402
});
403403
});
404+
405+
describe('autoSessionTracking', () => {
406+
it('enables autoSessionTracking if there is a release', () => {
407+
init({
408+
dsn: '',
409+
release: '3.5.7',
410+
});
411+
412+
const options = (initAndBind as jest.Mock).mock.calls[0][1];
413+
expect(options.autoSessionTracking).toBe(true);
414+
});
415+
416+
it('disables autoSessionTracking if dsn is undefined', () => {
417+
init({
418+
release: '3.5.7',
419+
});
420+
421+
const options = (initAndBind as jest.Mock).mock.calls[0][1];
422+
expect(options.autoSessionTracking).toBe(undefined);
423+
});
424+
});
404425
});

31C2 0 commit comments

Comments
 (0)
0