99
1010from ..log import logger
1111from ..singletons import tracer
12-
12+ from .. util . traceutils import get_active_tracer
1313
1414try :
1515 import boto3
1616 from boto3 .s3 import inject
1717
18+
1819 def lambda_inject_context (payload , scope ):
1920 """
2021 When boto3 lambda client 'Invoke' is called, we want to inject the tracing context.
@@ -36,13 +37,13 @@ def lambda_inject_context(payload, scope):
3637 @wrapt .patch_function_wrapper ('botocore.client' , 'BaseClient._make_api_call' )
3738 def make_api_call_with_instana (wrapped , instance , arg_list , kwargs ):
3839 # pylint: disable=protected-access
39- parent_span = tracer . active_span
40+ active_tracer = get_active_tracer ()
4041
4142 # If we're not tracing, just return
42- if parent_span is None :
43+ if active_tracer is None :
4344 return wrapped (* arg_list , ** kwargs )
4445
45- with tracer .start_active_span ("boto3" , child_of = parent_span ) as scope :
46+ with active_tracer .start_active_span ("boto3" , child_of = active_tracer . active_span ) as scope :
4647 try :
4748 operation = arg_list [0 ]
4849 payload = arg_list [1 ]
@@ -62,7 +63,6 @@ def make_api_call_with_instana(wrapped, instance, arg_list, kwargs):
6263 if 'lambda' in instance ._endpoint .host and operation == 'Invoke' :
6364 lambda_inject_context (payload , scope )
6465
65-
6666 except Exception as exc :
6767 logger .debug ("make_api_call_with_instana: collect error" , exc_info = True )
6868
@@ -81,19 +81,20 @@ def make_api_call_with_instana(wrapped, instance, arg_list, kwargs):
8181 scope .span .mark_as_errored ({'error' : exc })
8282 raise
8383
84+
8485 def s3_inject_method_with_instana (wrapped , instance , arg_list , kwargs ):
8586 fas = inspect .getfullargspec (wrapped )
8687 fas_args = fas .args
8788 fas_args .remove ('self' )
8889
8990 # pylint: disable=protected-access
90- parent_span = tracer . active_span
91+ active_tracer = get_active_tracer ()
9192
9293 # If we're not tracing, just return
93- if parent_span is None :
94+ if active_tracer is None :
9495 return wrapped (* arg_list , ** kwargs )
9596
96- with tracer .start_active_span ("boto3" , child_of = parent_span ) as scope :
97+ with active_tracer .start_active_span ("boto3" , child_of = active_tracer . active_span ) as scope :
9798 try :
9899 operation = wrapped .__name__
99100 scope .span .set_tag ('op' , operation )
@@ -119,6 +120,7 @@ def s3_inject_method_with_instana(wrapped, instance, arg_list, kwargs):
119120 scope .span .mark_as_errored ({'error' : exc })
120121 raise
121122
123+
122124 for method in ['upload_file' , 'upload_fileobj' , 'download_file' , 'download_fileobj' ]:
123125 wrapt .wrap_function_wrapper ('boto3.s3.inject' , method , s3_inject_method_with_instana )
124126
0 commit comments