From 62ba353db50fe2a4805cdb36bc40b45f287669bc Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Mon, 6 Jan 2025 16:47:23 +0100 Subject: [PATCH] Actually make the OpenTelemetry code properly 8.4 compatible. That code is not available on PHP 7.0 anyway. --- src/DDTrace/Integrations/Logs/LogsIntegration.php | 2 +- src/DDTrace/OpenTelemetry/Span.php | 9 +++++---- src/DDTrace/OpenTelemetry/SpanBuilder.php | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/DDTrace/Integrations/Logs/LogsIntegration.php b/src/DDTrace/Integrations/Logs/LogsIntegration.php index 0324823c67..c729fa44db 100644 --- a/src/DDTrace/Integrations/Logs/LogsIntegration.php +++ b/src/DDTrace/Integrations/Logs/LogsIntegration.php @@ -114,7 +114,7 @@ public static function replacePlaceholders( ): string { return strtr( $message, - $placeholders ? $placeholders : LogsIntegration::getPlaceholders($traceIdSubstitute, $spanIdSubstitute) + $placeholders ?: LogsIntegration::getPlaceholders($traceIdSubstitute, $spanIdSubstitute) ); } diff --git a/src/DDTrace/OpenTelemetry/Span.php b/src/DDTrace/OpenTelemetry/Span.php index 1d2a4def3b..6d2764342f 100644 --- a/src/DDTrace/OpenTelemetry/Span.php +++ b/src/DDTrace/OpenTelemetry/Span.php @@ -20,6 +20,7 @@ use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeInterface; use OpenTelemetry\SDK\Common\Time\ClockFactory; use OpenTelemetry\SDK\Resource\ResourceInfo; +use Psr\Link\LinkInterface; use Throwable; use function DDTrace\close_span; use function DDTrace\switch_stack; @@ -427,7 +428,7 @@ public function updateName(string $name): SpanInterface /** * @inheritDoc */ - public function setStatus(string $code, $description = null): SpanInterface + public function setStatus(string $code, ?string $description = null): SpanInterface { if ($this->hasEnded()) { return $this; @@ -459,7 +460,7 @@ public function setStatus(string $code, $description = null): SpanInterface /** * @inheritDoc */ - public function end($endEpochNanos = null): void + public function end(?int $endEpochNanos = null): void { if ($this->hasEnded()) { return; @@ -472,7 +473,7 @@ public function end($endEpochNanos = null): void $this->spanProcessor->onEnd($this); } - public function endOTelSpan($endEpochNanos = null): void + public function endOTelSpan(?int $endEpochNanos = null): void { if ($this->hasEnded()) { return; @@ -572,7 +573,7 @@ private function updateSpanEvents() $this->totalRecordedEvents = count($otel); } - private function createAndSaveSpanLink(SpanContextInterface $context, iterable $attributes = [], $link = null) + private function createAndSaveSpanLink(SpanContextInterface $context, iterable $attributes = [], ?LinkInterface $link = null) { $spanLink = new SpanLink(); $spanLink->traceId = $context->getTraceId(); diff --git a/src/DDTrace/OpenTelemetry/SpanBuilder.php b/src/DDTrace/OpenTelemetry/SpanBuilder.php index f5da050250..6e87eb896a 100644 --- a/src/DDTrace/OpenTelemetry/SpanBuilder.php +++ b/src/DDTrace/OpenTelemetry/SpanBuilder.php @@ -96,10 +96,10 @@ public function addLink(SpanContextInterface $context, iterable $attributes = [] return $this; } - public function addEvent(string $name, iterable $attributes = [], $timestamp = null): SpanBuilderInterface + public function addEvent(string $name, iterable $attributes = [], ?int $timestamp = null): SpanBuilderInterface { $this->events[] = new Event( - $name, + $name, $timestamp ?? (int)(microtime(true) * 1e9), $this->tracerSharedState ->getSpanLimits() @@ -107,7 +107,7 @@ public function addEvent(string $name, iterable $attributes = [], $timestamp = n ->builder($attributes) ->build(), ); - + return $this; }