Skip to content
Draft
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
3 changes: 2 additions & 1 deletion packages/elysia/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
bunServerIntegration,
getDefaultIntegrations as getBunDefaultIntegrations,
makeFetchTransport,
makeNodeTransport,
} from '@sentry/bun';
import type { Integration, Options } from '@sentry/core';
import { applySdkMetadata } from '@sentry/core';
Expand Down Expand Up @@ -50,7 +51,7 @@ export function init(userOptions: ElysiaOptions = {}): NodeClient | undefined {

applySdkMetadata(userOptions, 'elysia', ['elysia', options.runtime.name]);

options.transport = options.transport || makeFetchTransport;
options.transport = options.transport || (options.runtime.name === 'bun' ? makeFetchTransport : makeNodeTransport);

if (options.defaultIntegrations === undefined) {
options.defaultIntegrations = getDefaultIntegrations(options);
Expand Down
14 changes: 12 additions & 2 deletions packages/elysia/test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const mockApplySdkMetadata = vi.fn();
const mockInitNode = vi.fn();
const mockGetBunDefaultIntegrations = vi.fn(() => [] as Integration[]);
const mockMakeFetchTransport = vi.fn();
const mockMakeNodeTransport = vi.fn();

vi.mock('@sentry/core', async importActual => {
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
Expand All @@ -19,6 +20,7 @@ vi.mock('@sentry/bun', () => ({
init: mockInitNode,
getDefaultIntegrations: mockGetBunDefaultIntegrations,
makeFetchTransport: mockMakeFetchTransport,
makeNodeTransport: mockMakeNodeTransport,
bunServerIntegration: () => ({ name: 'BunServer', setupOnce: vi.fn() }),
}));

Expand Down Expand Up @@ -53,16 +55,24 @@ describe('init', () => {
);
});

it('uses makeFetchTransport by default', () => {
it('uses makeNodeTransport by default on Node', () => {
init({ dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0' });

expect(mockInitNode).toHaveBeenCalledWith(
expect.objectContaining({
transport: mockMakeFetchTransport,
transport: mockMakeNodeTransport,
}),
);
});

it('uses makeFetchTransport by default on Bun', () => {
vi.stubGlobal('Bun', { version: '1.2.3' });

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

expect(mockInitNode).toHaveBeenCalledWith(expect.objectContaining({ transport: mockMakeFetchTransport }));
});

it('allows overriding transport', () => {
const customTransport = vi.fn();
init({ dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0', transport: customTransport });
Expand Down
Loading