Skip to content

Commit 6edfb01

Browse files
committed
ref(boto3): remove uncessary defensive conditionals
1 parent 84601ca commit 6edfb01

1 file changed

Lines changed: 9 additions & 23 deletions

File tree

‎sentry_sdk/integrations/boto3/_instrumentation.py‎

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
)
2626

2727
if TYPE_CHECKING:
28-
from typing import Any, Dict, Optional, Union
28+
from typing import Any, Dict, Mapping, Optional, Union
2929

3030
from sentry_sdk._types import Attributes
3131
from sentry_sdk.integrations.boto3._context import AwsCallContext
@@ -92,13 +92,8 @@ def _get_client_attributes(
9292
return attributes
9393

9494

95-
def _get_response_attributes(response: "Any") -> "Attributes":
96-
if not isinstance(response, dict):
97-
return {}
98-
99-
metadata = response.get("ResponseMetadata")
100-
if not isinstance(metadata, dict):
101-
return {}
95+
def _get_response_attributes(response: "Mapping[str, Any]") -> "Attributes":
96+
metadata = response.get("ResponseMetadata", {})
10297
attributes: "Attributes" = {}
10398

10499
# botocore injects HTTP status into `ResponseMetadata` after parsing.
@@ -107,18 +102,11 @@ def _get_response_attributes(response: "Any") -> "Attributes":
107102
if isinstance(status_code, int) and 100 <= status_code <= 599:
108103
attributes[SPANDATA.HTTP_STATUS_CODE] = status_code
109104

110-
retry_attempts = metadata.get("RetryAttempts")
111-
if (
112-
isinstance(retry_attempts, int)
113-
# avoid emitting `resend_count=True`.
114-
and not isinstance(retry_attempts, bool)
115-
and retry_attempts > 0
116-
):
105+
retry_attempts = metadata.get("RetryAttempts", 0)
106+
if retry_attempts > 0:
117107
attributes[SPANDATA.HTTP_REQUEST_RESEND_COUNT] = retry_attempts
118108

119-
headers = metadata.get("HTTPHeaders")
120-
if not isinstance(headers, dict):
121-
headers = {}
109+
headers = metadata.get("HTTPHeaders", {})
122110

123111
request_id = next(
124112
(
@@ -157,11 +145,9 @@ def _get_error_type(exception: "BaseException") -> str:
157145
# `ClientError` wraps AWS service errors; `Error.Code` identifies the
158146
# actual service error, e.g. `AccessDeniedException`.
159147
# https://docs.aws.amazon.com/boto3/latest/guide/error-handling.html
160-
error = exception.response.get("Error")
161-
if isinstance(error, dict):
162-
error_code = error.get("Code")
163-
if isinstance(error_code, str) and error_code:
164-
return error_code
148+
error_code: "Optional[str]" = exception.response.get("Error", {}).get("Code")
149+
if error_code:
150+
return error_code
165151

166152
# failures before a service response have no AWS error code.
167153
# https://opentelemetry.io/docs/specs/semconv/rpc/rpc-spans/

0 commit comments

Comments
 (0)