Skip to content

Commit 12b2c8b

Browse files
authored
Modify end time of lambda load span to be last cold start node's end_time (#319)
* modify endtime of lambda load span to be the last cold start node endtime
1 parent ce53280 commit 12b2c8b

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

datadog_lambda/cold_start.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,16 @@ def __init__(
134134
self,
135135
tracer,
136136
function_name,
137-
cold_start_span_finish_time_ns,
137+
current_span_start_time_ns,
138138
trace_ctx,
139139
min_duration_ms: int,
140-
ignored_libs: List[str] = [],
140+
ignored_libs: List[str] = None,
141141
):
142+
if ignored_libs is None:
143+
ignored_libs = []
142144
self._tracer = tracer
143145
self.function_name = function_name
144-
self.cold_start_span_finish_time_ns = cold_start_span_finish_time_ns
146+
self.current_span_start_time_ns = current_span_start_time_ns
145147
self.min_duration_ms = min_duration_ms
146148
self.trace_ctx = trace_ctx
147149
self.ignored_libs = ignored_libs
@@ -151,11 +153,14 @@ def trace(self, root_nodes: List[ImportNode] = root_nodes):
151153
if not root_nodes:
152154
return
153155
cold_start_span_start_time_ns = root_nodes[0].start_time_ns
156+
cold_start_span_end_time_ns = min(
157+
root_nodes[-1].end_time_ns, self.current_span_start_time_ns
158+
)
154159
cold_start_span = self.create_cold_start_span(cold_start_span_start_time_ns)
155160
while root_nodes:
156161
root_node = root_nodes.pop()
157162
self.trace_tree(root_node, cold_start_span)
158-
self.finish_span(cold_start_span, self.cold_start_span_finish_time_ns)
163+
self.finish_span(cold_start_span, cold_start_span_end_time_ns)
159164

160165
def trace_tree(self, import_node: ImportNode, parent_span):
161166
if (

datadog_lambda/tracing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def is_authorizer_response(response) -> bool:
385385
and response["principalId"]
386386
and response["policyDocument"]
387387
)
388-
except KeyError:
388+
except (KeyError, AttributeError):
389389
pass
390390
except Exception as e:
391391
logger.debug("unknown error while checking is_authorizer_response %s", e)

scripts/build_layers.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ mkdir $LAYER_DIR
6868

6969
for python_version in "${PYTHON_VERSIONS[@]}"
7070
do
71-
if [ "$python_version" == "3.8" ] || [ "$python_version" == "3.9" ]; then
71+
if [ "$python_version" != "3.7" ]; then
7272
echo "Building layer for Python ${python_version} arch=arm64"
7373
docker_build_zip ${python_version} $LAYER_DIR/${LAYER_FILES_PREFIX}-arm64-${python_version}.zip arm64
7474
fi

0 commit comments

Comments
 (0)