-
-
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.
feat(replay): Add
onError
callback + other small improvements to de…
…bugging (#13721) * Adds an `onError` callback for replay SDK exceptions * Do not log empty messages when calling `logger.exception` * Send `ratelimit_backoff` client report when necessary (instead of generic `send_error`)
- Loading branch information
Showing
6 changed files
with
113 additions
and
15 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { beforeEach, describe, expect, it } from 'vitest'; | ||
|
||
import * as SentryCore from '@sentry/core'; | ||
import { logger as coreLogger } from '@sentry/utils'; | ||
import { logger } from '../../../src/util/logger'; | ||
|
||
const mockCaptureException = vi.spyOn(SentryCore, 'captureException'); | ||
const mockAddBreadcrumb = vi.spyOn(SentryCore, 'addBreadcrumb'); | ||
const mockLogError = vi.spyOn(coreLogger, 'error'); | ||
vi.spyOn(coreLogger, 'info'); | ||
vi.spyOn(coreLogger, 'log'); | ||
vi.spyOn(coreLogger, 'warn'); | ||
|
||
describe('logger', () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
describe.each([ | ||
[false, false], | ||
[false, true], | ||
[true, false], | ||
[true, true], | ||
])('with options: captureExceptions:%s, traceInternals:%s', (captureExceptions, traceInternals) => { | ||
beforeEach(() => { | ||
logger.setConfig({ | ||
captureExceptions, | ||
traceInternals, | ||
}); | ||
}); | ||
|
||
it.each([ | ||
['info', 'info', 'info message'], | ||
['log', 'log', 'log message'], | ||
['warn', 'warning', 'warn message'], | ||
['error', 'error', 'error message'], | ||
])('%s', (fn, level, message) => { | ||
logger[fn](message); | ||
expect(coreLogger[fn]).toHaveBeenCalledWith('[Replay] ', message); | ||
|
||
if (traceInternals) { | ||
expect(mockAddBreadcrumb).toHaveBeenLastCalledWith( | ||
{ | ||
category: 'console', | ||
data: { logger: 'replay' }, | ||
level, | ||
message: `[Replay] ${message}`, | ||
}, | ||
{ level }, | ||
); | ||
} | ||
}); | ||
|
||
it('logs exceptions with a message', () => { | ||
const err = new Error('An error'); | ||
logger.exception(err, 'a message'); | ||
if (captureExceptions) { | ||
expect(mockCaptureException).toHaveBeenCalledWith(err); | ||
} | ||
expect(mockLogError).toHaveBeenCalledWith('[Replay] ', 'a message'); | ||
expect(mockLogError).toHaveBeenLastCalledWith('[Replay] ', err); | ||
expect(mockLogError).toHaveBeenCalledTimes(2); | ||
|
||
if (traceInternals) { | ||
expect(mockAddBreadcrumb).toHaveBeenCalledWith( | ||
{ | ||
category: 'console', | ||
data: { logger: 'replay' }, | ||
level: 'error', | ||
message: '[Replay] a message', | ||
}, | ||
{ level: 'error' }, | ||
); | ||
} | ||
}); | ||
|
||
it('logs exceptions without a message', () => { | ||
const err = new Error('An error'); | ||
logger.exception(err); | ||
if (captureExceptions) { | ||
expect(mockCaptureException).toHaveBeenCalledWith(err); | ||
expect(mockAddBreadcrumb).not.toHaveBeenCalled(); | ||
} | ||
expect(mockLogError).toHaveBeenCalledTimes(1); | ||
expect(mockLogError).toHaveBeenLastCalledWith('[Replay] ', err); | ||
}); | ||
}); | ||
}); |