@@ -262,26 +262,17 @@ def _patched_endpoint_prepare_request(
262
262
263
263
return wrapped (* args , ** kwargs )
264
264
265
+ # pylint: disable=too-many-locals
265
266
# pylint: disable=too-many-branches
266
267
def _patched_api_call (self , original_func , instance , args , kwargs ):
267
268
if not is_instrumentation_enabled ():
268
269
return original_func (* args , ** kwargs )
269
270
270
- call_context = _determine_call_context (instance , args )
271
- if call_context is None :
271
+ span_data = self . _prepare_span_data (instance , args )
272
+ if span_data is None :
272
273
return original_func (* args , ** kwargs )
273
274
274
- extension = _find_extension (call_context )
275
- if not extension .should_trace_service_call ():
276
- return original_func (* args , ** kwargs )
277
-
278
- attributes = {
279
- SpanAttributes .RPC_SYSTEM : "aws-api" ,
280
- SpanAttributes .RPC_SERVICE : call_context .service_id ,
281
- SpanAttributes .RPC_METHOD : call_context .operation ,
282
- CLOUD_REGION : call_context .region ,
283
- ** get_server_attributes (call_context .endpoint_url ),
284
- }
275
+ call_context , extension , attributes = span_data
285
276
286
277
_safe_invoke (extension .extract_attributes , attributes )
287
278
end_span_on_exit = extension .should_end_span_on_exit ()
@@ -346,6 +337,25 @@ def _call_response_hook(
346
337
span , call_context .service , call_context .operation , result
347
338
)
348
339
340
+ @staticmethod
341
+ def _prepare_span_data (instance , args ):
342
+ call_context = _determine_call_context (instance , args )
343
+ if call_context is None :
344
+ return None
345
+
346
+ extension = _find_extension (call_context )
347
+ if not extension .should_trace_service_call ():
348
+ return None
349
+
350
+ attributes = {
351
+ SpanAttributes .RPC_SYSTEM : "aws-api" ,
352
+ SpanAttributes .RPC_SERVICE : call_context .service_id ,
353
+ SpanAttributes .RPC_METHOD : call_context .operation ,
354
+ CLOUD_REGION : call_context .region ,
355
+ ** get_server_attributes (call_context .endpoint_url ),
356
+ }
357
+
358
+ return call_context , extension , attributes
349
359
350
360
def _apply_response_attributes (span : Span , result ):
351
361
if result is None or not span .is_recording ():
0 commit comments