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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ test('Captures an error thrown in a route handler', async ({ baseURL, request })
});

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

expect(errorEvent.contexts?.trace).toEqual(
expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ test('Captures an error thrown in a route handler', async ({ baseURL, request })
});

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

expect(errorEvent.contexts?.trace).toEqual(
expect.objectContaining({
Expand Down
2 changes: 1 addition & 1 deletion packages/elysia/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function init(userOptions: ElysiaOptions = {}): NodeClient | undefined {
serverName: userOptions.serverName || global.process.env.SENTRY_NAME || os.hostname(),
};

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

options.transport = options.transport || makeFetchTransport;

Expand Down
29 changes: 11 additions & 18 deletions packages/elysia/test/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import type { Integration } from '@sentry/core';
import { afterEach, describe, expect, it, vi } from 'vitest';

const mockApplySdkMetadata = vi.fn();
const mockInitNode = vi.fn();
const mockGetBunDefaultIntegrations = vi.fn(() => [] as Integration[]);
const mockMakeFetchTransport = vi.fn();

vi.mock('@sentry/core', async importActual => {
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
const actual = await importActual<typeof import('@sentry/core')>();
return {
...actual,
applySdkMetadata: mockApplySdkMetadata,
};
});

vi.mock('@sentry/bun', () => ({
init: mockInitNode,
getDefaultIntegrations: mockGetBunDefaultIntegrations,
Expand All @@ -32,13 +22,13 @@ describe('init', () => {
vi.unstubAllGlobals();
});

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

expect(mockApplySdkMetadata).toHaveBeenCalledWith(
expect.objectContaining({ dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0' }),
'elysia',
['elysia', 'node'],
expect(mockInitNode).toHaveBeenCalledWith(
expect.objectContaining({
_metadata: { sdk: expect.objectContaining({ name: 'sentry.javascript.elysia' }) },
}),
);
});

Expand Down Expand Up @@ -115,9 +105,12 @@ describe('init', () => {

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']);
expect(mockInitNode).toHaveBeenCalledWith(
expect.objectContaining({
runtime: { name: 'bun', version: '1.2.3' },
_metadata: { sdk: expect.objectContaining({ name: 'sentry.javascript.elysia' }) },
}),
);
});
});

Expand Down
Loading