Skip to content

Commit

Permalink
Merge pull request #4 from chocofamilyme/fix.span_stop_timer
Browse files Browse the repository at this point in the history
Исправил команду span, не правильно считался timer
  • Loading branch information
AidynMakhataev authored Jul 7, 2021
2 parents 3001b5e + 7c25cf2 commit 6d552e7
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions src/Jaeger.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,15 @@ public function stop(string $operationName, array $tags = []): void
return ;
}

foreach ($this->spans as $index => $span) {
/** @var Span $span */
if (strcmp($span->getOperationName(), $operationName) === 0) {
foreach ($tags as $key => $value) {
$span->setTag($key, $value);
}
$span->finish();
$this->spans->offsetUnset($index);

break;
$span = $this->spans->top();

/** @var Span $span */
if (strcmp($span->getOperationName(), $operationName) === 0) {
foreach ($tags as $key => $value) {
$span->setTag($key, $value);
}
$span->finish();
$this->spans->pop();
}
}

Expand Down Expand Up @@ -154,4 +152,31 @@ private function startSpan(string $operationName, SpanContext $context = null):

return $this->tracer->startSpan($operationName, $options);
}

public function getTraceId(): ?string
{
if (false === $this->spans->isEmpty()) {
$spanParent = $this->spans->top();

if ($spanParent instanceof \Jaeger\Span) {
/** @psalm-suppress UndefinedInterfaceMethod */
return $spanParent->getContext()->traceIdLowToString();
}
}

return null;
}

public function getRootTraceId(): ?string
{
$serverSpan = $this->serverContext;

if ($serverSpan instanceof \Jaeger\SpanContext) {
return $serverSpan->traceIdLowToString();
}

return null;
}


}

0 comments on commit 6d552e7

Please sign in to comment.