Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit 52994ea

Browse files
committed
fix: bugfix
1 parent fe3ae1b commit 52994ea

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/Support/CarbonClock.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Overtrue\LaravelOpenTelemetry\Support;
4+
5+
use Carbon\Carbon;
6+
use Carbon\CarbonImmutable;
7+
use Carbon\CarbonInterface;
8+
use OpenTelemetry\SDK\Common\Time\ClockInterface;
9+
use OpenTelemetry\SDK\Common\Time\SystemClock;
10+
11+
class CarbonClock implements ClockInterface
12+
{
13+
protected SystemClock $systemClock;
14+
15+
public function __construct()
16+
{
17+
$this->systemClock = new SystemClock();
18+
}
19+
20+
public function now(): int
21+
{
22+
if (Carbon::hasTestNow()) {
23+
return static::carbonToNanos(CarbonImmutable::now());
24+
}
25+
26+
return $this->systemClock->now();
27+
}
28+
29+
public static function carbonToNanos(CarbonInterface $carbon): int
30+
{
31+
return (int) $carbon->getPreciseTimestamp(6) * 1000;
32+
}
33+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Overtrue\LaravelOpenTelemetry\Support;
6+
7+
use Illuminate\Http\Response;
8+
use OpenTelemetry\Context\Propagation\PropagationSetterInterface;
9+
10+
use function assert;
11+
12+
/**
13+
* @internal
14+
*/
15+
class ResponsePropagationSetter implements PropagationSetterInterface
16+
{
17+
public static function instance(): self
18+
{
19+
static $instance;
20+
21+
return $instance ??= new self();
22+
}
23+
24+
public function set(&$carrier, string $key, string $value): void
25+
{
26+
assert($carrier instanceof Response);
27+
28+
$carrier->headers->set($key, $value);
29+
}
30+
}

0 commit comments

Comments
 (0)