From b380a0df3c0ff59385cf59c6a50de9392bdd8d34 Mon Sep 17 00:00:00 2001 From: Ago Allikmaa Date: Wed, 28 Feb 2024 09:13:17 +0200 Subject: [PATCH] Extract response headers for Guzzle, HTTPlug Async (#241) --- src/GuzzleInstrumentation.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/GuzzleInstrumentation.php b/src/GuzzleInstrumentation.php index 523f90e..609fb9c 100644 --- a/src/GuzzleInstrumentation.php +++ b/src/GuzzleInstrumentation.php @@ -100,6 +100,13 @@ public static function register(): void $span->setAttribute(TraceAttributes::HTTP_RESPONSE_STATUS_CODE, $response->getStatusCode()); $span->setAttribute(TraceAttributes::NETWORK_PROTOCOL_VERSION, $response->getProtocolVersion()); $span->setAttribute(TraceAttributes::HTTP_RESPONSE_BODY_SIZE, $response->getHeaderLine('Content-Length')); + + foreach ((array) (get_cfg_var('otel.instrumentation.http.response_headers') ?: []) as $header) { + if ($response->hasHeader($header)) { + /** @psalm-suppress ArgumentTypeCoercion */ + $span->setAttribute(sprintf('http.response.header.%s', strtolower($header)), $response->getHeader($header)); + } + } if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 600) { $span->setStatus(StatusCode::STATUS_ERROR); }