File tree 2 files changed +27
-8
lines changed
2 files changed +27
-8
lines changed Original file line number Diff line number Diff line change 12
12
use OpenTelemetry \API \Trace \StatusCode ;
13
13
use OpenTelemetry \Context \Context ;
14
14
use function OpenTelemetry \Instrumentation \hook ;
15
+ use OpenTelemetry \SDK \Common \Configuration \Configuration ;
15
16
use OpenTelemetry \SemConv \TraceAttributes ;
16
17
use Throwable ;
17
18
18
19
class ConsoleInstrumentation
19
20
{
20
21
public static function register (CachedInstrumentation $ instrumentation ): void
22
+ {
23
+ if (self ::shouldTraceCli ()) {
24
+ self ::hookConsoleKernel ($ instrumentation );
25
+ }
26
+
27
+ self ::hookCommandExecution ($ instrumentation );
28
+ }
29
+
30
+ private static function shouldTraceCli (): bool
31
+ {
32
+ return PHP_SAPI !== 'cli ' || Configuration::getBoolean ('OTEL_PHP_TRACE_CLI_ENABLED ' , false );
33
+ }
34
+
35
+ private static function hookConsoleKernel (CachedInstrumentation $ instrumentation ): void
21
36
{
22
37
hook (
23
38
Kernel::class,
@@ -58,7 +73,10 @@ public static function register(CachedInstrumentation $instrumentation): void
58
73
$ span ->end ();
59
74
}
60
75
);
76
+ }
61
77
78
+ private static function hookCommandExecution (CachedInstrumentation $ instrumentation ): void
79
+ {
62
80
hook (
63
81
Command::class,
64
82
'execute ' ,
Original file line number Diff line number Diff line change @@ -27,14 +27,15 @@ public function test_command_tracing(): void
27
27
*
28
28
* @see \Illuminate\Foundation\Console\OptimizeClearCommand::handle() for the additional commands/spans.
29
29
*/
30
- $ count = 8 ;
31
- $ this ->assertCount ($ count , $ this ->storage );
32
-
33
- $ span = $ this ->storage [--$ count ];
34
- $ this ->assertSame ('Artisan handler ' , $ span ->getName ());
35
-
36
- $ span = $ this ->storage [--$ count ];
37
- $ this ->assertSame ('Command optimize:clear ' , $ span ->getName ());
30
+ $ this ->assertCount (7 , $ this ->storage );
31
+
32
+ $ this ->assertSame ('Command event:clear ' , $ this ->storage [0 ]->getName ());
33
+ $ this ->assertSame ('Command view:clear ' , $ this ->storage [1 ]->getName ());
34
+ $ this ->assertSame ('Command cache:clear ' , $ this ->storage [2 ]->getName ());
35
+ $ this ->assertSame ('Command route:clear ' , $ this ->storage [3 ]->getName ());
36
+ $ this ->assertSame ('Command config:clear ' , $ this ->storage [4 ]->getName ());
37
+ $ this ->assertSame ('Command clear-compiled ' , $ this ->storage [5 ]->getName ());
38
+ $ this ->assertSame ('Command optimize:clear ' , $ this ->storage [6 ]->getName ());
38
39
}
39
40
40
41
private function kernel (): Kernel
You can’t perform that action at this time.
0 commit comments