Skip to content

Commit a93b6dd

Browse files
Laravel: decoupled from SDK ClockFactory (& some linting) (#211)
* Laravel: `open-telemetry/sdk` dependency required by QueryWatcher. Use 1.0 stable release for `open-telemetry/api`. * Laravel: removed unused `laravel/sail` & `laravel/sanctum` from dev dependencies. * Laravel: restored dev dependency `open-telemetry/sdk` but decoupled from the runtime dependency on the ClockFactory.
1 parent cfa4839 commit a93b6dd

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
"ext-json": "*",
1313
"ext-opentelemetry": "*",
1414
"laravel/framework": ">=6.0",
15-
"open-telemetry/api": "^1.0.0beta10",
15+
"open-telemetry/api": "^1.0",
1616
"open-telemetry/sem-conv": "^1.22"
1717
},
1818
"require-dev": {
1919
"friendsofphp/php-cs-fixer": "^3",
2020
"guzzlehttp/guzzle": "*",
21-
"laravel/sail": "*",
22-
"laravel/sanctum": "*",
2321
"laravel/tinker": "*",
2422
"nunomaduro/collision": "*",
2523
"open-telemetry/sdk": "^1.0",

src/Watchers/QueryWatcher.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Illuminate\Support\Str;
1010
use OpenTelemetry\API\Instrumentation\CachedInstrumentation;
1111
use OpenTelemetry\API\Trace\SpanKind;
12-
use OpenTelemetry\SDK\Common\Time\ClockFactory;
1312
use OpenTelemetry\SemConv\TraceAttributes;
1413

1514
class QueryWatcher extends Watcher
@@ -31,7 +30,7 @@ public function register(Application $app): void
3130
/** @psalm-suppress UndefinedThisPropertyFetch */
3231
public function recordQuery(QueryExecuted $query): void
3332
{
34-
$nowInNs = ClockFactory::getDefault()->now();
33+
$nowInNs = (int) (microtime(true) * 1E9);
3534

3635
$operationName = Str::upper(Str::before($query->sql, ' '));
3736
if (! in_array($operationName, ['SELECT', 'INSERT', 'UPDATE', 'DELETE'])) {
@@ -58,6 +57,6 @@ public function recordQuery(QueryExecuted $query): void
5857

5958
private function calculateQueryStartTime(int $nowInNs, float $queryTimeMs): int
6059
{
61-
return (int) ($nowInNs - ($queryTimeMs * 1000000));
60+
return (int) ($nowInNs - ($queryTimeMs * 1E6));
6261
}
6362
}

0 commit comments

Comments
 (0)