Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions packages/astro/src/client/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getDefaultIntegrations as getBrowserDefaultIntegrations,
init as initBrowserSdk,
} from '@sentry/browser';
import { applySdkMetadata, hasTracingEnabled } from '@sentry/core';
import { applySdkMetadata } from '@sentry/core';
import type { Client, Integration } from '@sentry/types';

// Tree-shakable guard to remove all code related to tracing
Expand All @@ -26,14 +26,12 @@ export function init(options: BrowserOptions): Client | undefined {
return initBrowserSdk(opts);
}

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

return undefined;
}
17 changes: 1 addition & 16 deletions packages/astro/test/client/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('Sentry client SDK', () => {
['tracesSampleRate', { tracesSampleRate: 0 }],
['tracesSampler', { tracesSampler: () => 1.0 }],
['enableTracing', { enableTracing: true }],
['no tracing option set', {}],
])('adds browserTracingIntegration if tracing is enabled via %s', (_, tracingOptions) => {
init({
dsn: 'https://[email protected]/1337',
Expand All @@ -66,22 +67,6 @@ describe('Sentry client SDK', () => {
expect(browserTracing).toBeDefined();
});

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

const integrationsToInit = browserInit.mock.calls[0]![0]?.defaultIntegrations || [];
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing');

expect(integrationsToInit).not.toContainEqual(expect.objectContaining({ name: 'BrowserTracing' }));
expect(browserTracing).toBeUndefined();
});

it("doesn't add browserTracingIntegration if `__SENTRY_TRACING__` is set to false", () => {
(globalThis as any).__SENTRY_TRACING__ = false;

Expand Down