From 915894acbaa85d298d860a42013a3a6c9928d5b9 Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Tue, 6 Aug 2024 12:19:23 +0200 Subject: [PATCH] feat(astro): Always add BrowserTracing --- packages/astro/src/client/sdk.ts | 14 ++++++-------- packages/astro/test/client/sdk.test.ts | 17 +---------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/packages/astro/src/client/sdk.ts b/packages/astro/src/client/sdk.ts index e38a552feb39..8a4617c652cf 100644 --- a/packages/astro/src/client/sdk.ts +++ b/packages/astro/src/client/sdk.ts @@ -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 @@ -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; } diff --git a/packages/astro/test/client/sdk.test.ts b/packages/astro/test/client/sdk.test.ts index 1ef31131cb77..41ff4bbae061 100644 --- a/packages/astro/test/client/sdk.test.ts +++ b/packages/astro/test/client/sdk.test.ts @@ -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', @@ -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()?.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;