Skip to content

Commit

Permalink
Extract response headers for Guzzle, HTTPlug Async (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
agoallikmaa authored Feb 28, 2024
1 parent 385a9e5 commit b380a0d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/GuzzleInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit b380a0d

Please sign in to comment.