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
2 changes: 1 addition & 1 deletion packages/bun/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function _init(
const options = {
...userOptions,
platform: 'javascript',
runtime: { name: 'bun', version: typeof Bun !== 'undefined' ? Bun.version : 'unknown' },
runtime: userOptions.runtime || { name: 'bun', version: typeof Bun !== 'undefined' ? Bun.version : 'unknown' },
serverName: userOptions.serverName || global.process.env.SENTRY_NAME || os.hostname(),
};

Expand Down
8 changes: 8 additions & 0 deletions packages/bun/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ export interface BaseBunOptions extends ServerRuntimeOptions {
* @default false
*/
enableOpenTelemetrySetup?: boolean;

/**
* Override the runtime name reported in events.
* Defaults to 'bun' with the current Bun version if not specified.
*
* @hidden This is primarily used internally to support SDKs wrapping the Bun SDK, like Elysia.
*/
runtime?: { name: string; version?: string };
}

/**
Expand Down
14 changes: 14 additions & 0 deletions packages/bun/test/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@ describe('init()', () => {
});
});

describe('runtime', () => {
it('defaults to bun', () => {
init({ dsn: PUBLIC_DSN, traceLifecycle: 'static' });

expect(getClient()?.getOptions().runtime).toEqual({ name: 'bun', version: Bun.version });
});

it('respects a runtime provided through options', () => {
init({ dsn: PUBLIC_DSN, traceLifecycle: 'static', runtime: { name: 'node', version: '20.0.0' } });

expect(getClient()?.getOptions().runtime).toEqual({ name: 'node', version: '20.0.0' });
});
});

describe('initWithoutDefaultIntegrations()', () => {
it('installs no default integrations', () => {
initWithoutDefaultIntegrations({ dsn: PUBLIC_DSN, traceLifecycle: 'static' });
Expand Down
11 changes: 11 additions & 0 deletions packages/elysia/test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const { init, getDefaultIntegrations } = await import('../src/sdk');
describe('init', () => {
afterEach(() => {
vi.clearAllMocks();
vi.unstubAllGlobals();
});

it('sets SDK metadata to elysia', () => {
Expand Down Expand Up @@ -108,6 +109,16 @@ describe('init', () => {
expect(calledOptions.runtime.name).toBe('node');
expect(calledOptions.runtime.version).toBe(process.version);
});

it('detects bun runtime when Bun is defined', () => {
vi.stubGlobal('Bun', { version: '1.2.3' });

init({ dsn: 'https://***@o0.ingest.sentry.io/0' });

const calledOptions = mockInitNode.mock.calls[0]![0];
expect(calledOptions.runtime).toEqual({ name: 'bun', version: '1.2.3' });
expect(mockApplySdkMetadata).toHaveBeenCalledWith(expect.anything(), 'elysia', ['elysia', 'bun']);
});
});

describe('getDefaultIntegrations', () => {
Expand Down
Loading