diff --git a/src/Aws/src/AwsSdkInstrumentation.php b/src/Aws/src/AwsSdkInstrumentation.php index 32cd980de..b1496b152 100644 --- a/src/Aws/src/AwsSdkInstrumentation.php +++ b/src/Aws/src/AwsSdkInstrumentation.php @@ -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();