Skip to content

Commit

Permalink
feat(astro): Always add BrowserTracing
Browse files Browse the repository at this point in the history
  • Loading branch information
s1gr1d committed Aug 6, 2024
1 parent 7fc479f commit 915894a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
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://public@dsn.ingest.sentry.io/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://public@dsn.ingest.sentry.io/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

0 comments on commit 915894a

Please sign in to comment.