This repository was archived by the owner on Dec 5, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +63
-0
lines changed
Expand file tree Collapse file tree 2 files changed +63
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments