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
@@ -0,0 +1,11 @@
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';

Sentry.init({
dsn: 'https://[email protected]/1337',
release: '1.0',
transport: loggingTransport,
attachStacktrace: true,
});

Sentry.captureMessage('Message');
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';

afterAll(() => {
cleanupChildProcesses();
});

test('capture a simple message string with a stack trace if `attachStackTrace` is `true`', done => {
createRunner(__dirname, 'scenario.ts')
.expect({
event: {
message: 'Message',
level: 'info',
exception: {
values: [
{
mechanism: { synthetic: true, type: 'generic', handled: true },
value: 'Message',
stacktrace: { frames: expect.any(Array) },
},
],
},
},
})
.start(done);
});
1 change: 1 addition & 0 deletions packages/core/src/utils-hoist/eventbuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export function eventFromMessage(
},
],
};
addExceptionMechanism(event, { synthetic: true });
}
}

Expand Down
62 changes: 61 additions & 1 deletion packages/core/test/utils-hoist/eventbuilder.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Client } from '../../src/types-hoist';
import { eventFromUnknownInput } from '../../src/utils-hoist/eventbuilder';
import { eventFromMessage, eventFromUnknownInput } from '../../src/utils-hoist/eventbuilder';
import { nodeStackLineParser } from '../../src/utils-hoist/node-stack-trace';
import { createStackParser } from '../../src/utils-hoist/stacktrace';

Expand Down Expand Up @@ -154,3 +154,63 @@ describe('eventFromUnknownInput', () => {
expect(event.exception?.values?.[0]?.value).toBe('Object captured as exception with keys: foo, prop');
});
});

describe('eventFromMessage', () => {
it('creates an event from a string message', () => {
const event = eventFromMessage(stackParser, 'Test Message');
expect(event).toEqual({
event_id: undefined, // this is undefined because the hint isn't passed
level: 'info',
message: 'Test Message',
});
});

it('attaches a synthetic exception if passed and `attachStackTrace` is true', () => {
const syntheticException = new Error('Test Message');
const event = eventFromMessage(
stackParser,
'Test Message',
'info',
{ syntheticException, event_id: '123abc' },
true,
);

expect(event).toEqual({
event_id: '123abc',
exception: {
values: [
{
mechanism: {
handled: true,
synthetic: true,
type: 'generic',
},
stacktrace: {
frames: expect.any(Array),
},
value: 'Test Message',
},
],
},
level: 'info',
message: 'Test Message',
});
});

it("doesn't attach a synthetic exception if `attachStackTrace` is false", () => {
const syntheticException = new Error('Test Message');
const event = eventFromMessage(
stackParser,
'Test Message',
'info',
{ syntheticException, event_id: '123abc' },
false,
);

expect(event).toEqual({
event_id: '123abc',
level: 'info',
message: 'Test Message',
});
});
});
Loading