Skip to content

Commit 906cbc5

Browse files
Fix PHP 8.4 deprecations (#2981)
* Fix PHP 8.4 deprecations In order to keep PHP 7.0 compatibility, I removed the implicitely nullable types instead of making them explicitely nullable. * Actually make the OpenTelemetry code properly 8.4 compatible. That code is not available on PHP 7.0 anyway. Signed-off-by: Bob Weinand <[email protected]> --------- Signed-off-by: Bob Weinand <[email protected]> Co-authored-by: Bob Weinand <[email protected]>
1 parent d25f2cc commit 906cbc5

File tree

11 files changed

+35
-34
lines changed

11 files changed

+35
-34
lines changed

src/DDTrace/Integrations/AMQP/AMQPIntegration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ public function setGenericTags(
486486
SpanData $span,
487487
string $name,
488488
string $spanKind,
489-
string $resourceDetail = null,
489+
$resourceDetail = null,
490490
$exception = null
491491
) {
492492
$span->name = "amqp.$name";

src/DDTrace/Integrations/CodeIgniter/V2/CodeIgniterIntegration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CodeIgniterIntegration extends Integration
1515
/**
1616
* Add instrumentation to CodeIgniter requests
1717
*/
18-
public function init(\CI_Router $router = null): int
18+
public function init($router = null): int
1919
{
2020
$integration = $this;
2121
$rootSpan = \DDTrace\root_span();

src/DDTrace/Integrations/Logs/LogsIntegration.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public static function laminasLogLevelToString(int $logLevel, string $fallback):
3838
}
3939

4040
public static function getPlaceholders(
41-
string $traceIdSubstitute = null,
42-
string $spanIdSubstitute = null
41+
$traceIdSubstitute = null,
42+
$spanIdSubstitute = null
4343
): array {
4444
$placeholders = [
4545
'%dd.trace_id%' => 'dd.trace_id="' . ($traceIdSubstitute ?? logs_correlation_trace_id()) . '"',
@@ -84,8 +84,8 @@ public static function messageContainsPlaceholders(string $message): bool
8484

8585
public static function appendTraceIdentifiersToMessage(
8686
string $message,
87-
string $traceIdSubstitute = null,
88-
string $spanIdSubstitute = null
87+
$traceIdSubstitute = null,
88+
$spanIdSubstitute = null
8989
): string {
9090
$placeholders = LogsIntegration::getPlaceholders($traceIdSubstitute, $spanIdSubstitute);
9191
LogsIntegration::replacePlaceholders($message, $placeholders);
@@ -108,20 +108,20 @@ public static function appendTraceIdentifiersToMessage(
108108

109109
public static function replacePlaceholders(
110110
string $message,
111-
array $placeholders = null,
112-
string $traceIdSubstitute = null,
113-
string $spanIdSubstitute = null
111+
$placeholders = null,
112+
$traceIdSubstitute = null,
113+
$spanIdSubstitute = null
114114
): string {
115115
return strtr(
116116
$message,
117-
$placeholders ? $placeholders : LogsIntegration::getPlaceholders($traceIdSubstitute, $spanIdSubstitute)
117+
$placeholders ?: LogsIntegration::getPlaceholders($traceIdSubstitute, $spanIdSubstitute)
118118
);
119119
}
120120

121121
public static function addTraceIdentifiersToContext(
122122
array $context,
123-
string $traceIdSubstitute = null,
124-
string $spanIdSubstitute = null
123+
$traceIdSubstitute = null,
124+
$spanIdSubstitute = null
125125
): array {
126126
if (!isset($context['dd.trace_id'])) {
127127
$context['dd.trace_id'] = $traceIdSubstitute ?? logs_correlation_trace_id();

src/DDTrace/Integrations/WordPress/WordPressIntegrationLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public static function setCommonTags(
118118
WordPressIntegration $integration,
119119
SpanData $span,
120120
string $name,
121-
string $resource = null
121+
$resource = null
122122
) {
123123
$span->name = $name;
124124
$span->resource = $resource ?: $name;

src/DDTrace/OpenTelemetry/Span.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use DDTrace\OpenTelemetry\Convention;
1313
use DDTrace\Util\ObjectKVStore;
1414
use OpenTelemetry\API\Trace as API;
15+
use OpenTelemetry\SDK\Trace\LinkInterface;
1516
use OpenTelemetry\API\Trace\SpanContextInterface;
1617
use OpenTelemetry\API\Trace\SpanInterface;
1718
use OpenTelemetry\Context\ContextInterface;
@@ -380,7 +381,7 @@ public function addLink(SpanContextInterface $context, iterable $attributes = []
380381
/**
381382
* @inheritDoc
382383
*/
383-
public function addEvent(string $name, iterable $attributes = [], int $timestamp = null): SpanInterface
384+
public function addEvent(string $name, iterable $attributes = [], $timestamp = null): SpanInterface
384385
{
385386
if (!$this->hasEnded()) {
386387
$this->span->events[] = new SpanEvent(
@@ -427,7 +428,7 @@ public function updateName(string $name): SpanInterface
427428
/**
428429
* @inheritDoc
429430
*/
430-
public function setStatus(string $code, string $description = null): SpanInterface
431+
public function setStatus(string $code, ?string $description = null): SpanInterface
431432
{
432433
if ($this->hasEnded()) {
433434
return $this;
@@ -459,7 +460,7 @@ public function setStatus(string $code, string $description = null): SpanInterfa
459460
/**
460461
* @inheritDoc
461462
*/
462-
public function end(int $endEpochNanos = null): void
463+
public function end(?int $endEpochNanos = null): void
463464
{
464465
if ($this->hasEnded()) {
465466
return;
@@ -472,7 +473,7 @@ public function end(int $endEpochNanos = null): void
472473
$this->spanProcessor->onEnd($this);
473474
}
474475

475-
public function endOTelSpan(int $endEpochNanos = null): void
476+
public function endOTelSpan(?int $endEpochNanos = null): void
476477
{
477478
if ($this->hasEnded()) {
478479
return;
@@ -572,7 +573,7 @@ private function updateSpanEvents()
572573
$this->totalRecordedEvents = count($otel);
573574
}
574575

575-
private function createAndSaveSpanLink(SpanContextInterface $context, iterable $attributes = [], LinkInterface $link = null)
576+
private function createAndSaveSpanLink(SpanContextInterface $context, iterable $attributes = [], ?LinkInterface $link = null)
576577
{
577578
$spanLink = new SpanLink();
578579
$spanLink->traceId = $context->getTraceId();

src/DDTrace/OpenTelemetry/SpanBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,18 @@ public function addLink(SpanContextInterface $context, iterable $attributes = []
9696
return $this;
9797
}
9898

99-
public function addEvent(string $name, iterable $attributes = [], int $timestamp = null): SpanBuilderInterface
99+
public function addEvent(string $name, iterable $attributes = [], ?int $timestamp = null): SpanBuilderInterface
100100
{
101101
$this->events[] = new Event(
102-
$name,
102+
$name,
103103
$timestamp ?? (int)(microtime(true) * 1e9),
104104
$this->tracerSharedState
105105
->getSpanLimits()
106106
->getEventAttributesFactory()
107107
->builder($attributes)
108108
->build(),
109109
);
110-
110+
111111
return $this;
112112
}
113113

src/DDTrace/OpenTracer/Tracer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final class Tracer implements OTTracer
2828
/**
2929
* @param TracerInterface|null $tracer
3030
*/
31-
public function __construct(TracerInterface $tracer = null)
31+
public function __construct($tracer = null)
3232
{
3333
$this->tracer = $tracer ?: GlobalTracer::get();
3434
}
@@ -39,7 +39,7 @@ public function __construct(TracerInterface $tracer = null)
3939
* @param array $config
4040
* @return self
4141
*/
42-
public static function make(Transport $transport = null, array $propagators = null, array $config = [])
42+
public static function make($transport = null, $propagators = null, array $config = [])
4343
{
4444
return new self(
4545
new DDTracer($transport, $propagators, $config)

src/DDTrace/OpenTracer1/Tracer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class Tracer implements OTTracer
3030
/**
3131
* @param TracerInterface|null $tracer
3232
*/
33-
public function __construct(TracerInterface $tracer = null)
33+
public function __construct($tracer = null)
3434
{
3535
$this->tracer = $tracer ?: GlobalTracer::get();
3636
}
@@ -41,7 +41,7 @@ public function __construct(TracerInterface $tracer = null)
4141
* @param array $config
4242
* @return self
4343
*/
44-
public static function make(Transport $transport = null, array $propagators = null, array $config = [])
44+
public static function make($transport = null, $propagators = null, array $config = [])
4545
{
4646
return new self(
4747
new DDTracer($transport, $propagators, $config)

src/DDTrace/ScopeManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class ScopeManager implements ScopeManagerInterface
2626
*/
2727
private $rootContext;
2828

29-
public function __construct(SpanContext $rootContext = null)
29+
public function __construct($rootContext = null)
3030
{
3131
$this->rootContext = $rootContext;
3232
}

src/DDTrace/Tracer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ final class Tracer implements TracerInterface
7979
* @param Propagator[] $propagators
8080
* @param array $config
8181
*/
82-
public function __construct(Transport $transport = null, array $propagators = null, array $config = [])
82+
public function __construct($transport = null, $propagators = null, array $config = [])
8383
{
8484
$this->transport = $transport ?: new Internal();
8585
$textMapPropagator = new TextMap($this);

src/ddtrace_php_api.stubs.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function addLink(\OpenTelemetry\API\Trace\SpanContextInterface $context,
156156
/**
157157
* @inheritDoc
158158
*/
159-
public function addEvent(string $name, iterable $attributes = [], int $timestamp = null) : \OpenTelemetry\API\Trace\SpanInterface
159+
public function addEvent(string $name, iterable $attributes = [], $timestamp = null) : \OpenTelemetry\API\Trace\SpanInterface
160160
{
161161
}
162162
/**
@@ -174,16 +174,16 @@ public function updateName(string $name) : \OpenTelemetry\API\Trace\SpanInterfac
174174
/**
175175
* @inheritDoc
176176
*/
177-
public function setStatus(string $code, string $description = null) : \OpenTelemetry\API\Trace\SpanInterface
177+
public function setStatus(string $code, ?string $description = null) : \OpenTelemetry\API\Trace\SpanInterface
178178
{
179179
}
180180
/**
181181
* @inheritDoc
182182
*/
183-
public function end(int $endEpochNanos = null) : void
183+
public function end(?int $endEpochNanos = null) : void
184184
{
185185
}
186-
public function endOTelSpan(int $endEpochNanos = null) : void
186+
public function endOTelSpan(?int $endEpochNanos = null) : void
187187
{
188188
}
189189
public function getResource() : \OpenTelemetry\SDK\Resource\ResourceInfo
@@ -212,7 +212,7 @@ public function setParent($context) : \OpenTelemetry\API\Trace\SpanBuilderInterf
212212
public function addLink(\OpenTelemetry\API\Trace\SpanContextInterface $context, iterable $attributes = []) : \OpenTelemetry\API\Trace\SpanBuilderInterface
213213
{
214214
}
215-
public function addEvent(string $name, iterable $attributes = [], int $timestamp = null) : \OpenTelemetry\API\Trace\SpanBuilderInterface
215+
public function addEvent(string $name, iterable $attributes = [], ?int $timestamp = null) : \OpenTelemetry\API\Trace\SpanBuilderInterface
216216
{
217217
}
218218
public function recordException(\Throwable $exception, iterable $attributes = []) : \OpenTelemetry\API\Trace\SpanBuilderInterface
@@ -506,7 +506,7 @@ public function close();
506506
namespace DDTrace {
507507
final class ScopeManager implements \DDTrace\Contracts\ScopeManager
508508
{
509-
public function __construct(\DDTrace\SpanContext $rootContext = null)
509+
public function __construct($rootContext = null)
510510
{
511511
}
512512
/**
@@ -1341,7 +1341,7 @@ final class Tracer implements \DDTrace\Contracts\Tracer
13411341
* @param Propagator[] $propagators
13421342
* @param array $config
13431343
*/
1344-
public function __construct(\DDTrace\Transport $transport = null, array $propagators = null, array $config = [])
1344+
public function __construct($transport = null, $propagators = null, array $config = [])
13451345
{
13461346
}
13471347
public function limited()

0 commit comments

Comments
 (0)