Created
April 7, 2022 19:40
-
-
Save DerZyklop/ffe002bb4dfb9b75b689a7ca5d10031a to your computer and use it in GitHub Desktop.
Custom PSentryFilterIntegration
This file contains hidden or 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
import { EventProcessor, Hub, Integration, Event } from '@sentry/types'; | |
export class PSentryFilterIntegration implements Integration { | |
public static id : string = 'PSentryFilterIntegration'; | |
public name : string = PSentryFilterIntegration.id; | |
constructor(private ignoreErrors : RegExp[]) {} | |
/** | |
* Sets the integration up only once. | |
* This takes no options on purpose, options should be passed in the constructor | |
*/ | |
public setupOnce(addGlobalEventProcessor : (callback : EventProcessor) => void, getCurrentHub : () => Hub) : void { | |
addGlobalEventProcessor((event) => { | |
const hub = getCurrentHub(); | |
if (!hub) { | |
return event; | |
} | |
const self = hub.getIntegration(PSentryFilterIntegration); | |
if (self) { | |
if (typeof self._shouldDropEvent !== 'function') { | |
return event; | |
} | |
return self._shouldDropEvent(event , this.ignoreErrors) ? null : event; | |
} | |
return event; | |
}); | |
} | |
private _shouldDropEvent(event : Event, options : RegExp[]) : boolean { | |
// if (event.tags?.['Config.DEBUG'] === 'true') return false; | |
if (event.message) return false; | |
const result = options.find(regex => { | |
const errors = event.exception?.values; | |
return !!errors?.find(error => { | |
return !!error.value?.match(regex); | |
}); | |
}); | |
return !!result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment