diff --git a/datadog_lambda/wrapper.py b/datadog_lambda/wrapper.py index c174a501..d022988b 100644 --- a/datadog_lambda/wrapper.py +++ b/datadog_lambda/wrapper.py @@ -305,6 +305,16 @@ def _after(self, event, context): status_code = extract_http_status_code_tag(self.trigger_tags, self.response) + # Skip creating cold start spans in managed instances mode + # In managed instances, the tracer library handles cold start independently + should_trace_cold_start = ( + config.cold_start_tracing + and is_new_sandbox() + and not is_managed_instances_mode() + ) + if should_trace_cold_start: + trace_ctx = tracer.current_trace_context() + if self.span: if config.appsec_enabled and not self.blocking_response: asm_start_response( @@ -342,15 +352,6 @@ def _after(self, event, context): create_dd_dummy_metadata_subsegment( self.trigger_tags, XraySubsegment.LAMBDA_FUNCTION_TAGS_KEY ) - # Skip creating cold start spans in managed instances mode - # In managed instances, the tracer library handles cold start independently - should_trace_cold_start = ( - config.cold_start_tracing - and is_new_sandbox() - and not is_managed_instances_mode() - ) - if should_trace_cold_start: - trace_ctx = tracer.current_trace_context() if self.inferred_span: if status_code: diff --git a/tests/test_cold_start.py b/tests/test_cold_start.py index 858db9a5..5fc11e2c 100644 --- a/tests/test_cold_start.py +++ b/tests/test_cold_start.py @@ -310,13 +310,18 @@ def handler(event, context): handler.cold_start_tracing = True handler({}, lambda_context) - function_span = import_span = None + function_span = import_span = load_span = None for span in spans: if span.resource == "tabnanny": import_span = span elif span.name == "aws.lambda": function_span = span + elif span.name == "aws.lambda.load": + load_span = span assert function_span is not None assert import_span is not None assert import_span.parent_id == function_span.span_id + assert import_span.trace_id == function_span.trace_id + assert load_span is not None + assert load_span.trace_id == function_span.trace_id