Skip to content

Commit

Permalink
Added check to Instrumentation mapResult hook to check for presence of
Browse files Browse the repository at this point in the history
…@metadata element in the Aws\Result object, as @metadata is not always set for all instrumented functions.
  • Loading branch information
gwharton committed Oct 3, 2024
1 parent c06f8c6 commit ba00256
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Aws/src/AwsSdkInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,17 @@ public function activate(): bool

/** @psalm-suppress PossiblyInvalidArgument */
$end_middleware = Middleware::mapResult(function (ResultInterface $result) {
$this->span->setAttributes([
'http.status_code' => $result['@metadata']['statusCode'], //@phan-suppress-current-line PhanTypeMismatchDimFetch
]);
/**
* Some AWS SDK Funtions, such as S3Client->getObjectUrl() do not actually perform on the wire comms
* with AWS Servers, and therefore do not return with a populated AWS\Result object with valid @metadata
* Check for the presence of @metadata before extracting status code as these calls are still
* instrumented.
*/
if (isset($result['@metadata'])) {
$this->span->setAttributes([
'http.status_code' => $result['@metadata']['statusCode'], //@phan-suppress-current-line PhanTypeMismatchDimFetch
]);
}

$this->span->end();
$this->scope->detach();
Expand Down

0 comments on commit ba00256

Please sign in to comment.