@@ -307,6 +307,8 @@ public function handleBeginRequestEvent(\CEvent $event): void
307
307
*/
308
308
public function handleEndRequestEvent (\CEvent $ event ): void
309
309
{
310
+ $ this ->grabPushLogsFromLoggerToBreadcrumbs ();
311
+
310
312
if ($ this ->appSpan !== null ) {
311
313
$ this ->appSpan ->finish ();
312
314
}
@@ -321,6 +323,8 @@ public function handleEndRequestEvent(\CEvent $event): void
321
323
322
324
public function handleExceptionEvent (\CEvent $ event ): void
323
325
{
326
+ $ this ->grabPushLogsFromLoggerToBreadcrumbs ();
327
+
324
328
if ($ this ->rootTransaction !== null ) {
325
329
$ this ->rootTransaction ->setHttpStatus (500 );
326
330
}
@@ -329,7 +333,7 @@ public function handleExceptionEvent(\CEvent $event): void
329
333
/**
330
334
* @param string[]|int[]|bool[] $data
331
335
*/
332
- public function startRootTransaction (string $ description , array $ data = []): Transaction
336
+ private function startRootTransaction (string $ description , array $ data = []): Transaction
333
337
{
334
338
$ context = new TransactionContext ();
335
339
$ context ->setOp ('yii-app ' );
@@ -392,4 +396,28 @@ private function operationNameFromBeginRequestEvent(CEvent $event): string
392
396
}
393
397
394
398
//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
+ }
395
423
}
0 commit comments