-
-
Notifications
You must be signed in to change notification settings - Fork 452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2.0] Monolog #790
Comments
There is no feature like that one in the v2. We are reasoning about adding it back and there is an open issue in Seldaek/monolog#1273 to track the feature request. In the meantime the only way to do it is to write yourself the handler
It is here |
Ah thanks, I missed that. I was reading the official docs and didn't notice anything. |
@ste93cry Would you consider creating a repository under @getsentry organization as suggested in linked issue and maintaining it there? |
@fmasa We will move the code into this package. |
@HazAT Thank you, that will be great 👍 |
Hi, any ETA to create monolog handler for 2.0 version? |
I'm also waiting to upgrade until the monolog handler is bundled. |
I've opened the PR that should fix this issue. If you have any suggestion they are welcome! Please note that following Semver the first version that will include such feature will be |
@ste93cry is there anyway to use monolog handler to track breadcrumbs as it did with the old raven sdk? |
#844 is still pending review/discussion and should implement such feature, but talking with @untitaker I found out that in other SDKs the decision was to avoid as much as possible pulling information from structured logging entries, so it may be that it won't be supported anymore out-of-the-box. Of course this doesn't means that it cannot be implemented in your own project. My suggestion until a final decision on the matter is taken is to decorate the handler and add the breadcrumbs to the scope using |
Ok no problem. I implemented my own which seems to be working well in case anyone else wants to use it. <?php
declare(strict_types=1);
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Logger;
use Sentry\State\HubInterface;
use Sentry\State\Scope;
use Sentry\Breadcrumb;
/**
* This Monolog handler logs every message to a Sentry's server using the given
* hub instance.
*/
final class MonologBreadcrumbHandler extends AbstractProcessingHandler
{
/**
* @var HubInterface
*/
private $hub;
/**
* Constructor.
*
* @param HubInterface $hub The hub to which errors are reported
* @param int $level The minimum logging level at which this
* handler will be triggered
* @param bool $bubble Whether the messages that are handled can
* bubble up the stack or not
*/
public function __construct(HubInterface $hub, $level = Logger::DEBUG, bool $bubble = true)
{
$this->hub = $hub;
parent::__construct($level, $bubble);
}
/**
* {@inheritdoc}
*/
protected function write(array $record): void
{
$level = $this->getSeverityFromLevel($record['level']);
$message = $record['message'];
$type = Breadcrumb::TYPE_DEFAULT;
$category = 'monolog';
$metadata = $record['context'];
$breadcrumb = new Breadcrumb($level, $type, $category, $message, $metadata);
$this->hub->addBreadcrumb($breadcrumb);
}
/**
* Translates the Monolog level into the Sentry severity.
*
* @param int $level The Monolog log level
*
* @return Severity
*/
private function getSeverityFromLevel(int $level): string
{
switch ($level) {
case Logger::DEBUG:
return Breadcrumb::LEVEL_DEBUG;
case Logger::INFO:
case Logger::NOTICE:
return Breadcrumb::LEVEL_INFO;
case Logger::WARNING:
return Breadcrumb::LEVEL_WARNING;
case Logger::ERROR:
return Breadcrumb::LEVEL_ERROR;
case Logger::CRITICAL:
case Logger::ALERT:
case Logger::EMERGENCY:
return Breadcrumb::LEVEL_CRITICAL;
default:
return Breadcrumb::LEVEL_INFO;
}
}
} using it like this: $hub = \Sentry\State\Hub::getCurrent();
$sentryHandler = new MonologBreadcrumbHandler($hub);
$logger->pushHandler($sentryHandler); |
@esetnik I released a dedicated handler lib if you are interested -> https://github.com/B-Galati/monolog-sentry-handler |
What's the status here? The monolog documentation says the handler in sentry-php is the one to use. But there is no mention of it anywhere in the sentry-php documentation. |
FTR, #808 added it in 2.1.0 of this client. |
In sentry client v1 we were able to use the
Raven_Breadcrumbs_MonologHandler
handler. Is there a similar functionality in v2? There doesn't appear to be any documentation on this and it isn't listed as a removed feature either.The text was updated successfully, but these errors were encountered: