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

feat(sveltekit): Always add browserTracingIntegration #13322

Merged
merged 5 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions packages/sveltekit/src/client/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { applySdkMetadata, hasTracingEnabled } from '@sentry/core';
import { applySdkMetadata } from '@sentry/core';
import type { BrowserOptions } from '@sentry/svelte';
import { getDefaultIntegrations as getDefaultSvelteIntegrations } from '@sentry/svelte';
import { WINDOW, init as initSvelteSdk } from '@sentry/svelte';
Expand Down Expand Up @@ -41,15 +41,13 @@ export function init(options: BrowserOptions): Client | undefined {
}

function getDefaultIntegrations(options: BrowserOptions): Integration[] | undefined {
// This evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false", in which case everything inside
// will get treeshaken away
// This evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false",
// in which case everything inside will get tree-shaken away
if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) {
if (hasTracingEnabled(options)) {
return [...getDefaultSvelteIntegrations(options), svelteKitBrowserTracingIntegration()];
}
return [...getDefaultSvelteIntegrations(options), svelteKitBrowserTracingIntegration()];
} else {
return getDefaultSvelteIntegrations(options);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: we don't need to throw the last return statement into an else block but we can just return directly. Not a problem but it shaves off a couple of bytes and reduces blocks :)

return undefined;
}

/**
Expand Down
14 changes: 1 addition & 13 deletions packages/sveltekit/test/client/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('Sentry client SDK', () => {
['tracesSampleRate', { tracesSampleRate: 0 }],
['tracesSampler', { tracesSampler: () => 1.0 }],
['enableTracing', { enableTracing: true }],
['no tracing option set', {}],
])('adds a browserTracingIntegration if tracing is enabled via %s', (_, tracingOptions) => {
init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
Expand All @@ -56,19 +57,6 @@ describe('Sentry client SDK', () => {
expect(browserTracing).toBeDefined();
});

it.each([
['enableTracing', { enableTracing: false }],
['no tracing option set', {}],
])("doesn't add a browserTracingIntegration integration if tracing is disabled via %s", (_, tracingOptions) => {
init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
...tracingOptions,
});

const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing');
expect(browserTracing).toBeUndefined();
});

it("doesn't add a browserTracingIntegration if `__SENTRY_TRACING__` is set to false", () => {
// This is the closest we can get to unit-testing the `__SENTRY_TRACING__` tree-shaking guard
// IRL, the code to add the integration would most likely be removed by the bundler.
Expand Down
Loading