@@ -226,14 +226,15 @@ protected function write(LogRecord $record): void
226226 public function test_logs_after_span_completion_have_no_trace_context (): void
227227 {
228228 $ context = TelemetryTestContext::createWithTracing ();
229- static ::assertNotNull ($ context ->tracer );
229+ $ tracer = $ context ->tracer ;
230+ static ::assertNotNull ($ tracer );
230231
231232 $ monolog = new MonologLogger ('application ' );
232233 $ monolog ->pushHandler (telemetry_handler ($ context ->logger ));
233234
234- $ span = $ context -> tracer ->span ('short-operation ' );
235+ $ span = $ tracer ->span ('short-operation ' );
235236 $ monolog ->info ('Inside span ' );
236- $ context -> tracer ->complete ($ span );
237+ $ tracer ->complete ($ span );
237238
238239 $ monolog ->info ('After span completed ' );
239240
@@ -247,34 +248,37 @@ public function test_logs_after_span_completion_have_no_trace_context(): void
247248 public function test_logs_within_active_span_include_trace_and_span_ids (): void
248249 {
249250 $ context = TelemetryTestContext::createWithTracing ();
250- static ::assertNotNull ($ context ->tracer );
251+ $ tracer = $ context ->tracer ;
252+ static ::assertNotNull ($ tracer );
251253
252254 $ monolog = new MonologLogger ('application ' );
253255 $ monolog ->pushHandler (telemetry_handler ($ context ->logger ));
254256
255- $ span = $ context -> tracer ->span ('process-order ' );
257+ $ span = $ tracer ->span ('process-order ' );
256258
257259 $ monolog ->info ('Processing order ' , ['order_id ' => 123 ]);
258260 $ monolog ->warning ('Low inventory ' , ['product_id ' => 456 ]);
259261
260- $ context -> tracer ->complete ($ span );
262+ $ tracer ->complete ($ span );
261263
262264 $ entries = $ context ->processor ->entries ();
263265 static ::assertCount (2 , $ entries );
264266
265- static ::assertNotNull ($ entries [0 ]->spanContext );
266- static ::assertNotNull ($ entries [0 ]->spanContext ->traceId );
267- static ::assertNotNull ($ entries [0 ]->spanContext ->spanId );
267+ $ spanContext0 = $ entries [0 ]->spanContext ;
268+ $ spanContext1 = $ entries [1 ]->spanContext ;
269+ static ::assertNotNull ($ spanContext0 );
270+ static ::assertNotNull ($ spanContext0 ->traceId );
271+ static ::assertNotNull ($ spanContext0 ->spanId );
268272
269- static ::assertNotNull ($ entries [ 1 ]-> spanContext );
273+ static ::assertNotNull ($ spanContext1 );
270274 static ::assertSame (
271- $ entries [ 0 ]-> spanContext ->traceId ->toHex (),
272- $ entries [ 1 ]-> spanContext ->traceId ->toHex (),
275+ $ spanContext0 ->traceId ->toHex (),
276+ $ spanContext1 ->traceId ->toHex (),
273277 'Both logs should share the same trace_id ' ,
274278 );
275279 static ::assertSame (
276- $ entries [ 0 ]-> spanContext ->spanId ->toHex (),
277- $ entries [ 1 ]-> spanContext ->spanId ->toHex (),
280+ $ spanContext0 ->spanId ->toHex (),
281+ $ spanContext1 ->spanId ->toHex (),
278282 'Both logs should share the same span_id ' ,
279283 );
280284 }
@@ -425,32 +429,36 @@ public function test_nested_data_structures_in_context(): void
425429 public function test_nested_spans_propagate_child_span_id_to_logs (): void
426430 {
427431 $ context = TelemetryTestContext::createWithTracing ();
428- static ::assertNotNull ($ context ->tracer );
432+ $ tracer = $ context ->tracer ;
433+ static ::assertNotNull ($ tracer );
429434
430435 $ monolog = new MonologLogger ('application ' );
431436 $ monolog ->pushHandler (telemetry_handler ($ context ->logger ));
432437
433- $ parentSpan = $ context -> tracer ->span ('parent-operation ' );
438+ $ parentSpan = $ tracer ->span ('parent-operation ' );
434439 $ monolog ->info ('In parent span ' );
435440
436- $ childSpan = $ context -> tracer ->span ('child-operation ' );
441+ $ childSpan = $ tracer ->span ('child-operation ' );
437442 $ monolog ->info ('In child span ' );
438443
439- $ context -> tracer ->complete ($ childSpan );
444+ $ tracer ->complete ($ childSpan );
440445 $ monolog ->info ('Back in parent span ' );
441446
442- $ context -> tracer ->complete ($ parentSpan );
447+ $ tracer ->complete ($ parentSpan );
443448
444449 $ entries = $ context ->processor ->entries ();
445450 static ::assertCount (3 , $ entries );
446451
447- $ parentSpanId = $ entries [0 ]->spanContext ?->spanId->toHex ();
448- $ childSpanId = $ entries [1 ]->spanContext ?->spanId->toHex ();
449- $ backInParentSpanId = $ entries [2 ]->spanContext ?->spanId->toHex ();
452+ $ spanContext0 = $ entries [0 ]->spanContext ;
453+ $ spanContext1 = $ entries [1 ]->spanContext ;
454+ $ spanContext2 = $ entries [2 ]->spanContext ;
455+ static ::assertNotNull ($ spanContext0 );
456+ static ::assertNotNull ($ spanContext1 );
457+ static ::assertNotNull ($ spanContext2 );
450458
451- static :: assertNotNull ( $ parentSpanId );
452- static :: assertNotNull ( $ childSpanId );
453- static :: assertNotNull ( $ backInParentSpanId );
459+ $ parentSpanId = $ spanContext0 -> spanId -> toHex ( );
460+ $ childSpanId = $ spanContext1 -> spanId -> toHex ( );
461+ $ backInParentSpanId = $ spanContext2 -> spanId -> toHex ( );
454462
455463 static ::assertNotSame ($ parentSpanId , $ childSpanId , 'Child span should have different span_id ' );
456464 static ::assertSame (
@@ -460,13 +468,13 @@ public function test_nested_spans_propagate_child_span_id_to_logs(): void
460468 );
461469
462470 static ::assertSame (
463- $ entries [ 0 ]-> spanContext ->traceId ->toHex (),
464- $ entries [ 1 ]-> spanContext ->traceId ->toHex (),
471+ $ spanContext0 ->traceId ->toHex (),
472+ $ spanContext1 ->traceId ->toHex (),
465473 'All logs should share the same trace_id ' ,
466474 );
467475 static ::assertSame (
468- $ entries [ 1 ]-> spanContext ->traceId ->toHex (),
469- $ entries [ 2 ]-> spanContext ->traceId ->toHex (),
476+ $ spanContext1 ->traceId ->toHex (),
477+ $ spanContext2 ->traceId ->toHex (),
470478 'All logs should share the same trace_id ' ,
471479 );
472480 }
0 commit comments