Skip to content

Commit

Permalink
fix(node): Disable autoSessionTracking if dsn undefined (#3954)
Browse files Browse the repository at this point in the history
Co-authored-by: Kamil Ogórek <[email protected]>
  • Loading branch information
AbhiPrasad and kamilogorek authored Sep 3, 2021
1 parent e71454e commit d3ca7a8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/node/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function init(options: NodeOptions = {}): void {
options.environment = process.env.SENTRY_ENVIRONMENT;
}

if (options.autoSessionTracking === undefined) {
if (options.autoSessionTracking === undefined && options.dsn !== undefined) {
options.autoSessionTracking = true;
}

Expand Down
25 changes: 23 additions & 2 deletions packages/node/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ describe('SentryNode initialization', () => {
defaultIntegrations: [new MockIntegration('bar')],
});
const integrations = (initAndBind as jest.Mock).mock.calls[0][1].defaultIntegrations;
expect(integrations.map(i => i.name)).toEqual(['bar', 'foo']);
expect(integrations.map((i: { name: string }) => i.name)).toEqual(['bar', 'foo']);
});
});

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

Expand All @@ -401,4 +401,25 @@ describe('SentryNode initialization', () => {
});
});
});

describe('autoSessionTracking', () => {
it('enables autoSessionTracking if there is a release', () => {
init({
dsn: '',
release: '3.5.7',
});

const options = (initAndBind as jest.Mock).mock.calls[0][1];
expect(options.autoSessionTracking).toBe(true);
});

it('disables autoSessionTracking if dsn is undefined', () => {
init({
release: '3.5.7',
});

const options = (initAndBind as jest.Mock).mock.calls[0][1];
expect(options.autoSessionTracking).toBe(undefined);
});
});
});

0 comments on commit d3ca7a8

Please sign in to comment.