From 2d7b96fc2cd8f8dfae122cb01e234703de73394f Mon Sep 17 00:00:00 2001 From: Peter Wadie Date: Tue, 7 Jul 2026 22:04:32 -0400 Subject: [PATCH 1/2] feat(bun): Add initWithoutDefaultIntegrations and getDefaultIntegrationsWithoutPerformance Brings @sentry/bun to parity with @sentry/node by adding a getDefaultIntegrationsWithoutPerformance() helper and an initWithoutDefaultIntegrations() entry point. init() and getDefaultIntegrations() are refactored to route through them, so existing default behavior is unchanged. --- packages/bun/src/index.ts | 7 ++++- packages/bun/src/sdk.ts | 29 ++++++++++++++++--- packages/bun/test/init.test.ts | 51 +++++++++++++++++++++++++++++++++- 3 files changed, 81 insertions(+), 6 deletions(-) diff --git a/packages/bun/src/index.ts b/packages/bun/src/index.ts index ca54db18c6be..ae98ae2aecad 100644 --- a/packages/bun/src/index.ts +++ b/packages/bun/src/index.ts @@ -198,7 +198,12 @@ export type { BunOptions } from './types'; // eslint-disable-next-line typescript/no-deprecated export { BunClient } from './client'; -export { getDefaultIntegrations, init } from './sdk'; +export { + getDefaultIntegrations, + getDefaultIntegrationsWithoutPerformance, + init, + initWithoutDefaultIntegrations, +} from './sdk'; export { bunServerIntegration } from './integrations/bunserver'; export { bunRuntimeMetricsIntegration, type BunRuntimeMetricsOptions } from './integrations/bunRuntimeMetrics'; export { makeFetchTransport } from './transports'; diff --git a/packages/bun/src/sdk.ts b/packages/bun/src/sdk.ts index ae27a986c352..7cc3a94c7a33 100644 --- a/packages/bun/src/sdk.ts +++ b/packages/bun/src/sdk.ts @@ -63,8 +63,8 @@ function getPerformanceIntegrations(options: Options): Integration[] { ]; } -/** Get the default integrations for the Bun SDK. */ -export function getDefaultIntegrations(options: Options): Integration[] { +/** Get the default integrations for the Bun SDK, excluding performance integrations. */ +export function getDefaultIntegrationsWithoutPerformance(): Integration[] { // We return a copy of the defaultIntegrations here to avoid mutating this return [ // Common @@ -88,10 +88,14 @@ export function getDefaultIntegrations(options: Options): Integration[] { processSessionIntegration(), // Bun Specific bunServerIntegration(), - ...getPerformanceIntegrations(options), ]; } +/** Get the default integrations for the Bun SDK. */ +export function getDefaultIntegrations(options: Options): Integration[] { + return [...getDefaultIntegrationsWithoutPerformance(), ...getPerformanceIntegrations(options)]; +} + /** * The Sentry Bun SDK Client. * @@ -137,6 +141,23 @@ export function getDefaultIntegrations(options: Options): Integration[] { * @see {@link BunOptions} for documentation on configuration options. */ export function init(userOptions: BunOptions = {}): NodeClient | undefined { + return _init(userOptions, getDefaultIntegrations); +} + +/** + * Initialize Sentry for Bun, without any integrations added by default. + */ +export function initWithoutDefaultIntegrations(userOptions: BunOptions = {}): NodeClient | undefined { + return _init(userOptions, () => []); +} + +/** + * Internal initialization function. + */ +function _init( + userOptions: BunOptions = {}, + getDefaultIntegrationsImpl: (options: Options) => Integration[], +): NodeClient | undefined { applySdkMetadata(userOptions, 'bun'); const options = { @@ -149,7 +170,7 @@ export function init(userOptions: BunOptions = {}): NodeClient | undefined { options.transport = options.transport || makeFetchTransport; if (options.defaultIntegrations === undefined) { - options.defaultIntegrations = getDefaultIntegrations(options); + options.defaultIntegrations = getDefaultIntegrationsImpl(options); } return initNode(options); diff --git a/packages/bun/test/init.test.ts b/packages/bun/test/init.test.ts index 0dd76a3a4072..793262314a98 100644 --- a/packages/bun/test/init.test.ts +++ b/packages/bun/test/init.test.ts @@ -2,7 +2,13 @@ import { type Integration } from '@sentry/core'; import * as sentryNode from '@sentry/node'; import type { Mock } from 'bun:test'; import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from 'bun:test'; -import { getClient, init } from '../src'; +import { + getClient, + getDefaultIntegrations, + getDefaultIntegrationsWithoutPerformance, + init, + initWithoutDefaultIntegrations, +} from '../src'; const PUBLIC_DSN = 'https://username@domain/123'; @@ -123,4 +129,47 @@ describe('init()', () => { expect(integrations?.map(({ name }) => name)).toContain('Some mock integration 4.3'); }); }); + + describe('initWithoutDefaultIntegrations()', () => { + it('installs no default integrations', () => { + initWithoutDefaultIntegrations({ dsn: PUBLIC_DSN }); + + const client = getClient(); + + expect(client?.getOptions().integrations).toEqual([]); + expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(0); + }); + + it('still installs user-provided integrations', () => { + const customIntegration = new MockIntegration('Custom integration'); + + initWithoutDefaultIntegrations({ dsn: PUBLIC_DSN, integrations: [customIntegration] }); + + const client = getClient(); + + expect(client?.getOptions().integrations.map(({ name }) => name)).toEqual(['Custom integration']); + expect(customIntegration.setupOnce).toHaveBeenCalledTimes(1); + }); + }); + + describe('getDefaultIntegrationsWithoutPerformance()', () => { + it('matches the full default set when tracing is disabled (no performance integrations added)', () => { + const withoutPerformance = getDefaultIntegrationsWithoutPerformance().map(({ name }) => name); + const full = getDefaultIntegrations({}).map(({ name }) => name); + + expect(withoutPerformance).toEqual(full); + expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(0); + }); + + it('omits the performance integrations that the full set adds when tracing is enabled', () => { + const performanceIntegration = new MockIntegration('Performance integration'); + mockAutoPerformanceIntegrations.mockImplementation(() => [performanceIntegration]); + + const withoutPerformance = getDefaultIntegrationsWithoutPerformance().map(({ name }) => name); + const full = getDefaultIntegrations({ tracesSampleRate: 1 }).map(({ name }) => name); + + expect(full).toContain('Performance integration'); + expect(withoutPerformance).not.toContain('Performance integration'); + }); + }); }); From 95689aac0e4d3560fdd5e87902b076c17c20c2cc Mon Sep 17 00:00:00 2001 From: Peter Wadie Date: Tue, 7 Jul 2026 22:15:53 -0400 Subject: [PATCH 2/2] ref(bun): Match @sentry/node nullish handling of defaultIntegrations Use nullish coalescing so a nullish defaultIntegrations falls back to the defaults (matching @sentry/node), and clarify the integrations comment. --- packages/bun/src/sdk.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/bun/src/sdk.ts b/packages/bun/src/sdk.ts index 7cc3a94c7a33..f0f083bb0661 100644 --- a/packages/bun/src/sdk.ts +++ b/packages/bun/src/sdk.ts @@ -65,7 +65,7 @@ function getPerformanceIntegrations(options: Options): Integration[] { /** Get the default integrations for the Bun SDK, excluding performance integrations. */ export function getDefaultIntegrationsWithoutPerformance(): Integration[] { - // We return a copy of the defaultIntegrations here to avoid mutating this + // Return a fresh array on each call so callers can safely mutate the result. return [ // Common // TODO(v11): Replace with eventFiltersIntegration once we remove the deprecated `inboundFiltersIntegration` @@ -169,9 +169,7 @@ function _init( options.transport = options.transport || makeFetchTransport; - if (options.defaultIntegrations === undefined) { - options.defaultIntegrations = getDefaultIntegrationsImpl(options); - } + options.defaultIntegrations = options.defaultIntegrations ?? getDefaultIntegrationsImpl(options); return initNode(options); }