Skip to content

Commit 6912ab2

Browse files
committed
fix(http-client): use lowercase header key for Content-Length lookup
Symfony's getHeaders() normalizes header names to lowercase, so the Content-Length check was unreachable. Access the first array element since headers are returned as arrays.
1 parent f15d9cf commit 6912ab2

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/Instrumentation/Symfony/HttpClient/TraceableResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ private function endSpan(): void
138138
$statusCode = $this->response->getStatusCode();
139139
if (0 !== $statusCode && $this->span->isRecording()) {
140140
$headers = $this->response->getHeaders(false);
141-
if (isset($headers['Content-Length'])) {
142-
$this->span->setAttribute(HttpIncubatingAttributes::HTTP_RESPONSE_BODY_SIZE, $headers['Content-Length']);
141+
if (isset($headers['content-length'][0])) {
142+
$this->span->setAttribute(HttpIncubatingAttributes::HTTP_RESPONSE_BODY_SIZE, $headers['content-length'][0]);
143143
}
144144

145145
$this->span->setAttribute(HttpAttributes::HTTP_RESPONSE_STATUS_CODE, $statusCode);

tests/Functional/Instrumentation/HttpClientTracingTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testOk(): void
2929
'url' => 'http://localhost/ok',
3030
'http_code' => 200,
3131
'http_method' => 'GET',
32-
'response_headers' => ['Content-Type' => 'application/json'],
32+
'response_headers' => ['Content-Type' => 'application/json', 'Content-Length' => '16'],
3333
])),
3434
self::getContainer()->get('open_telemetry.traces.tracers.main'),
3535
new Psr17Factory(),
@@ -39,7 +39,7 @@ public function testOk(): void
3939

4040
self::assertSame(Response::HTTP_OK, $response->getStatusCode());
4141
self::assertSame('{"status": "ok"}', $response->getContent());
42-
self::assertSame(['content-type' => ['application/json']], $response->getHeaders());
42+
self::assertSame(['content-type' => ['application/json'], 'content-length' => ['16']], $response->getHeaders());
4343

4444
self::assertSpansCount(1);
4545

@@ -53,6 +53,7 @@ public function testOk(): void
5353
'url.query' => '',
5454
'url.fragment' => '',
5555
'http.request.method' => 'GET',
56+
'http.response.body.size' => '16',
5657
'http.response.status_code' => 200,
5758
]);
5859
self::assertSpanEventsCount($mainSpan, 0);

0 commit comments

Comments
 (0)