Skip to content

Commit b5b9467

Browse files
fix(v10/elysia): use Node transport on Node runtimes (#25484)
Backport of: #25015 ## Differences to the original PR - `packages/elysia/test/sdk.test.ts`: added `vi.unstubAllGlobals()` to the `init` suite's `afterEach`. `develop` already has it from an earlier change, but `v10` doesn't. Without it, the new `Bun` global stub from the "uses makeFetchTransport by default on Bun" test leaks into the later "detects runtime correctly" test and makes it fail. This only changes the test; the SDK change is the same as the original. <!-- junior-request-attribution:start --> via Junior system actor `junior`. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent-dispatch%3Adispatch_e2d9682ec1a7b2d7f0f202f0a051f7a3 --> -- [View Junior Session](https://junior-prod.sentry.dev/conversations/agent-dispatch%3Adispatch_e2d9682ec1a7b2d7f0f202f0a051f7a3) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent-dispatch%3Adispatch_e2d9682ec1a7b2d7f0f202f0a051f7a3/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
1 parent d3270d2 commit b5b9467

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

‎packages/elysia/src/sdk.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
bunServerIntegration,
44
getDefaultIntegrations as getBunDefaultIntegrations,
55
makeFetchTransport,
6+
makeNodeTransport,
67
} from '@sentry/bun';
78
import type { Integration, Options } from '@sentry/core';
89
import { applySdkMetadata } from '@sentry/core';
@@ -50,7 +51,7 @@ export function init(userOptions: ElysiaOptions = {}): NodeClient | undefined {
5051

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

53-
options.transport = options.transport || makeFetchTransport;
54+
options.transport = options.transport || (options.runtime.name === 'bun' ? makeFetchTransport : makeNodeTransport);
5455

5556
if (options.defaultIntegrations === undefined) {
5657
options.defaultIntegrations = getDefaultIntegrations(options);

‎packages/elysia/test/sdk.test.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const mockApplySdkMetadata = vi.fn();
55
const mockInitNode = vi.fn();
66
const mockGetBunDefaultIntegrations = vi.fn(() => [] as Integration[]);
77
const mockMakeFetchTransport = vi.fn();
8+
const mockMakeNodeTransport = vi.fn();
89

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

@@ -29,6 +31,7 @@ const { init, getDefaultIntegrations } = await import('../src/sdk');
2931
describe('init', () => {
3032
afterEach(() => {
3133
vi.clearAllMocks();
34+
vi.unstubAllGlobals();
3235
});
3336

3437
it('sets SDK metadata to elysia', () => {
@@ -52,16 +55,24 @@ describe('init', () => {
5255
);
5356
});
5457

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

5861
expect(mockInitNode).toHaveBeenCalledWith(
5962
expect.objectContaining({
60-
transport: mockMakeFetchTransport,
63+
transport: mockMakeNodeTransport,
6164
}),
6265
);
6366
});
6467

68+
it('uses makeFetchTransport by default on Bun', () => {
69+
vi.stubGlobal('Bun', { version: '1.2.3' });
70+
71+
init({ dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0' });
72+
73+
expect(mockInitNode).toHaveBeenCalledWith(expect.objectContaining({ transport: mockMakeFetchTransport }));
74+
});
75+
6576
it('allows overriding transport', () => {
6677
const customTransport = vi.fn();
6778
init({ dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0', transport: customTransport });

0 commit comments

Comments
 (0)