Skip to content

Commit 488993c

Browse files
author
Michal Cech
committed
grab all logs and push them to breadcrumbs
1 parent f5ff228 commit 488993c

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/Client.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ public function handleBeginRequestEvent(\CEvent $event): void
307307
*/
308308
public function handleEndRequestEvent(\CEvent $event): void
309309
{
310+
$this->grabPushLogsFromLoggerToBreadcrumbs();
311+
310312
if ($this->appSpan !== null) {
311313
$this->appSpan->finish();
312314
}
@@ -321,6 +323,8 @@ public function handleEndRequestEvent(\CEvent $event): void
321323

322324
public function handleExceptionEvent(\CEvent $event): void
323325
{
326+
$this->grabPushLogsFromLoggerToBreadcrumbs();
327+
324328
if ($this->rootTransaction !== null) {
325329
$this->rootTransaction->setHttpStatus(500);
326330
}
@@ -329,7 +333,7 @@ public function handleExceptionEvent(\CEvent $event): void
329333
/**
330334
* @param string[]|int[]|bool[] $data
331335
*/
332-
public function startRootTransaction(string $description, array $data = []): Transaction
336+
private function startRootTransaction(string $description, array $data = []): Transaction
333337
{
334338
$context = new TransactionContext();
335339
$context->setOp('yii-app');
@@ -392,4 +396,28 @@ private function operationNameFromBeginRequestEvent(CEvent $event): string
392396
}
393397

394398
//endregion
399+
private function grabPushLogsFromLoggerToBreadcrumbs(): void
400+
{
401+
$logs = Yii::getLogger()->getLogs();
402+
403+
foreach ($logs as $log) {
404+
/**
405+
* @var string $message
406+
* @var string $level
407+
* @var string $category
408+
*/
409+
list($message, $level, $category) = $log;
410+
411+
// remove stack trace from message
412+
if (($pos = strpos($message, 'Stack trace:')) !== false) {
413+
$message = substr($message, 0, $pos);
414+
}
415+
416+
if ($level === 'trace') {
417+
$level = Breadcrumb::LEVEL_DEBUG;
418+
}
419+
420+
$this->addBreadcrumb($level, Breadcrumb::TYPE_DEFAULT, $category, $message);
421+
}
422+
}
395423
}

0 commit comments

Comments
 (0)