Skip to content

Commit

Permalink
ref(backend): Use fluent tracing APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric committed Jan 18, 2024
1 parent b0a30f9 commit d8c75ad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Command/UpdateUsersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected function _execute(Arguments $args, ConsoleIo $io)
$connection = ConnectionManager::get('default');
$connection->getDriver()->setLogger($logger);

$transactionContext = (new TransactionContext())
$transactionContext = TransactionContext::make()
->setOp('command')
->setName('COMMAND update_users')
->setSource(TransactionSource::task());
Expand All @@ -101,7 +101,7 @@ protected function _execute(Arguments $args, ConsoleIo $io)
]);

foreach ($users as $user) {
$spanContext = (new SpanContext())
$spanContext = SpanContext::make()
->setOp('command')
->setDescription('Update user');
$span = $transaction->startChild($spanContext);
Expand Down Expand Up @@ -159,8 +159,8 @@ protected function _execute(Arguments $args, ConsoleIo $io)
}
SentrySdk::getCurrentHub()->setSpan($transaction);

$transaction->setStatus(SpanStatus::ok());
$transaction->finish();
$transaction->setStatus(SpanStatus::ok())
->finish();

$io->success("\n[DONE]");
}
Expand Down
23 changes: 11 additions & 12 deletions src/Middleware/SentryMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,23 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
return $handler->handle($request);
}

$requestStartTime = $request->getServerParams()['REQUEST_TIME_FLOAT'] ?? microtime(true);

$sentryTraceHeader = $request->getHeaderLine('sentry-trace');
$baggageHeader = $request->getHeaderLine('baggage');

$transactionContext = TransactionContext::fromHeaders($sentryTraceHeader, $baggageHeader);

$requestStartTime = $request->getServerParams()['REQUEST_TIME_FLOAT'] ?? microtime(true);

$transactionContext->setOp('http.server');
$transactionContext->setName($request->getMethod() . ' ' . $request->getUri()->getPath());
$transactionContext->setSource(TransactionSource::route());
$transactionContext->setStartTimestamp($requestStartTime);
$transactionContext = TransactionContext::fromHeaders($sentryTraceHeader, $baggageHeader)
->setOp('http.server')
->setName($request->getMethod() . ' ' . $request->getUri()->getPath())
->setSource(TransactionSource::route())
->setStartTimestamp($requestStartTime);

$transaction = startTransaction($transactionContext);

SentrySdk::getCurrentHub()->setSpan($transaction);

$spanContext = new SpanContext();
$spanContext->setOp('middleware.handle');
$spanContext = SpanContext::make()
->setOp('middleware.handle');
$span = $transaction->startChild($spanContext);

SentrySdk::getCurrentHub()->setSpan($span);
Expand All @@ -69,8 +68,8 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$transaction->setSampled(false);
}

$span->setHttpStatus($response->getStatusCode());
$span->finish();
$span->setHttpStatus($response->getStatusCode())
->finish();

SentrySdk::getCurrentHub()->setSpan($transaction);

Expand Down

0 comments on commit d8c75ad

Please sign in to comment.