Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Support/JaegerDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ public static function traceIdDecoder(string $traceId): string
if (strlen($traceId) == 32 || !is_numeric($traceId)) {
return $traceId;
}

return substr($traceId, 0, 16) . substr($traceId, -16, 16);
$hiLen = strlen($traceId) - 16;
$newTraceId = substr($traceId, 0, $hiLen) . substr($traceId, $hiLen);
return str_pad($newTraceId, 32, '0', STR_PAD_LEFT);
}

public static function spanIdDecoder(string $spanId): string
Expand Down
5 changes: 5 additions & 0 deletions src/TracerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public static function setTracer(Tracer $tracer): Tracer
return Context::set(self::TRACER, $tracer);
}

public static function hasTracer(): bool
{
return Context::has(self::TRACER);
}

public static function getTracer(): Tracer
{
return Context::getOrSet(self::TRACER, fn () => make(Tracer::class));
Expand Down
8 changes: 7 additions & 1 deletion src/TracerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class TracerFactory
*/
public function __invoke(ContainerInterface $container): Tracer
{
if(TracerContext::hasTracer()) {
return TracerContext::getTracer();
}

$config = $container->get(ConfigInterface::class);
$name = $config->get('opentracing.default');

Expand All @@ -51,6 +55,8 @@ public function __invoke(ContainerInterface $container): Tracer
);
}

return $factory->make($name);
$tracer = $factory->make($name);
TracerContext::setTracer($tracer);
return TracerContext::getTracer();
}
}