8
8
_cold_start = True
9
9
_proactive_initialization = False
10
10
_lambda_container_initialized = False
11
+ _tracer = None
11
12
12
13
13
14
def set_cold_start (init_timestamp_ns ):
@@ -18,6 +19,7 @@ def set_cold_start(init_timestamp_ns):
18
19
global _cold_start
19
20
global _lambda_container_initialized
20
21
global _proactive_initialization
22
+ global _tracer
21
23
if not _lambda_container_initialized :
22
24
now = time .time_ns ()
23
25
if (now - init_timestamp_ns ) // 1_000_000_000 > 10 :
@@ -29,6 +31,7 @@ def set_cold_start(init_timestamp_ns):
29
31
_cold_start = False
30
32
_proactive_initialization = False
31
33
_lambda_container_initialized = True
34
+ from ddtrace import tracer as _tracer
32
35
33
36
34
37
def is_cold_start ():
@@ -62,6 +65,9 @@ def __init__(self, module_name, full_file_path, start_time_ns, end_time_ns=None)
62
65
self .start_time_ns = start_time_ns
63
66
self .end_time_ns = end_time_ns
64
67
self .children = []
68
+ self .context = None
69
+ if _lambda_container_initialized :
70
+ self .context = _tracer .context_provider .active ()
65
71
66
72
67
73
root_nodes : List [ImportNode ] = []
@@ -183,7 +189,8 @@ def trace(self, root_nodes: List[ImportNode] = root_nodes):
183
189
cold_start_span = self .create_cold_start_span (cold_start_span_start_time_ns )
184
190
while root_nodes :
185
191
root_node = root_nodes .pop ()
186
- self .trace_tree (root_node , cold_start_span )
192
+ parent = root_node .context or cold_start_span
193
+ self .trace_tree (root_node , parent )
187
194
self .finish_span (cold_start_span , cold_start_span_end_time_ns )
188
195
189
196
def trace_tree (self , import_node : ImportNode , parent_span ):
0 commit comments