@@ -55,6 +55,7 @@ def __init__(
55
55
trace_id_suffix : str = None ,
56
56
trigger_by : dict = None ,
57
57
max_finish_time : int = None ,
58
+ is_new_invocation : bool = False ,
58
59
event : str = None ,
59
60
envs : str = None ,
60
61
):
@@ -102,7 +103,8 @@ def __init__(
102
103
)
103
104
self .span_ids_to_send : Set [str ] = set ()
104
105
self .spans : List [Dict ] = []
105
- SpansContainer .is_cold = False
106
+ if is_new_invocation :
107
+ SpansContainer .is_cold = False
106
108
107
109
def _generate_start_span (self ) -> dict :
108
110
to_send = self .function_span .copy ()
@@ -285,14 +287,14 @@ def get_span(cls) -> "SpansContainer":
285
287
return cls .create_span ()
286
288
287
289
@classmethod
288
- def create_span (cls , event = None , context = None , force = False ) -> "SpansContainer" :
290
+ def create_span (cls , event = None , context = None , is_new_invocation = False ) -> "SpansContainer" :
289
291
"""
290
292
This function creates a span out of a given AWS context.
291
293
The force flag delete any existing span-container (to handle with warm execution of lambdas).
292
294
Note that if lambda will be executed directly (regular pythonic function call and not invoked),
293
295
it will override the container.
294
296
"""
295
- if cls ._span and not force :
297
+ if cls ._span and not is_new_invocation :
296
298
return cls ._span
297
299
# copy the event to ensure that we will not change it
298
300
event = copy .deepcopy (event )
@@ -319,6 +321,7 @@ def create_span(cls, event=None, context=None, force=False) -> "SpansContainer":
319
321
account = safe_split_get (getattr (context , "invoked_function_arn" , "" ), ":" , 4 , "" ),
320
322
trigger_by = parse_triggered_by (event ),
321
323
max_finish_time = get_current_ms_time () + remaining_time ,
324
+ is_new_invocation = is_new_invocation ,
322
325
** additional_info ,
323
326
)
324
327
return cls ._span
0 commit comments