Skip to content

Commit 3a66cc8

Browse files
authored
Added check to Instrumentation mapResult hook to check for presence of @metadata element in the Aws\Result object, as @metadata is not always set for all instrumented functions. (#301)
1 parent c06f8c6 commit 3a66cc8

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Aws/src/AwsSdkInstrumentation.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,17 @@ public function activate(): bool
109109

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

116124
$this->span->end();
117125
$this->scope->detach();

0 commit comments

Comments
 (0)