Skip to content

Commit 65d23eb

Browse files
fix(v10/elysia): Set SDK metadata on the options passed to init (#25486)
Backport of: #24521 ## Differences to the original PR - `packages/elysia/test/sdk.test.ts`: dropped the updated `detects bun runtime when Bun is defined` assertions — that test (and its `vi.stubGlobal`/`vi.unstubAllGlobals` setup) doesn't exist on v10. The Node-runtime regression test (`passes Elysia SDK metadata to initNode`) is backported and fails without the fix. <!-- junior-request-attribution:start --> via Junior system actor `junior`. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent-dispatch%3Adispatch_bd63706ff178f2ce5dfeca498c2ed352 --> -- [View Junior Session](https://junior-prod.sentry.dev/conversations/agent-dispatch%3Adispatch_bd63706ff178f2ce5dfeca498c2ed352) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent-dispatch%3Adispatch_bd63706ff178f2ce5dfeca498c2ed352/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
1 parent b5b9467 commit 65d23eb

4 files changed

Lines changed: 21 additions & 19 deletions

File tree

‎dev-packages/e2e-tests/test-applications/elysia-bun/tests/errors.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ test('Captures an error thrown in a route handler', async ({ baseURL, request })
1919
});
2020

2121
expect(errorEvent.transaction).toEqual('GET /test-exception/:id');
22+
expect(errorEvent.sdk?.name).toBe('sentry.javascript.elysia');
2223

2324
expect(errorEvent.contexts?.trace).toEqual(
2425
expect.objectContaining({

‎dev-packages/e2e-tests/test-applications/elysia-node/tests/errors.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ test('Captures an error thrown in a route handler', async ({ baseURL, request })
1919
});
2020

2121
expect(errorEvent.transaction).toEqual('GET /test-exception/:id');
22+
expect(errorEvent.sdk?.name).toBe('sentry.javascript.elysia');
2223

2324
expect(errorEvent.contexts?.trace).toEqual(
2425
expect.objectContaining({

‎packages/elysia/src/sdk.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function init(userOptions: ElysiaOptions = {}): NodeClient | undefined {
4949
serverName: userOptions.serverName || global.process.env.SENTRY_NAME || os.hostname(),
5050
};
5151

52-
applySdkMetadata(userOptions, 'elysia', ['elysia', options.runtime.name]);
52+
applySdkMetadata(options, 'elysia', ['elysia', options.runtime.name]);
5353

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

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
import type { Integration } from '@sentry/core';
22
import { afterEach, describe, expect, it, vi } from 'vitest';
33

4-
const mockApplySdkMetadata = vi.fn();
54
const mockInitNode = vi.fn();
65
const mockGetBunDefaultIntegrations = vi.fn(() => [] as Integration[]);
76
const mockMakeFetchTransport = vi.fn();
87
const mockMakeNodeTransport = vi.fn();
98

10-
vi.mock('@sentry/core', async importActual => {
11-
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
12-
const actual = await importActual<typeof import('@sentry/core')>();
13-
return {
14-
...actual,
15-
applySdkMetadata: mockApplySdkMetadata,
16-
};
17-
});
18-
199
vi.mock('@sentry/bun', () => ({
2010
init: mockInitNode,
2111
getDefaultIntegrations: mockGetBunDefaultIntegrations,
@@ -34,13 +24,21 @@ describe('init', () => {
3424
vi.unstubAllGlobals();
3525
});
3626

37-
it('sets SDK metadata to elysia', () => {
27+
it('passes Elysia SDK metadata to initNode', () => {
3828
init({ dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0' });
3929

40-
expect(mockApplySdkMetadata).toHaveBeenCalledWith(
41-
expect.objectContaining({ dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0' }),
42-
'elysia',
43-
['elysia', 'node'],
30+
expect(mockInitNode).toHaveBeenCalledWith(
31+
expect.objectContaining({
32+
_metadata: {
33+
sdk: expect.objectContaining({
34+
name: 'sentry.javascript.elysia',
35+
packages: [
36+
expect.objectContaining({ name: 'npm:@sentry/elysia' }),
37+
expect.objectContaining({ name: 'npm:@sentry/node' }),
38+
],
39+
}),
40+
},
41+
}),
4442
);
4543
});
4644

@@ -114,10 +112,12 @@ describe('init', () => {
114112
it('detects runtime correctly', () => {
115113
init({ dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0' });
116114

117-
const calledOptions = mockInitNode.mock.calls[0]![0];
118115
// In vitest (Node), Bun is not defined, so runtime should be node
119-
expect(calledOptions.runtime.name).toBe('node');
120-
expect(calledOptions.runtime.version).toBe(process.version);
116+
expect(mockInitNode).toHaveBeenCalledWith(
117+
expect.objectContaining({
118+
runtime: { name: 'node', version: process.version },
119+
}),
120+
);
121121
});
122122
});
123123

0 commit comments

Comments
 (0)