Skip to content

Commit 395d3b1

Browse files
committed
Send better stack traces
Prior to this commit, the stack trace sent to Sentry would include references to all the FireGento Logger code plus this extension's logger. This made it harder to quickly determine where the actual error/exception occurred. So now we simply attempt to "rewind" the stack trace to the point where the error/exception occurred. And if for any reason we can't, we'll just use the original functionality.
1 parent df581ab commit 395d3b1

File tree

1 file changed

+26
-1
lines changed
  • app/code/community/Hackathon/LoggerSentry/Model

1 file changed

+26
-1
lines changed

app/code/community/Hackathon/LoggerSentry/Model/Sentry.php

+26-1
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ protected function _write($eventObj)
9494

9595
$this->_addUserContext($eventObj);
9696

97+
$stack = $this->_getStackTrace($event);
98+
9799
$this->_sentryClient->captureMessage(
98-
$event['message'], array(), $this->_priorityToLevelMapping[$priority], true, $additional
100+
$event['message'], array(), $this->_priorityToLevelMapping[$priority], $stack, $additional
99101
);
100102

101103
} catch (Exception $e) {
@@ -161,6 +163,29 @@ protected function _addUserContext($eventObj)
161163
}
162164
}
163165

166+
/**
167+
* @param array $event
168+
*
169+
* @return array
170+
*/
171+
protected function _getStackTrace($event)
172+
{
173+
$stack = debug_backtrace();
174+
// Remove the call to this _getStackTrace() function
175+
array_shift($stack);
176+
177+
if (isset($event['file']) && isset($event['line'])) {
178+
// "Unwind" the stack until we find where this was actually triggered from
179+
foreach ($stack as $i => $item) {
180+
if ($item['line'] === $event['line'] && strpos($item['file'], $event['file']) !== false) {
181+
return array_slice($stack, $i);
182+
}
183+
}
184+
}
185+
186+
return $stack;
187+
}
188+
164189
/**
165190
* Satisfy newer Zend Framework
166191
*

0 commit comments

Comments
 (0)