1111use OpenTelemetry \API \Trace \TraceState ;
1212use OpenTelemetry \Context \Context ;
1313use OpenTelemetry \Context \ContextInterface ;
14- use OpenTelemetry \Contrib \Propagation \ServerTiming \ServerTimingPropagator as Propagator ;
14+ use OpenTelemetry \Contrib \Propagation \ServerTiming \ServerTimingPropagator ;
1515use OpenTelemetry \SDK \Trace \Span ;
1616use PHPUnit \Framework \TestCase ;
1717
@@ -21,15 +21,20 @@ class PropagatorTest extends TestCase
2121 private const SPAN_ID = '53995c3f42cd8ad8 ' ;
2222 private const TRACERESPONSE_HEADER_SAMPLED = '00-5759e988bd862e3fe1be46a994272793-53995c3f42cd8ad8-01 ' ;
2323 private const TRACERESPONSE_HEADER_NOT_SAMPLED = '00-5759e988bd862e3fe1be46a994272793-53995c3f42cd8ad8-00 ' ;
24+ private ServerTimingPropagator $ propagator ;
2425
26+ #[\Override]
27+ protected function setUp (): void
28+ {
29+ $ this ->propagator = ServerTimingPropagator::getInstance ();
30+ }
2531 /**
2632 * @test
2733 * fields() should return an array of fields that will be set on the carrier
2834 */
2935 public function test_fields ()
3036 {
31- $ propagator = new Propagator ();
32- $ this ->assertSame ($ propagator ->fields (), [Propagator::SERVER_TIMING ]);
37+ $ this ->assertSame ($ this ->propagator ->fields (), [ServerTimingPropagator::SERVER_TIMING ]);
3338 }
3439
3540 /**
@@ -40,7 +45,7 @@ public function test_fields()
4045 public function test_inject_valid_sampled_trace_id ()
4146 {
4247 $ carrier = [];
43- ( new Propagator ()) ->inject (
48+ $ this -> propagator ->inject (
4449 $ carrier ,
4550 null ,
4651 $ this ->withSpanContext (
@@ -50,7 +55,7 @@ public function test_inject_valid_sampled_trace_id()
5055 );
5156
5257 $ this ->assertSame (
53- [Propagator ::SERVER_TIMING => sprintf ('%s;desc=%s ' , Propagator ::TRACEPARENT , self ::TRACERESPONSE_HEADER_SAMPLED )],
58+ [ServerTimingPropagator ::SERVER_TIMING => sprintf ('%s;desc=%s ' , ServerTimingPropagator ::TRACEPARENT , self ::TRACERESPONSE_HEADER_SAMPLED )],
5459 $ carrier
5560 );
5661 }
@@ -62,7 +67,7 @@ public function test_inject_valid_sampled_trace_id()
6267 public function test_inject_valid_not_sampled_trace_id ()
6368 {
6469 $ carrier = [];
65- ( new Propagator ()) ->inject (
70+ $ this -> propagator ->inject (
6671 $ carrier ,
6772 null ,
6873 $ this ->withSpanContext (
@@ -72,7 +77,7 @@ public function test_inject_valid_not_sampled_trace_id()
7277 );
7378
7479 $ this ->assertSame (
75- [Propagator ::SERVER_TIMING => sprintf ('%s;desc=%s ' , Propagator ::TRACEPARENT , self ::TRACERESPONSE_HEADER_NOT_SAMPLED )],
80+ [ServerTimingPropagator ::SERVER_TIMING => sprintf ('%s;desc=%s ' , ServerTimingPropagator ::TRACEPARENT , self ::TRACERESPONSE_HEADER_NOT_SAMPLED )],
7681 $ carrier
7782 );
7883 }
@@ -84,7 +89,7 @@ public function test_inject_valid_not_sampled_trace_id()
8489 public function test_inject_trace_id_with_trace_state ()
8590 {
8691 $ carrier = [];
87- ( new Propagator ()) ->inject (
92+ $ this -> propagator ->inject (
8893 $ carrier ,
8994 null ,
9095 $ this ->withSpanContext (
@@ -94,7 +99,7 @@ public function test_inject_trace_id_with_trace_state()
9499 );
95100
96101 $ this ->assertSame (
97- [Propagator ::SERVER_TIMING => sprintf ('%s;desc=%s ' , Propagator ::TRACEPARENT , self ::TRACERESPONSE_HEADER_SAMPLED )],
102+ [ServerTimingPropagator ::SERVER_TIMING => sprintf ('%s;desc=%s ' , ServerTimingPropagator ::TRACEPARENT , self ::TRACERESPONSE_HEADER_SAMPLED )],
98103 $ carrier
99104 );
100105 }
@@ -106,7 +111,7 @@ public function test_inject_trace_id_with_trace_state()
106111 public function test_inject_trace_id_with_invalid_span_context ()
107112 {
108113 $ carrier = [];
109- ( new Propagator ()) ->inject (
114+ $ this -> propagator ->inject (
110115 $ carrier ,
111116 null ,
112117 $ this ->withSpanContext (
0 commit comments