Skip to content

Latest commit

 

History

History
46 lines (37 loc) · 1.33 KB

extension-points.md

File metadata and controls

46 lines (37 loc) · 1.33 KB

Extension points

You can inherit from SentryHandler class and optionally override two methods:

<?php

namespace App;

use BGalati\MonologSentryHandler\SentryHandler as BaseSentryHandler;
use Sentry\Event as SentryEvent;
use Sentry\State\Scope;

class SentryHandler extends BaseSentryHandler
{
    /** {@inheritdoc} */
    protected function processScope(Scope $scope, $record, SentryEvent $sentryEvent): void
    {
        // Your custom logic like this one:
        // ....
        if (isset($record['context']['extra']) && \is_array($record['context']['extra'])) {
            foreach ($record['context']['extra'] as $key => $value) {
                $scope->setExtra((string) $key, $value);
            }
        }

        if (isset($record['context']['tags']) && \is_array($record['context']['tags'])) {
            foreach ($record['context']['tags'] as $key => $value) {
                $scope->setTag($key, $value);
            }
        }
    }

    /** {@inheritdoc} */
    protected function afterWrite(): void
    {
        // Your custom code before events are flushed
        // ...

        // Call parent method to keep default behavior or don't call it if you don't need it
        parent::afterWrite();
    }
}

Please look at these methods within the class SentryHandler if you want more details.