diff --git a/packages/browser/test/index.test.ts b/packages/browser/test/index.test.ts index 42492cd36747..c0e79481788b 100644 --- a/packages/browser/test/index.test.ts +++ b/packages/browser/test/index.test.ts @@ -235,6 +235,7 @@ describe('SentryBrowser', () => { await flush(2000); const event = beforeSend.mock.calls[0]?.[0]; + expect(event.level).toBe('error'); expect(event.exception).toBeDefined(); expect(event.exception.values[0]).toBeDefined(); expect(event.exception.values[0]?.type).toBe('Error'); @@ -242,20 +243,20 @@ describe('SentryBrowser', () => { expect(event.exception.values[0]?.stacktrace.frames).not.toHaveLength(0); }); - it('should capture a message', () => - new Promise(resolve => { - const options = getDefaultBrowserClientOptions({ - beforeSend: event => { - expect(event.message).toBe('test'); - expect(event.exception).toBeUndefined(); - resolve(); - return event; - }, - dsn, - }); - setCurrentClient(new BrowserClient(options)); - captureMessage('test'); - })); + it('should capture a message', done => { + const options = getDefaultBrowserClientOptions({ + beforeSend: (event: Event): Event | null => { + expect(event.level).toBe('info'); + expect(event.message).toBe('test'); + expect(event.exception).toBeUndefined(); + done(); + return event; + }, + dsn, + }); + setCurrentClient(new BrowserClient(options)); + captureMessage('test'); + }); it('should capture an event', () => new Promise(resolve => { diff --git a/packages/core/src/server-runtime-client.ts b/packages/core/src/server-runtime-client.ts index c683ad0d2d54..e1d89c1d067b 100644 --- a/packages/core/src/server-runtime-client.ts +++ b/packages/core/src/server-runtime-client.ts @@ -60,7 +60,10 @@ export class ServerRuntimeClient< * @inheritDoc */ public eventFromException(exception: unknown, hint?: EventHint): PromiseLike { - return resolvedSyncPromise(eventFromUnknownInput(this, this._options.stackParser, exception, hint)); + const event = eventFromUnknownInput(this, this._options.stackParser, exception, hint); + event.level = 'error'; + + return resolvedSyncPromise(event); } /** diff --git a/packages/core/test/lib/serverruntimeclient.test.ts b/packages/core/test/lib/serverruntimeclient.test.ts index 40be09bf011c..bdf1c5242b80 100644 --- a/packages/core/test/lib/serverruntimeclient.test.ts +++ b/packages/core/test/lib/serverruntimeclient.test.ts @@ -154,4 +154,52 @@ describe('ServerRuntimeClient', () => { expect(sendEnvelopeSpy).toHaveBeenCalledTimes(0); }); }); + + describe('captureException', () => { + it('sends an exception event with level error', () => { + const options = getDefaultClientOptions({ dsn: PUBLIC_DSN }); + client = new ServerRuntimeClient(options); + + const sendEnvelopeSpy = jest.spyOn(client, 'sendEnvelope'); + + client.captureException(new Error('foo')); + + expect(sendEnvelopeSpy).toHaveBeenCalledTimes(1); + expect(sendEnvelopeSpy).toHaveBeenCalledWith([ + expect.any(Object), + [ + [ + expect.any(Object), + expect.objectContaining({ + level: 'error', + }), + ], + ], + ]); + }); + }); + + describe('captureMessage', () => { + it('sends a message event with level info', () => { + const options = getDefaultClientOptions({ dsn: PUBLIC_DSN }); + client = new ServerRuntimeClient(options); + + const sendEnvelopeSpy = jest.spyOn(client, 'sendEnvelope'); + + client.captureMessage('foo'); + + expect(sendEnvelopeSpy).toHaveBeenCalledTimes(1); + expect(sendEnvelopeSpy).toHaveBeenCalledWith([ + expect.any(Object), + [ + [ + expect.any(Object), + expect.objectContaining({ + level: 'info', + }), + ], + ], + ]); + }); + }); }); diff --git a/packages/deno/test/__snapshots__/mod.test.ts.snap b/packages/deno/test/__snapshots__/mod.test.ts.snap index 937eae2893f8..f9f3006c34c4 100644 --- a/packages/deno/test/__snapshots__/mod.test.ts.snap +++ b/packages/deno/test/__snapshots__/mod.test.ts.snap @@ -101,6 +101,7 @@ snapshot[`captureException 1`] = ` }, ], }, + level: "error", platform: "javascript", sdk: { integrations: [ @@ -134,6 +135,7 @@ snapshot[`captureMessage 1`] = ` { category: "sentry.event", event_id: "{{id}}", + level: "error", message: "Error: Some unhandled error", timestamp: 0, }, @@ -204,6 +206,7 @@ snapshot[`captureMessage twice 1`] = ` { category: "sentry.event", event_id: "{{id}}", + level: "error", message: "Error: Some unhandled error", timestamp: 0, }, @@ -281,6 +284,7 @@ snapshot[`captureMessage twice 2`] = ` { category: "sentry.event", event_id: "{{id}}", + level: "error", message: "Error: Some unhandled error", timestamp: 0, },