Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Suppress stack when
SentryError
isn't an error (#5562)
We use `SentryError`s in our event processing and sending pipeline both when something has gone legitimately wrong and when we just want to bail on a promise chain. In all cases, however, we log both the message and the stack, at a warning log level, which both clutters the logs and unnecessarily alarms anyone who has logging on. This fixes that by adding a `logLevel` property to the `SentryError` class, which can be read before we log to the console. The default behavior remains the same (log the full error, using `logger.warn`), but now we have the option of passing `'log'` as a second constructor parameter, in order to mark a given `SentryError` as something which should only be `logger.log`ged and whose stack should be suppressed.
- Loading branch information
1 parent
9339a73
commit 380f483
Showing
6 changed files
with
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
import type { ConsoleLevel } from './logger'; | ||
|
||
/** An error emitted by Sentry SDKs and related utilities. */ | ||
export class SentryError extends Error { | ||
/** Display name of this error instance. */ | ||
public name: string; | ||
|
||
public constructor(public message: string) { | ||
public logLevel: ConsoleLevel; | ||
|
||
public constructor(public message: string, logLevel: ConsoleLevel = 'warn') { | ||
super(message); | ||
|
||
this.name = new.target.prototype.constructor.name; | ||
// This sets the prototype to be `Error`, not `SentryError`. It's unclear why we do this, but commenting this line | ||
// out causes various (seemingly totally unrelated) playwright tests consistently time out. FYI, this makes | ||
// instances of `SentryError` fail `obj instanceof SentryError` checks. | ||
Object.setPrototypeOf(this, new.target.prototype); | ||
this.logLevel = logLevel; | ||
} | ||
} |
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