Skip to content
Open
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
7 changes: 6 additions & 1 deletion packages/bun/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
33 changes: 26 additions & 7 deletions packages/bun/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ function getPerformanceIntegrations(options: Options): Integration[] {
];
}

/** Get the default integrations for the Bun SDK. */
export function getDefaultIntegrations(options: Options): Integration[] {
// We return a copy of the defaultIntegrations here to avoid mutating this
/** Get the default integrations for the Bun SDK, excluding performance integrations. */
export function getDefaultIntegrationsWithoutPerformance(): Integration[] {
// 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`
Expand All @@ -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.
*
Expand Down Expand Up @@ -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 = {
Expand All @@ -148,9 +169,7 @@ export function init(userOptions: BunOptions = {}): NodeClient | undefined {

options.transport = options.transport || makeFetchTransport;

if (options.defaultIntegrations === undefined) {
options.defaultIntegrations = getDefaultIntegrations(options);
}
options.defaultIntegrations = options.defaultIntegrations ?? getDefaultIntegrationsImpl(options);

return initNode(options);
}
51 changes: 50 additions & 1 deletion packages/bun/test/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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');
});
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing integration or E2E test

Low Severity

This feat PR adds public initWithoutDefaultIntegrations and getDefaultIntegrationsWithoutPerformance exports but only extends unit tests. Per project review guidelines, feature work should include at least one integration or E2E test covering the new behavior.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 95689aa. Configure here.

});