Skip to content

Commit

Permalink
feat(sveltekit): Always add browserTracingIntegration (#13322)
Browse files Browse the repository at this point in the history
closes #13011

ref: #13318
  • Loading branch information
s1gr1d authored Aug 13, 2024
1 parent 899c571 commit 0e7c492
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
12 changes: 5 additions & 7 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()];
}

return undefined;
return getDefaultSvelteIntegrations(options);
}

/**
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

0 comments on commit 0e7c492

Please sign in to comment.