Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node): Disable autoSessionTracking if dsn undefined #3954

Merged
merged 3 commits into from Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/node/src/sdk.ts
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
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);
});
});
});