22from typing import TYPE_CHECKING
33
44import sentry_sdk
5- from sentry_sdk .consts import SPANDATA
65from sentry_sdk .integrations import DidNotEnable
76from sentry_sdk .integrations .boto3 ._context import AwsCallContext
87from sentry_sdk .integrations .boto3 ._instrumentation import (
1413 _sentry_request_created ,
1514 _start_client_span ,
1615)
17- from sentry_sdk .integrations .boto3 ._services .registry import (
18- _resolve_service ,
16+ from sentry_sdk .integrations .boto3 ._services .bedrock import _BedrockExtension
17+ from sentry_sdk .integrations .boto3 ._services .dynamodb import _DynamoDBExtension
18+ from sentry_sdk .integrations .boto3 ._services .kinesis import _KinesisExtension
19+ from sentry_sdk .integrations .boto3 ._services .lambda_ import _LambdaExtension
20+ from sentry_sdk .integrations .boto3 ._services .s3 import _S3Extension
21+ from sentry_sdk .integrations .boto3 ._services .secretsmanager import (
22+ _SecretsManagerExtension ,
23+ )
24+ from sentry_sdk .integrations .boto3 ._services .sns import _SNSExtension
25+ from sentry_sdk .integrations .boto3 ._services .sqs import _SQSExtension
26+ from sentry_sdk .integrations .boto3 ._services .stepfunctions import (
27+ _StepFunctionsExtension ,
1928)
2029from sentry_sdk .integrations .boto3 .consts import IDENTIFIER
21- from sentry_sdk .traces import NoOpSpan , Span , SpanStatus
30+ from sentry_sdk .traces import NoOpSpan , Span
2231from sentry_sdk .utils import capture_internal_exceptions
2332
2433if TYPE_CHECKING :
2534 from typing import Any , Dict , Iterator , Optional
2635
2736 from sentry_sdk ._types import Attributes
37+ from sentry_sdk .integrations .boto3 ._services .base import _ServiceExtension
2838
2939try :
3040 from botocore .client import BaseClient
31- from botocore .exceptions import ClientError
3241except ImportError :
3342 raise DidNotEnable ("botocore not installed" )
3443
@@ -94,7 +103,27 @@ def sentry_patched_make_api_call(
94103 with capture_internal_exceptions ():
95104 # add optional metadata to the context, e.g. service-name, region-name, etc.
96105 ctx .add_metadata (self )
97- service_ext = _resolve_service (ctx .service_name )
106+
107+ service_ext : "Optional[_ServiceExtension]" = None
108+ if ctx .service_name == "bedrock-runtime" :
109+ service_ext = _BedrockExtension ()
110+ elif ctx .service_name == "dynamodb" :
111+ service_ext = _DynamoDBExtension ()
112+ elif ctx .service_name == "kinesis" :
113+ service_ext = _KinesisExtension ()
114+ elif ctx .service_name == "lambda" :
115+ service_ext = _LambdaExtension ()
116+ elif ctx .service_name == "s3" :
117+ service_ext = _S3Extension ()
118+ elif ctx .service_name == "secretsmanager" :
119+ service_ext = _SecretsManagerExtension ()
120+ elif ctx .service_name == "sns" :
121+ service_ext = _SNSExtension ()
122+ elif ctx .service_name == "sqs" :
123+ service_ext = _SQSExtension ()
124+ elif ctx .service_name == "stepfunctions" :
125+ service_ext = _StepFunctionsExtension ()
126+
98127 span = _start_client_span (ctx , service_ext )
99128
100129 if span is None :
@@ -107,40 +136,30 @@ def sentry_patched_make_api_call(
107136 try :
108137 parsed = orig_make_api_call (self , operation_name , api_params )
109138 except BaseException as error :
110- if service_ext is not None and isinstance (error , ClientError ):
111- with capture_internal_exceptions ():
112- attributes .update (
113- service_ext .get_response_attributes (ctx , error .response )
114- )
115139 with capture_internal_exceptions ():
116140 attributes .update (_get_error_attributes (error ))
117141 with capture_internal_exceptions ():
118142 span .set_attributes (attributes )
119143 raise
120- if service_ext is not None :
121- with capture_internal_exceptions ():
122- attributes .update (
123- service_ext .get_response_attributes (ctx , parsed )
124- )
125144 with capture_internal_exceptions ():
126145 attributes .update (_get_response_attributes (parsed ))
127146 with capture_internal_exceptions ():
128147 span .set_attributes (attributes )
129- # a service extension reports a failure that didn't raise, i.e. one
130- # in a successful response, with `error.type`.
131- if SPANDATA .ERROR_TYPE in attributes :
132- span .status = SpanStatus .ERROR
133148 except BaseException as error :
134149 _finish_span (span , error )
135150 raise
136151
152+ if service_ext is not None :
153+ service_ext .on_success_response (ctx , parsed , span )
154+ return parsed
155+
137156 streaming_body_instrumented = False
138157 with capture_internal_exceptions ():
139158 streaming_body_instrumented = _instrument_streaming_body (span , parsed )
140159
141160 # `StreamingBody`s finish their span when consumed or closed.
142161 if not streaming_body_instrumented :
143- _finish_span ( span )
162+ span . end ( )
144163 return parsed
145164
146165 BaseClient .__init__ = sentry_patched_init # type: ignore
0 commit comments