Custom Sentry handler for Monolog for sending log context data to sentry events with additional event information and it's focussed on ease-of-use and elegant syntax
You can install the package using the Composer package manager. You can install it by running this command in your project root:
composer require gentenox/sentry-monolog-handler
monolog:
handlers:
sentry:
type: service
id: monolog_context_handler
monolog_context_handler:
class: SentryMonologHandler\MonologContextHandler
arguments:
$hub: '@Sentry\State\HubInterface'
$level: !php/const Monolog\Logger::ERROR
In examples below used monolog logger that implements Psr\Log\LoggerInterface
In this example sentry error handler receive logger context data end send it to Sentry as sentry event context data
$logger->error('Cannot find existing order for user', [
'user_id' => $user->getId()
]);
In this example sentry error handler receive logger context data and handle specific properties such as tags and fingerprint These specific properties will not be added to logs and used only for providing additional event information to Sentry
Field | Type | Description |
---|---|---|
MonologFields::Tags |
array | Contains Sentry tags. Tags are key/value string pairs and used for filtering events |
MonologFields::Fingerprint |
array | Contains Sentry fingerprint. Events with the same fingerprint are grouped together into an issue |
$logger->error('Invalid postback received', [
MonologFields::Tags->value => ['scope' => 'postback_validation']
MonologFields::Fingerprint->value => ['postback_validation_fingerprint']
]);