Skip to content

Commit

Permalink
Add Sentry Store Frame -> Event mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Dec 16, 2023
1 parent 5e0bc1b commit 9bc24ec
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Sender/Console/Renderer/Sentry/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public static function renderMessageHeader(OutputInterface $output, array $messa
{
// Collect metadata
$meta = [];
$time = new DateTimeImmutable(isset($message['sent_at']) ? $message['sent_at'] : "@$message[timestamp]");
$timeValue = $message['sent_at'] ?? $message['timestamp'] ?? 'now';
$time = new DateTimeImmutable(\is_numeric($timeValue) ? "@$timeValue" : $timeValue);
$meta['Time'] = $time->format('Y-m-d H:i:s.u');
isset($message['event_id']) and $meta['Event ID'] = $message['event_id'];
isset($message['transaction']) and $meta['Transaction'] = $message['transaction'];
Expand Down
1 change: 1 addition & 0 deletions src/Sender/Frontend/FrameMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function map(Frame $frame): Event
Frame\VarDumper::class => (new Mapper\VarDump())->map($frame),
Frame\Http::class => (new Mapper\HttpRequest())->map($frame),
Frame\Smtp::class => (new Mapper\Smtp())->map($frame),
Frame\Sentry\SentryStore::class => (new Mapper\SentryStore())->map($frame),
default => throw new \InvalidArgumentException('Unknown frame type ' . $frame::class),
};
}
Expand Down
25 changes: 25 additions & 0 deletions src/Sender/Frontend/Mapper/SentryStore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Buggregator\Trap\Sender\Frontend\Mapper;

use Buggregator\Trap\Proto\Frame\Sentry as SentryFrame;
use Buggregator\Trap\Sender\Frontend\Event;
use Buggregator\Trap\Support\Uuid;

/**
* @internal
*/
final class SentryStore
{
public function map(SentryFrame $frame): Event
{
return new Event(
uuid: Uuid::uuid4(),
type: 'sentry',
payload: $frame->message,
timestamp: (float)$frame->time->format('U.u'),
);
}
}
4 changes: 2 additions & 2 deletions src/Sender/Frontend/Mapper/VarDump.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Buggregator\Trap\Sender\Frontend\Mapper;

use Buggregator\Trap\Proto\Frame\VarDumper;
use Buggregator\Trap\Proto\Frame\VarDumper as VarDumperFrame;
use Buggregator\Trap\Sender\Frontend\Event;
use Buggregator\Trap\Support\Uuid;
use Symfony\Component\VarDumper\Cloner\Data;
Expand All @@ -16,7 +16,7 @@
*/
final class VarDump
{
public function map(VarDumper $frame): Event
public function map(VarDumperFrame $frame): Event
{
$payload = $this->parse($frame->dump);
return new Event(
Expand Down

0 comments on commit 9bc24ec

Please sign in to comment.