-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(core)!: Mark exceptions from
captureConsoleIntegration
as `hand…
…led: true` by default (#14734) Flip the default value for the `handled` flag in exceptions captured by `captureConsoleIntegration`. This integration only captures exceptions if `attachStackTrace` is set to `true`. Added another integration test as a follow-up as promised in #14664.
- Loading branch information
Showing
7 changed files
with
213 additions
and
12 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
...ges/browser-integration-tests/suites/integrations/captureConsole-attachStackTrace/init.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
import { captureConsoleIntegration } from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
integrations: [captureConsoleIntegration()], | ||
autoSessionTracking: false, | ||
attachStacktrace: true, | ||
}); |
8 changes: 8 additions & 0 deletions
8
.../browser-integration-tests/suites/integrations/captureConsole-attachStackTrace/subject.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
console.log('console log'); | ||
console.warn('console warn'); | ||
console.error('console error'); | ||
console.info('console info'); | ||
console.trace('console trace'); | ||
|
||
console.error(new Error('console error with error object')); | ||
console.trace(new Error('console trace with error object')); |
176 changes: 176 additions & 0 deletions
176
...ges/browser-integration-tests/suites/integrations/captureConsole-attachStackTrace/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/core'; | ||
|
||
import { sentryTest } from '../../../utils/fixtures'; | ||
import { getMultipleSentryEnvelopeRequests } from '../../../utils/helpers'; | ||
|
||
sentryTest( | ||
'captures console messages correctly and adds a synthetic stack trace if `attachStackTrace` is set to `true`', | ||
async ({ getLocalTestUrl, page }) => { | ||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
const [, events] = await Promise.all([page.goto(url), getMultipleSentryEnvelopeRequests<Event>(page, 7)]); | ||
|
||
expect(events).toHaveLength(7); | ||
|
||
const logEvent = events.find(event => event.message === 'console log'); | ||
const warnEvent = events.find(event => event.message === 'console warn'); | ||
const infoEvent = events.find(event => event.message === 'console info'); | ||
const errorEvent = events.find(event => event.message === 'console error'); | ||
const traceEvent = events.find(event => event.message === 'console trace'); | ||
const errorWithErrorEvent = events.find( | ||
event => event.exception && event.exception.values?.[0].value === 'console error with error object', | ||
); | ||
const traceWithErrorEvent = events.find( | ||
event => event.exception && event.exception.values?.[0].value === 'console trace with error object', | ||
); | ||
|
||
expect(logEvent).toEqual( | ||
expect.objectContaining({ | ||
level: 'log', | ||
logger: 'console', | ||
extra: { | ||
arguments: ['console log'], | ||
}, | ||
message: 'console log', | ||
}), | ||
); | ||
expect(logEvent?.exception?.values![0]).toMatchObject({ | ||
mechanism: { | ||
handled: true, | ||
type: 'console', | ||
synthetic: true, | ||
}, | ||
value: 'console log', | ||
stacktrace: { | ||
frames: expect.any(Array), | ||
}, | ||
}); | ||
|
||
expect(warnEvent).toEqual( | ||
expect.objectContaining({ | ||
level: 'warning', | ||
logger: 'console', | ||
extra: { | ||
arguments: ['console warn'], | ||
}, | ||
message: 'console warn', | ||
}), | ||
); | ||
expect(warnEvent?.exception?.values![0]).toMatchObject({ | ||
mechanism: { | ||
handled: true, | ||
type: 'console', | ||
synthetic: true, | ||
}, | ||
value: 'console warn', | ||
stacktrace: { | ||
frames: expect.any(Array), | ||
}, | ||
}); | ||
|
||
expect(infoEvent).toEqual( | ||
expect.objectContaining({ | ||
level: 'info', | ||
logger: 'console', | ||
extra: { | ||
arguments: ['console info'], | ||
}, | ||
message: 'console info', | ||
}), | ||
); | ||
expect(infoEvent?.exception?.values![0]).toMatchObject({ | ||
mechanism: { | ||
handled: true, | ||
type: 'console', | ||
synthetic: true, | ||
}, | ||
value: 'console info', | ||
stacktrace: { | ||
frames: expect.any(Array), | ||
}, | ||
}); | ||
|
||
expect(errorEvent).toEqual( | ||
expect.objectContaining({ | ||
level: 'error', | ||
logger: 'console', | ||
extra: { | ||
arguments: ['console error'], | ||
}, | ||
message: 'console error', | ||
}), | ||
); | ||
expect(errorEvent?.exception?.values![0]).toMatchObject({ | ||
mechanism: { | ||
handled: true, | ||
type: 'console', | ||
synthetic: true, | ||
}, | ||
value: 'console error', | ||
stacktrace: { | ||
frames: expect.any(Array), | ||
}, | ||
}); | ||
|
||
expect(traceEvent).toEqual( | ||
expect.objectContaining({ | ||
level: 'log', | ||
logger: 'console', | ||
extra: { | ||
arguments: ['console trace'], | ||
}, | ||
message: 'console trace', | ||
}), | ||
); | ||
expect(traceEvent?.exception?.values![0]).toMatchObject({ | ||
mechanism: { | ||
handled: true, | ||
type: 'console', | ||
synthetic: true, | ||
}, | ||
value: 'console trace', | ||
stacktrace: { | ||
frames: expect.any(Array), | ||
}, | ||
}); | ||
|
||
expect(errorWithErrorEvent).toEqual( | ||
expect.objectContaining({ | ||
level: 'error', | ||
logger: 'console', | ||
extra: { | ||
arguments: [ | ||
{ | ||
message: 'console error with error object', | ||
name: 'Error', | ||
stack: expect.any(String), | ||
}, | ||
], | ||
}, | ||
exception: expect.any(Object), | ||
}), | ||
); | ||
expect(errorWithErrorEvent?.exception?.values?.[0].value).toBe('console error with error object'); | ||
expect(errorWithErrorEvent?.exception?.values?.[0].mechanism).toEqual({ | ||
handled: true, | ||
type: 'console', | ||
}); | ||
expect(traceWithErrorEvent).toEqual( | ||
expect.objectContaining({ | ||
level: 'log', | ||
logger: 'console', | ||
extra: { | ||
arguments: [ | ||
{ | ||
message: 'console trace with error object', | ||
name: 'Error', | ||
stack: expect.any(String), | ||
}, | ||
], | ||
}, | ||
}), | ||
); | ||
expect(traceWithErrorEvent?.exception?.values?.[0].value).toBe('console trace with error object'); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters