Skip to content
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

Ability to add a custom stacktrace parsing method #1585

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/DataCollector/QueryCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class QueryCollector extends PDOCollector
'/vendor/october/rain',
'/vendor/barryvdh/laravel-debugbar',
];
protected static $customFrameParsers = [];

/**
* @param TimeDataCollector $timeCollector
Expand All @@ -43,6 +44,14 @@ public function __construct(TimeDataCollector $timeCollector = null)
$this->timeCollector = $timeCollector;
}

/**
* Add a custom frame parser for a specific object type.
*/
public static function addCustomFrameParser(string $objectType, callable $customFrameParser): void
{
static::$customFrameParsers[$objectType] = $customFrameParser;
}

/**
* @param int|null $softLimit After the soft limit, no parameters/backtrace are captured
* @param int|null $hardLimit After the hard limit, queries are ignored
Expand Down Expand Up @@ -334,6 +343,15 @@ protected function parseTrace($index, array $trace)
) {
$frame->file = $trace['file'];

foreach (static::$customFrameParsers as $objectType => $customFrameParser) {
if (isset($trace['object']) && is_a($trace['object'], $objectType)) {
$frame->line = '?';
$frame = $customFrameParser($frame, $trace);
$frame->name = $this->normalizeFilePath($frame->file);
return $frame;
}
}

if (isset($trace['object']) && is_a($trace['object'], 'Twig_Template')) {
list($frame->file, $frame->line) = $this->getTwigInfo($trace);
} elseif (strpos($frame->file, storage_path()) !== false) {
Expand Down