Skip to content

Commit

Permalink
Fixed the bug that $transaction is null
Browse files Browse the repository at this point in the history
  • Loading branch information
huangdijia committed Oct 26, 2023
1 parent 408f692 commit 649fbda
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/sentry/src/Tracing/Middleware/TraceMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$response = $handler->handle($request);

// Set http status code
TraceContext::getTransaction()?->setHttpStatus($response->getStatusCode());
$transaction?->setHttpStatus($response->getStatusCode());
// Set status
TraceContext::getTransaction()?->setStatus(SpanStatus::ok());
$transaction?->setStatus(SpanStatus::ok());

// Append sentry-trace header to response
$traceId = (string) TraceContext::getTransaction()?->getTraceId();
$traceId = (string) $transaction?->getTraceId();
if ($traceId) {
$response = $response->withHeader('sentry-trace-id', $traceId);
}
} catch (Throwable $exception) {
$transaction->setStatus(SpanStatus::internalError());
$transaction?->setStatus(SpanStatus::internalError());
if (! $this->switcher->isExceptionIgnored($exception)) {
$transaction->setTags([
$transaction?->setTags([
'exception.class' => get_class($exception),
'exception.code' => $exception->getCode(),
'exception.message' => $exception->getMessage(),
Expand Down

0 comments on commit 649fbda

Please sign in to comment.