Increasing serialization information depth in context


#1

Hi,

I’m trying to figure out how to get more information in the sentry logs. Currently using a legacy layer, I’m trying to add the php exception information to the context of a log (using a monolog compatible adapter). Sadly the serialization doesn’t go deep enough as seen in this image:
image

How can I improve this?


#2

You’d want to report this as an actual exception and not a log attribute. Without that sentry will fail to group things well. Otherwise your only other option is to serializer this as another value. The tree depth might be configurable (I forget) but we enforce it to ensure the UI is usable and the packet size is acceptable.


#3

Usually monolog takes care of this, which works fine in the Symfony application. Sadly I do not have Symfony started in this context (and doing so would be overkill), so I don’t have access to the actual monolog configuration. I basically set the exception in the context array, so I can access it and process it some way. How would I configure setting the exception as such? I feel like this is trivial to add, but must’ve missed it in the documentation.

I feel like there’s something to add to this piece of code, perhaps try and add the monolog processor for this manually? Thanks for pointing me in the right direction already!

self::$logger = new \Monolog\Logger($name);
self::$logger->pushProcessor(function ($record) {
    // ...
    $trace = \Logger::getStackTrace();
    $record['stacktrace'] = ['frames' => Raven_Stacktrace::get_stack_info($trace)];
    $record['context']['stacktrace'] = $record['stacktrace'];

    return $record;
});

if (defined('SENTRY_DSN')) {
    $client = new \Raven_Client(SENTRY_DSN, array('curl_method' => 'exec'));

    $handler = new RavenLoggerWithStacktraceHandler($client, \Monolog\Logger::WARNING);
    $handler->setFormatter(new LineFormatter("%message% %context% %extra%\n"));

    self::$logger->pushHandler($handler);
}