Skip to content
Merged
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 @@ -49,7 +49,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 || (options.runtime.name === 'bun' ? makeFetchTransport : makeNodeTransport);

Expand Down
53 changes: 32 additions & 21 deletions packages/elysia/test/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
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();
const mockMakeNodeTransport = 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 @@ -34,13 +24,21 @@ 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',
packages: [
expect.objectContaining({ name: 'npm:@sentry/elysia' }),
expect.objectContaining({ name: 'npm:@sentry/node' }),
],
}),
},
}),
);
});

Expand Down Expand Up @@ -114,20 +112,33 @@ describe('init', () => {
it('detects runtime correctly', () => {
init({ dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0' });

const calledOptions = mockInitNode.mock.calls[0]![0];
// In vitest (Node), Bun is not defined, so runtime should be node
expect(calledOptions.runtime.name).toBe('node');
expect(calledOptions.runtime.version).toBe(process.version);
expect(mockInitNode).toHaveBeenCalledWith(
expect.objectContaining({
runtime: { name: 'node', version: 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']);
expect(mockInitNode).toHaveBeenCalledWith(
expect.objectContaining({
runtime: { name: 'bun', version: '1.2.3' },
_metadata: {
sdk: expect.objectContaining({
name: 'sentry.javascript.elysia',
packages: [
expect.objectContaining({ name: 'npm:@sentry/elysia' }),
expect.objectContaining({ name: 'npm:@sentry/bun' }),
],
}),
},
}),
);
});
});

Expand Down
Loading