Skip to content

Commit 2d7b96f

Browse files
committed
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.
1 parent 9ca357f commit 2d7b96f

3 files changed

Lines changed: 81 additions & 6 deletions

File tree

packages/bun/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,12 @@ export type { BunOptions } from './types';
198198

199199
// eslint-disable-next-line typescript/no-deprecated
200200
export { BunClient } from './client';
201-
export { getDefaultIntegrations, init } from './sdk';
201+
export {
202+
getDefaultIntegrations,
203+
getDefaultIntegrationsWithoutPerformance,
204+
init,
205+
initWithoutDefaultIntegrations,
206+
} from './sdk';
202207
export { bunServerIntegration } from './integrations/bunserver';
203208
export { bunRuntimeMetricsIntegration, type BunRuntimeMetricsOptions } from './integrations/bunRuntimeMetrics';
204209
export { makeFetchTransport } from './transports';

packages/bun/src/sdk.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ function getPerformanceIntegrations(options: Options): Integration[] {
6363
];
6464
}
6565

66-
/** Get the default integrations for the Bun SDK. */
67-
export function getDefaultIntegrations(options: Options): Integration[] {
66+
/** Get the default integrations for the Bun SDK, excluding performance integrations. */
67+
export function getDefaultIntegrationsWithoutPerformance(): Integration[] {
6868
// We return a copy of the defaultIntegrations here to avoid mutating this
6969
return [
7070
// Common
@@ -88,10 +88,14 @@ export function getDefaultIntegrations(options: Options): Integration[] {
8888
processSessionIntegration(),
8989
// Bun Specific
9090
bunServerIntegration(),
91-
...getPerformanceIntegrations(options),
9291
];
9392
}
9493

94+
/** Get the default integrations for the Bun SDK. */
95+
export function getDefaultIntegrations(options: Options): Integration[] {
96+
return [...getDefaultIntegrationsWithoutPerformance(), ...getPerformanceIntegrations(options)];
97+
}
98+
9599
/**
96100
* The Sentry Bun SDK Client.
97101
*
@@ -137,6 +141,23 @@ export function getDefaultIntegrations(options: Options): Integration[] {
137141
* @see {@link BunOptions} for documentation on configuration options.
138142
*/
139143
export function init(userOptions: BunOptions = {}): NodeClient | undefined {
144+
return _init(userOptions, getDefaultIntegrations);
145+
}
146+
147+
/**
148+
* Initialize Sentry for Bun, without any integrations added by default.
149+
*/
150+
export function initWithoutDefaultIntegrations(userOptions: BunOptions = {}): NodeClient | undefined {
151+
return _init(userOptions, () => []);
152+
}
153+
154+
/**
155+
* Internal initialization function.
156+
*/
157+
function _init(
158+
userOptions: BunOptions = {},
159+
getDefaultIntegrationsImpl: (options: Options) => Integration[],
160+
): NodeClient | undefined {
140161
applySdkMetadata(userOptions, 'bun');
141162

142163
const options = {
@@ -149,7 +170,7 @@ export function init(userOptions: BunOptions = {}): NodeClient | undefined {
149170
options.transport = options.transport || makeFetchTransport;
150171

151172
if (options.defaultIntegrations === undefined) {
152-
options.defaultIntegrations = getDefaultIntegrations(options);
173+
options.defaultIntegrations = getDefaultIntegrationsImpl(options);
153174
}
154175

155176
return initNode(options);

packages/bun/test/init.test.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { type Integration } from '@sentry/core';
22
import * as sentryNode from '@sentry/node';
33
import type { Mock } from 'bun:test';
44
import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from 'bun:test';
5-
import { getClient, init } from '../src';
5+
import {
6+
getClient,
7+
getDefaultIntegrations,
8+
getDefaultIntegrationsWithoutPerformance,
9+
init,
10+
initWithoutDefaultIntegrations,
11+
} from '../src';
612

713
const PUBLIC_DSN = 'https://username@domain/123';
814

@@ -123,4 +129,47 @@ describe('init()', () => {
123129
expect(integrations?.map(({ name }) => name)).toContain('Some mock integration 4.3');
124130
});
125131
});
132+
133+
describe('initWithoutDefaultIntegrations()', () => {
134+
it('installs no default integrations', () => {
135+
initWithoutDefaultIntegrations({ dsn: PUBLIC_DSN });
136+
137+
const client = getClient();
138+
139+
expect(client?.getOptions().integrations).toEqual([]);
140+
expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(0);
141+
});
142+
143+
it('still installs user-provided integrations', () => {
144+
const customIntegration = new MockIntegration('Custom integration');
145+
146+
initWithoutDefaultIntegrations({ dsn: PUBLIC_DSN, integrations: [customIntegration] });
147+
148+
const client = getClient();
149+
150+
expect(client?.getOptions().integrations.map(({ name }) => name)).toEqual(['Custom integration']);
151+
expect(customIntegration.setupOnce).toHaveBeenCalledTimes(1);
152+
});
153+
});
154+
155+
describe('getDefaultIntegrationsWithoutPerformance()', () => {
156+
it('matches the full default set when tracing is disabled (no performance integrations added)', () => {
157+
const withoutPerformance = getDefaultIntegrationsWithoutPerformance().map(({ name }) => name);
158+
const full = getDefaultIntegrations({}).map(({ name }) => name);
159+
160+
expect(withoutPerformance).toEqual(full);
161+
expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(0);
162+
});
163+
164+
it('omits the performance integrations that the full set adds when tracing is enabled', () => {
165+
const performanceIntegration = new MockIntegration('Performance integration');
166+
mockAutoPerformanceIntegrations.mockImplementation(() => [performanceIntegration]);
167+
168+
const withoutPerformance = getDefaultIntegrationsWithoutPerformance().map(({ name }) => name);
169+
const full = getDefaultIntegrations({ tracesSampleRate: 1 }).map(({ name }) => name);
170+
171+
expect(full).toContain('Performance integration');
172+
expect(withoutPerformance).not.toContain('Performance integration');
173+
});
174+
});
126175
});

0 commit comments

Comments
 (0)