Skip to content
Merged
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';
31 changes: 26 additions & 5 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 @@ -149,7 +170,7 @@ export function init(userOptions: BunOptions = {}): NodeClient | undefined {
options.transport = options.transport || makeFetchTransport;

if (options.defaultIntegrations === undefined) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

m: We should leave this as before, even if it looks cleaner and is technically more correct. The reason for that is that we would check against null too with the new implementation, while the older one only matches for undefined. I don't think changing the behavior now is good (especially when other SDKs still have this check)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reverted — kept the === undefined check so the null-handling behavior is unchanged (and it stays consistent with @sentry/deno, which uses the same check).

@JPeer264 JPeer264 Jul 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did you push it already? It seems that is still the old code

Nvm. I was checking the wrong commit 🤷

options.defaultIntegrations = getDefaultIntegrations(options);
options.defaultIntegrations = getDefaultIntegrationsImpl(options);
}

return initNode(options);
Expand Down
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');
});
});
Comment thread
JPeer264 marked this conversation as resolved.
});
Loading