Skip to content

Commit

Permalink
Optimize TraceMiddleware
Browse files Browse the repository at this point in the history
  • Loading branch information
huangdijia committed Oct 26, 2023
1 parent 299e0fa commit c7b1532
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/sentry/src/Tracing/Middleware/TraceMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,35 +126,35 @@ private function startTransaction(ServerRequestInterface $request, HubInterface

// Set tags
$tags = [];

if ($this->tagManager->has('request.header')) {
foreach ($request->getHeaders() as $key => $value) {
$tags[$this->tagManager->get('request.header') . '.' . $key] = implode(', ', $value);
}
}

$context->setTags($tags);

// Start transaction
$transaction = $sentry->startTransaction($context);

// If this transaction is not sampled, we can stop here to prevent doing work for nothing
if (! $transaction->getSampled()) {
return;
}

// Set transaction to context
TraceContext::setTransaction($transaction);

$sentry->setSpan($transaction);

$reqContext = new SpanContext();
$reqContext->setOp('request.received');
$requestContext = new SpanContext();
$requestContext->setOp('request.received');
// $reqContext->setDescription('#' . Coroutine::id());
$reqContext->setStartTimestamp(microtime(true));
$requestContext->setStartTimestamp(microtime(true));

$reqSpan = $transaction->startChild($reqContext);
TraceContext::setSpan($reqSpan);
$requestSpan = $transaction->startChild($requestContext);
TraceContext::setSpan($requestSpan);

$sentry->setSpan($reqSpan);
$sentry->setSpan($requestSpan);
}

private function finishTransaction(): void
Expand Down

0 comments on commit c7b1532

Please sign in to comment.