Skip to content

Commit 64c5b62

Browse files
Merge pull request #2 from plunkettscott/fix/check-span-isset
Ensure span is set before accessing it
2 parents bedd76a + a5c0d00 commit 64c5b62

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Concerns/TracesHttpRequests.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public function createAndActivateRootSpan(bool $continueTrace, Request $request)
7171

7272
public function terminateRootSpan(Request $request, mixed $response): void
7373
{
74+
if (! isset($this->span)) {
75+
return;
76+
}
77+
7478
if (method_exists($response, 'getStatusCode')) {
7579
$this->span->setAttribute(TraceAttributes::HTTP_STATUS_CODE, $response->getStatusCode());
7680
}
@@ -82,7 +86,10 @@ public function terminateRootSpan(Request $request, mixed $response): void
8286
}
8387

8488
$this->span->end();
85-
$this->scope->detach();
89+
90+
if (isset($this->scope)) {
91+
$this->scope->detach();
92+
}
8693
}
8794

8895
private function calculateSpanName(Request $request): string

0 commit comments

Comments
 (0)