Skip to content

Commit

Permalink
Actually make the OpenTelemetry code properly 8.4 compatible.
Browse files Browse the repository at this point in the history
That code is not available on PHP 7.0 anyway.

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
  • Loading branch information
bwoebi committed Jan 6, 2025
1 parent aa32943 commit 2aaaa29
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/DDTrace/Integrations/Logs/LogsIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static function replacePlaceholders(
): string {
return strtr(
$message,
$placeholders ? $placeholders : LogsIntegration::getPlaceholders($traceIdSubstitute, $spanIdSubstitute)
$placeholders ?: LogsIntegration::getPlaceholders($traceIdSubstitute, $spanIdSubstitute)
);
}

Expand Down
9 changes: 5 additions & 4 deletions src/DDTrace/OpenTelemetry/Span.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/DDTrace/OpenTelemetry/SpanBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,18 @@ 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()
->getEventAttributesFactory()
->builder($attributes)
->build(),
);

return $this;
}

Expand Down
8 changes: 4 additions & 4 deletions src/ddtrace_php_api.stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,16 @@ public function updateName(string $name) : \OpenTelemetry\API\Trace\SpanInterfac
/**
* @inheritDoc
*/
public function setStatus(string $code, $description = null) : \OpenTelemetry\API\Trace\SpanInterface
public function setStatus(string $code, ?string $description = null) : \OpenTelemetry\API\Trace\SpanInterface
{
}
/**
* @inheritDoc
*/
public function end($endEpochNanos = null) : void
public function end(?int $endEpochNanos = null) : void
{
}
public function endOTelSpan($endEpochNanos = null) : void
public function endOTelSpan(?int $endEpochNanos = null) : void
{
}
public function getResource() : \OpenTelemetry\SDK\Resource\ResourceInfo
Expand Down Expand Up @@ -212,7 +212,7 @@ public function setParent($context) : \OpenTelemetry\API\Trace\SpanBuilderInterf
public function addLink(\OpenTelemetry\API\Trace\SpanContextInterface $context, iterable $attributes = []) : \OpenTelemetry\API\Trace\SpanBuilderInterface
{
}
public function addEvent(string $name, iterable $attributes = [], $timestamp = null) : \OpenTelemetry\API\Trace\SpanBuilderInterface
public function addEvent(string $name, iterable $attributes = [], ?int $timestamp = null) : \OpenTelemetry\API\Trace\SpanBuilderInterface
{
}
public function recordException(\Throwable $exception, iterable $attributes = []) : \OpenTelemetry\API\Trace\SpanBuilderInterface
Expand Down

0 comments on commit 2aaaa29

Please sign in to comment.