Skip to content

Commit 3f63c11

Browse files
jchrostek-ddclaude
andcommitted
fix: remove unnecessary trace_ctx initialization
The trace_ctx variable is only used inside the `if should_trace_cold_start:` block, so initializing it to None beforehand is redundant. Also updated comment to explain WHY we capture trace context before finishing spans (to ensure ColdStartTracer gets the correct trace_id). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 6ab7bcf commit 3f63c11

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

datadog_lambda/wrapper.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,13 @@ def _after(self, event, context):
305305

306306
status_code = extract_http_status_code_tag(self.trigger_tags, self.response)
307307

308-
# Skip creating cold start spans in managed instances mode
309-
# In managed instances, the tracer library handles cold start independently
308+
# Capture trace context BEFORE finishing spans so ColdStartTracer
309+
# creates spans with the correct trace_id.
310310
should_trace_cold_start = (
311311
config.cold_start_tracing
312312
and is_new_sandbox()
313313
and not is_managed_instances_mode()
314314
)
315-
trace_ctx = None
316315
if should_trace_cold_start:
317316
trace_ctx = tracer.current_trace_context()
318317

0 commit comments

Comments
 (0)