Skip to content

Commit

Permalink
use a local const for grpc time conversions (#1505)
Browse files Browse the repository at this point in the history
using a newly-added const in ClockInterface breaks things for some older PHP versions, so
lets use a local const for now
  • Loading branch information
brettmc authored Feb 9, 2025
1 parent 66c8ce8 commit 8316c50
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/Contrib/Grpc/GrpcTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use const Grpc\OP_SEND_MESSAGE;
use const Grpc\STATUS_OK;
use Grpc\Timeval;
use OpenTelemetry\API\Common\Time\ClockInterface;
use OpenTelemetry\Contrib\Otlp\ContentTypes;
use OpenTelemetry\SDK\Common\Export\TransportInterface;
use OpenTelemetry\SDK\Common\Future\CancellationInterface;
Expand All @@ -36,10 +35,11 @@
*/
final class GrpcTransport implements TransportInterface
{
private const MICROS_PER_MILLISECOND = 1_000;
private readonly array $metadata;
private readonly Channel $channel;
private bool $closed = false;
private Timeval $exportTimeout;
private readonly Timeval $exportTimeout;

public function __construct(
string $endpoint,
Expand All @@ -50,7 +50,7 @@ public function __construct(
) {
$this->channel = new Channel($endpoint, $opts);
$this->metadata = $this->formatMetadata(array_change_key_case($headers));
$this->exportTimeout = new Timeval($timeoutMillis * ClockInterface::MICROS_PER_MILLISECOND);
$this->exportTimeout = new Timeval($timeoutMillis * self::MICROS_PER_MILLISECOND);
}

public function contentType(): string
Expand Down
9 changes: 5 additions & 4 deletions src/Contrib/Grpc/GrpcTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use InvalidArgumentException;
use function json_encode;
use OpenTelemetry\API\Behavior\LogsMessagesTrait;
use OpenTelemetry\API\Common\Time\ClockInterface;
use OpenTelemetry\Contrib\Otlp\ContentTypes;
use OpenTelemetry\SDK\Common\Export\TransportFactoryInterface;
use OpenTelemetry\SDK\Common\Export\TransportInterface;
Expand All @@ -25,6 +24,8 @@ final class GrpcTransportFactory implements TransportFactoryInterface
{
use LogsMessagesTrait;

private const MILLIS_PER_SECOND = 1_000;

/**
* @psalm-param "application/x-protobuf" $contentType
* @psalm-return TransportInterface<"application/x-protobuf">
Expand Down Expand Up @@ -82,7 +83,7 @@ public function create(
$opts,
$method,
$headers,
(int) ($timeout * ClockInterface::MILLIS_PER_SECOND),
(int) ($timeout * self::MILLIS_PER_SECOND),
);
}

Expand Down Expand Up @@ -119,8 +120,8 @@ private static function createOpts(
],
'retryPolicy' => [
'maxAttempts' => $maxRetries,
'initialBackoff' => sprintf('%0.3fs', $retryDelay / ClockInterface::MILLIS_PER_SECOND),
'maxBackoff' => sprintf('%0.3fs', ($retryDelay << $maxRetries - 1) / ClockInterface::MILLIS_PER_SECOND),
'initialBackoff' => sprintf('%0.3fs', $retryDelay / self::MILLIS_PER_SECOND),
'maxBackoff' => sprintf('%0.3fs', ($retryDelay << $maxRetries - 1) / self::MILLIS_PER_SECOND),
'backoffMultiplier' => 2,
'retryableStatusCodes' => [
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlpgrpc-response
Expand Down

0 comments on commit 8316c50

Please sign in to comment.