- Issue created by @PabloNicolas
- Merge request !51raven-3521778: Update ignored_messages filtering β (Open) created by PabloNicolas
- πΊπΈUnited States mfb San Francisco
We intentionally match the generic unformatted/uninterpolated message because that is often necessary. For example, we don't want to have to ignore a message for each user logging in, but rather for "[user] logged in". So, we can't make this change.
To filter events the way you want you'll need to write a little code to set the
before_send
callback option, which allows you to provide arbitrary custom logic for filtering events; theignore_exceptions
option is also available. - πΊπΈUnited States mfb San Francisco
Thinking thru some pros and cons of various solutions for this:
If we check both the unformatted and formatted message in ignored_messages, then it would be easy to ignore specific errors. However, whenever the line number or absolute path of the file changes, the error would no longer be ignored. Therefore, this would be a pretty brittle solution - it doesn't seem particularly great to me
Another idea would be to check both the unformatted message and, if it exists,
$context['@message']
. This would be a more general rule, ignoring new cases of the error that appear, regardless of where it appears. So, it seems more useful as a filter, although certainly could cause people to unintentionally miss new errors. - π§π·Brazil PabloNicolas
I managed to resolve my specific issue by creating an event subscriber to OptionsAlter:
<?php namespace Drupal\example\EventSubscriber; use Drupal\raven\Event\OptionsAlter; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Sentry\Event; use Sentry\EventHint; class SentryOptionsAlterSubscriber implements EventSubscriberInterface { /** * {@inheritdoc} */ public static function getSubscribedEvents(): array { return [ OptionsAlter::class => 'onOptionsAlter', ]; } /** * Alter Sentry options before client initialization. */ public function onOptionsAlter(OptionsAlter $event): void { $options = &$event->options; $options['before_send'] = function (Event $event, ?EventHint $hint): ?Event { $ignored = \Drupal::config('raven.settings')->get('ignored_messages') ?? []; if ( $hint !== null && isset($hint->exception) && method_exists($hint->exception, 'getMessage') && in_array($hint->exception->getMessage(), $ignored, true) ) { return null; } return $event; }; } }
But I think we can replicate it on the module itself, and with some tweaks here and there would give us more flexibility on how we ignore these specific messages.
- πΊπΈUnited States mfb San Francisco
Sorry for the miscommunication: Subscribing to the event and setting the before_send callback is something you should do in your custom code to provide the functionality you're looking for.
It should not be done in this module.