traceId = $traceId; $this->spanId = $spanId; $this->parentSpanId = $parentSpanId; $this->name = $name; $this->sampled = $sampled; } public function setEndEpochNanos( int $endEpochNanos ): void { $this->endEpochNanos = $endEpochNanos; } public function setStartEpochNanos( int $startEpochNanos ): void { $this->startEpochNanos = $startEpochNanos; } public function setSpanKind( int $spanKind ): void { $this->spanKind = $spanKind; } public function setAttributes( array $attributes ): void { $this->attributes = $attributes; } public function isSampled(): bool { return $this->sampled; } public function getSpanId(): string { return $this->spanId; } public function getTraceId(): string { return $this->traceId; } public function getParentSpanId(): ?string { return $this->parentSpanId; } public function wasStarted(): bool { return $this->startEpochNanos !== null; } public function wasEnded(): bool { return $this->endEpochNanos !== null; } public function jsonSerialize(): array { $json = [ 'traceId' => $this->traceId, 'parentSpanId' => $this->parentSpanId, 'spanId' => $this->spanId, 'name' => $this->name, 'startTimeUnixNano' => $this->startEpochNanos, 'endTimeUnixNano' => $this->endEpochNanos, 'kind' => $this->spanKind ]; if ( $this->attributes ) { $json['attributes'] = OtlpSerializer::serializeKeyValuePairs( $this->attributes ); } return $json; } /** * Check whether the given SpanContext belongs to the same span. * * @param SpanContext|null $other * @return bool */ public function equals( ?SpanContext $other ): bool { if ( $other === null ) { return false; } return $other->spanId === $this->spanId; } }