Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/FlareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ public function register(): void
stacktraceMapper: $this->container->get(StacktraceMapper::class),
time: $this->container->get(Time::class),
ids: $this->container->get(Ids::class),
tracer: $this->container->get(Tracer::class),
resource: $this->container->get(Resource::class),
argumentReducers: $this->container->get(ArgumentReducers::class),
collectStackTraceArguments: $collects->collectStackFrameArguments,
Expand Down
3 changes: 3 additions & 0 deletions src/ReportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function __construct(
protected StacktraceMapper $stacktraceMapper,
protected Time $time,
protected Ids $ids,
protected Tracer $tracer,
public Resource $resource,
public null|ArgumentReducers $argumentReducers,
public bool $collectStackTraceArguments,
Expand Down Expand Up @@ -180,6 +181,8 @@ public function toArray(): array
'openFrameIndex' => null,
'applicationPath' => $this->applicationPath,
'trackingUuid' => $this->trackingUuid ?? $this->ids->uuid(),
'traceId' => $this->tracer->currentTraceId(),
'spanId' => $this->tracer->currentSpanId(),
'handled' => $this->handled,
'attributes' => $attributes,
'code' => $this->throwable->getCode(),
Expand Down
9 changes: 9 additions & 0 deletions tests/ReportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@
);
});

it('attaches the current trace and span id to a report', function () {
$flare = setupFlare();

$report = $flare->report(new Exception('this is an exception'))->toArray();

expect($report['traceId'])->toBe($flare->tracer->currentTraceId());
expect($report['spanId'])->toBe($flare->tracer->currentSpanId());
});

it('can create a report with error exception and will cleanup the stack trace', function () {
$flare = setupFlare();

Expand Down
10 changes: 10 additions & 0 deletions tests/TestClasses/ReportDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function serialize($data): string
$data = $this->emptyStacktrace($data);
$data = $this->removePhpunitArguments($data);
$data = $this->removeUuid($data);
$data = $this->removeTraceInfo($data);
$data = $this->removeResourceAttributes($data);

$yaml = parent::serialize($data);
Expand All @@ -27,6 +28,7 @@ public function match($expected, $actual)
$actual = $this->emptyStacktrace($actual);
$actual = $this->removePhpunitArguments($actual);
$actual = $this->removeUuid($actual);
$actual = $this->removeTraceInfo($actual);
$actual = $this->removeResourceAttributes($actual);

if (is_array($actual)) {
Expand Down Expand Up @@ -70,6 +72,14 @@ protected function removeUuid(array $data): array
return $data;
}

protected function removeTraceInfo(array $data): array
{
$data['traceId'] = 'fake-trace-id';
$data['spanId'] = 'fake-span-id';

return $data;
}

protected function removeResourceAttributes(array $data): array
{
$data['attributes']['telemetry.sdk.language'] = 'fake-telemetry-sdk-language';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ previous: { }
openFrameIndex: null
applicationPath: null
trackingUuid: fake-uuid
traceId: fake-trace-id
spanId: fake-span-id
handled: null
attributes:
service.name: 'PHP application'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ previous: { }
openFrameIndex: null
applicationPath: null
trackingUuid: fake-uuid
traceId: fake-trace-id
spanId: fake-span-id
handled: null
attributes:
service.name: 'PHP application'
Expand Down
2 changes: 2 additions & 0 deletions tests/__snapshots__/ReportTest__it_can_create_a_report__1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ previous: { }
openFrameIndex: null
applicationPath: null
trackingUuid: fake-uuid
traceId: fake-trace-id
spanId: fake-span-id
handled: null
attributes:
service.name: 'PHP application'
Expand Down
2 changes: 2 additions & 0 deletions tests/__snapshots__/ReportTest__it_can_create_a_report__2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ previous: { }
openFrameIndex: null
applicationPath: null
trackingUuid: fake-uuid
traceId: fake-trace-id
spanId: fake-span-id
handled: null
attributes:
service.name: 'PHP application'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ previous: { }
openFrameIndex: null
applicationPath: null
trackingUuid: fake-uuid
traceId: fake-trace-id
spanId: fake-span-id
handled: null
attributes:
service.name: 'PHP application'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ previous: { }
openFrameIndex: null
applicationPath: null
trackingUuid: fake-uuid
traceId: fake-trace-id
spanId: fake-span-id
handled: null
attributes:
service.name: 'PHP application'
Expand Down
Loading