Skip to content

Commit

Permalink
Optimize TraceMiddleware
Browse files Browse the repository at this point in the history
  • Loading branch information
huangdijia committed Oct 27, 2023
1 parent c0ba328 commit 3362aae
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Tracing/Middleware/TraceMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public function __construct(

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): PsrResponseInterface
{
// Must be called before all.
$this->startTransaction($request, SentrySdk::getCurrentHub(), SentryContext::getServerName());

/** @var Dispatched|null $dispatched */
$dispatched = $request->getAttribute(Dispatched::class);
if (
Expand All @@ -55,8 +58,6 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
return $handler->handle($request);
}

$this->startTransaction($request, SentrySdk::getCurrentHub(), SentryContext::getServerName());

$transaction = TraceContext::getTransaction();

if (! $transaction) {
Expand Down Expand Up @@ -157,7 +158,9 @@ private function startTransaction(ServerRequestInterface $request, HubInterface
$context->setData($data);

// Set tags
$tags = [];
$tags = [
'http.request.method' => strtoupper($request->getMethod()), // MUST
];
if ($this->tagManager->has('request.http.path')) {
$tags[$this->tagManager->get('request.http.path')] = $path;
}
Expand Down

0 comments on commit 3362aae

Please sign in to comment.