Skip to content

Commit effe5f8

Browse files
authored
feat: Update contrib for the experimental response propagator interface (#436)
* Revise contrib for response propagator * Bumped composer.json * Updated Yii composer.json * Fixed instrumentation integration tests * Fixed Propagation tests * Fixed style issue for Symfony * Fixed semconv issue of MongoDB * Bumped sem-conv version in MongoDB to 1.36
1 parent 0ade1e2 commit effe5f8

File tree

3 files changed

+12
-94
lines changed

3 files changed

+12
-94
lines changed

composer.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"require": {
1212
"php": "^8.1",
1313
"ext-opentelemetry": "*",
14-
"open-telemetry/api": "^1.0",
14+
"open-telemetry/api": "^1.6",
1515
"open-telemetry/sem-conv": "^1.32",
1616
"symfony/http-kernel": "*",
1717
"symfony/http-client-contracts": "*"
@@ -27,13 +27,11 @@
2727
"phpstan/phpstan": "^1.1",
2828
"phpstan/phpstan-phpunit": "^1.0",
2929
"psalm/plugin-phpunit": "^0.19.2",
30-
"open-telemetry/sdk": "^1.0",
30+
"open-telemetry/sdk": "^1.8",
3131
"phpunit/phpunit": "^9.5",
3232
"vimeo/psalm": "6.4.0",
3333
"symfony/http-client": "^5.4||^6.0",
34-
"symfony/messenger": "^5.4||^6.0",
35-
"open-telemetry/opentelemetry-propagation-traceresponse": "*",
36-
"open-telemetry/opentelemetry-propagation-server-timing": "*"
34+
"symfony/messenger": "^5.4||^6.0"
3735
},
3836
"autoload": {
3937
"psr-4": {

src/SymfonyInstrumentation.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,8 @@ public static function register(): void
138138

139139
$span->setAttribute(TraceAttributes::HTTP_RESPONSE_BODY_SIZE, $contentLength);
140140

141-
// Propagate server-timing header to response, if ServerTimingPropagator is present
142-
if (class_exists('OpenTelemetry\Contrib\Propagation\ServerTiming\ServerTimingPropagator')) {
143-
$prop = new \OpenTelemetry\Contrib\Propagation\ServerTiming\ServerTimingPropagator();
144-
$prop->inject($response, ResponsePropagationSetter::instance(), $scope->context());
145-
}
146-
147-
// Propagate traceresponse header to response, if TraceResponsePropagator is present
148-
if (class_exists('OpenTelemetry\Contrib\Propagation\TraceResponse\TraceResponsePropagator')) {
149-
$prop = new \OpenTelemetry\Contrib\Propagation\TraceResponse\TraceResponsePropagator();
150-
$prop->inject($response, ResponsePropagationSetter::instance(), $scope->context());
151-
}
141+
$prop = Globals::responsePropagator();
142+
$prop->inject($response, ResponsePropagationSetter::instance(), $scope->context());
152143

153144
$span->end();
154145
}

tests/Integration/SymfonyInstrumentationTest.php

Lines changed: 7 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
use OpenTelemetry\API\Trace\SpanKind;
88
use OpenTelemetry\API\Trace\StatusCode;
9-
use OpenTelemetry\Contrib\Propagation\ServerTiming\ServerTimingPropagator;
10-
use OpenTelemetry\Contrib\Propagation\TraceResponse\TraceResponsePropagator;
119
use OpenTelemetry\SemConv\TraceAttributes;
1210
use Symfony\Component\EventDispatcher\EventDispatcher;
1311
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -31,14 +29,7 @@ public function test_http_kernel_handle_exception(): void
3129
throw new \RuntimeException();
3230
});
3331
$this->assertCount(0, $this->storage);
34-
35-
$response = $kernel->handle(new Request());
36-
37-
$this->assertArrayHasKey(
38-
TraceResponsePropagator::TRACERESPONSE,
39-
$response->headers->all(),
40-
'traceresponse header is present if TraceResponsePropagator is present'
41-
);
32+
$kernel->handle(new Request());
4233
}
4334

4435
public function test_http_kernel_marks_root_as_erroneous(): void
@@ -49,18 +40,12 @@ public function test_http_kernel_marks_root_as_erroneous(): void
4940
});
5041
$this->assertCount(0, $this->storage);
5142

52-
$response = $kernel->handle(new Request(), HttpKernelInterface::MAIN_REQUEST, true);
43+
$kernel->handle(new Request(), HttpKernelInterface::MAIN_REQUEST, true);
5344

5445
$this->assertCount(1, $this->storage);
5546
$this->assertSame(500, $this->storage[0]->getAttributes()->get(TraceAttributes::HTTP_RESPONSE_STATUS_CODE));
5647

5748
$this->assertSame(StatusCode::STATUS_ERROR, $this->storage[0]->getStatus()->getCode());
58-
59-
$this->assertArrayHasKey(
60-
TraceResponsePropagator::TRACERESPONSE,
61-
$response->headers->all(),
62-
'traceresponse header is present if TraceResponsePropagator is present'
63-
);
6449
}
6550

6651
public function test_http_kernel_handle_attributes(): void
@@ -70,7 +55,7 @@ public function test_http_kernel_handle_attributes(): void
7055
$request = new Request();
7156
$request->attributes->set('_route', 'test_route');
7257

73-
$response = $kernel->handle($request);
58+
$kernel->handle($request);
7459

7560
$attributes = $this->storage[0]->getAttributes();
7661
$this->assertCount(1, $this->storage);
@@ -83,17 +68,6 @@ public function test_http_kernel_handle_attributes(): void
8368
$this->assertEquals('1.0', $attributes->get(TraceAttributes::NETWORK_PROTOCOL_VERSION));
8469
$this->assertEquals(5, $attributes->get(TraceAttributes::HTTP_RESPONSE_BODY_SIZE));
8570

86-
$this->assertArrayHasKey(
87-
TraceResponsePropagator::TRACERESPONSE,
88-
$response->headers->all(),
89-
'traceresponse header is present if TraceResponsePropagator is present'
90-
);
91-
92-
$this->assertArrayHasKey(
93-
ServerTimingPropagator::SERVER_TIMING,
94-
$response->headers->all(),
95-
'server-timings header is present if ServerTimingPropagator is present'
96-
);
9771
}
9872

9973
public function test_http_kernel_handle_stream_response(): void
@@ -104,43 +78,20 @@ public function test_http_kernel_handle_stream_response(): void
10478
}));
10579
$this->assertCount(0, $this->storage);
10680

107-
$response = $kernel->handle(new Request());
81+
$kernel->handle(new Request());
10882
$this->assertCount(1, $this->storage);
10983
$this->assertNull($this->storage[0]->getAttributes()->get(TraceAttributes::HTTP_RESPONSE_BODY_SIZE));
110-
111-
$this->assertArrayHasKey(
112-
TraceResponsePropagator::TRACERESPONSE,
113-
$response->headers->all(),
114-
'traceresponse header is present if TraceResponsePropagator is present'
115-
);
116-
117-
$this->assertArrayHasKey(
118-
ServerTimingPropagator::SERVER_TIMING,
119-
$response->headers->all(),
120-
'server-timings header is present if ServerTimingPropagator is present'
121-
);
12284
}
12385

12486
public function test_http_kernel_handle_binary_file_response(): void
12587
{
12688
$kernel = $this->getHttpKernel(new EventDispatcher(), fn () => new BinaryFileResponse(__FILE__));
12789
$this->assertCount(0, $this->storage);
12890

129-
$response = $kernel->handle(new Request());
91+
$kernel->handle(new Request());
13092
$this->assertCount(1, $this->storage);
13193
$this->assertNull($this->storage[0]->getAttributes()->get(TraceAttributes::HTTP_RESPONSE_BODY_SIZE));
13294

133-
$this->assertArrayHasKey(
134-
TraceResponsePropagator::TRACERESPONSE,
135-
$response->headers->all(),
136-
'traceresponse header is present if TraceResponsePropagator is present'
137-
);
138-
139-
$this->assertArrayHasKey(
140-
ServerTimingPropagator::SERVER_TIMING,
141-
$response->headers->all(),
142-
'server-timings header is present if ServerTimingPropagator is present'
143-
);
14495
}
14596

14697
public function test_http_kernel_handle_with_empty_route(): void
@@ -150,43 +101,21 @@ public function test_http_kernel_handle_with_empty_route(): void
150101
$request = new Request();
151102
$request->attributes->set('_route', '');
152103

153-
$response = $kernel->handle($request, HttpKernelInterface::MAIN_REQUEST, true);
104+
$kernel->handle($request, HttpKernelInterface::MAIN_REQUEST, true);
154105
$this->assertCount(1, $this->storage);
155106
$this->assertFalse($this->storage[0]->getAttributes()->has(TraceAttributes::HTTP_ROUTE));
156107

157-
$this->assertArrayHasKey(
158-
TraceResponsePropagator::TRACERESPONSE,
159-
$response->headers->all(),
160-
'traceresponse header is present if TraceResponsePropagator is present'
161-
);
162-
163-
$this->assertArrayHasKey(
164-
ServerTimingPropagator::SERVER_TIMING,
165-
$response->headers->all(),
166-
'server-timings header is present if ServerTimingPropagator is present'
167-
);
168108
}
169109

170110
public function test_http_kernel_handle_without_route(): void
171111
{
172112
$kernel = $this->getHttpKernel(new EventDispatcher());
173113
$this->assertCount(0, $this->storage);
174114

175-
$response = $kernel->handle(new Request(), HttpKernelInterface::MAIN_REQUEST, true);
115+
$kernel->handle(new Request(), HttpKernelInterface::MAIN_REQUEST, true);
176116
$this->assertCount(1, $this->storage);
177117
$this->assertFalse($this->storage[0]->getAttributes()->has(TraceAttributes::HTTP_ROUTE));
178118

179-
$this->assertArrayHasKey(
180-
TraceResponsePropagator::TRACERESPONSE,
181-
$response->headers->all(),
182-
'traceresponse header is present if TraceResponsePropagator is present'
183-
);
184-
185-
$this->assertArrayHasKey(
186-
ServerTimingPropagator::SERVER_TIMING,
187-
$response->headers->all(),
188-
'server-timings header is present if ServerTimingPropagator is present'
189-
);
190119
}
191120

192121
public function test_http_kernel_handle_subrequest(): void

0 commit comments

Comments
 (0)