phpkin
phpkin copied to clipboard
the tracer default span's id may equal it parent id
in tracer.php
$span = new Span(
TracerInfo::getTraceSpanId(),
$this->name,
new AnnotationBlock(
$this->endpoint,
$this->startTimestamp,
zipkin_timestamp(),
AnnotationBlock::SERVER
)
);
in span.php
$this->setIdentifier('parentId', $parentId, [TracerInfo::class, 'getTraceSpanId']);
when tracer type is backend, the tracer default span's id equal parentId. Is it right ?
I've confirmed this is likely a bug/design issue. As you pointed out, the root Span created in tracer.php:126 does not have a concept of which span is the parent span. line 135 should allow reporting Metadata and a parent trace id. My work around is kind of gross because a proper fix would introduce breaking changes.
@whitemerry can you confirm? Can you offer a cleaner solution that I'm not seeing?
class FixedTracer extends Tracer
{
/** @var SpanContext $context */
private $context;
/**
* @param SpanContext $context
* @return $this
*/
public function setSpanContext(SpanContext $context)
{
$this->context = $context;
return $this;
}
/**
* Save trace
* @override
*/
public function trace()
{
$this->traceRoot(null);
}
public function traceRoot(Metadata $metadata = null)
{
if (!TracerInfo::isSampled()) {
return;
}
$rootSpan = new Span(
new SpanIdentifier($this->context->getSpanId()),
$this->name,
new AnnotationBlock(
$this->endpoint,
$this->startTimestamp,
zipkin_timestamp(),
AnnotationBlock::SERVER
),
$metadata,
new TraceIdentifier($this->context->getTraceId()),
new SpanIdentifier($this->context->getParentSpanId())
);
$this->addSpan($rootSpan);
$this->logger->trace($this->spans);
}
}
I fix this problem in this way.
public function trace()
{
if (!TracerInfo::isSampled()) {
return;
}
$unsetParentId = true;
if ($this->profile === static::BACKEND && !$this->unsetParentIdForBackend) {
$unsetParentId = false;
}
if ($this->profile == Tracer::FRONTEND) {
$this->addTraceSpan($unsetParentId);
}
$this->logger->trace($this->spans);
}
when profile is FRONTEND, I do not add a root Span .