Skip to content

Commit

Permalink
fix: php 7.4 unpacking issue
Browse files Browse the repository at this point in the history
  • Loading branch information
PROFeNoM committed Sep 16, 2024
1 parent ae66da9 commit 22a2913
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/DDTrace/OpenTelemetry/Span.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,24 +225,32 @@ public function toSpanData(): SpanDataInterface
$this->updateSpanLinks();
$this->updateSpanEvents();

$spanData = [
'span' => $this,
'name' => $this->getName(),
'links' => $this->links,
'events' => $this->events,
'attributes' => Attributes::create(array_merge($this->span->meta, $this->span->metrics)),
'totalRecordedEvents' => $this->totalRecordedEvents,
'status' => StatusData::create($this->status->getCode(), $this->status->getDescription()),
'endEpochNanos' => $hasEnded ? $this->span->getStartTime() + $this->span->getDuration() : 0,
'hasEnded' => $this->hasEnded(),
];

// Workaround for a breaking change introduced in open-telemetry/api 1.1.0
if (in_array('addLink', get_class_methods(SpanInterface::class))) {
$spanData['totalRecordedLinks'] = $this->totalRecordedLinks;
return new ImmutableSpan(
$this,
$this->getName(),
$this->links,
$this->events,
Attributes::create(array_merge($this->span->meta, $this->span->metrics)),
$this->totalRecordedEvents,
$this->totalRecordedLinks,
StatusData::create($this->status->getCode(), $this->status->getDescription()),
$hasEnded ? $this->span->getStartTime() + $this->span->getDuration() : 0,
$this->hasEnded(),
);
} else {
return new ImmutableSpan(
$this,
$this->getName(),
$this->links,
$this->events,
Attributes::create(array_merge($this->span->meta, $this->span->metrics)),
$this->totalRecordedEvents,
StatusData::create($this->status->getCode(), $this->status->getDescription()),
$hasEnded ? $this->span->getStartTime() + $this->span->getDuration() : 0,
$this->hasEnded(),
);
}

return new ImmutableSpan(...$spanData);
}

/**
Expand Down

0 comments on commit 22a2913

Please sign in to comment.