Skip to content

Instantly share code, notes, and snippets.

@DerZyklop
Created April 7, 2022 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DerZyklop/ffe002bb4dfb9b75b689a7ca5d10031a to your computer and use it in GitHub Desktop.
Save DerZyklop/ffe002bb4dfb9b75b689a7ca5d10031a to your computer and use it in GitHub Desktop.
Custom PSentryFilterIntegration
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