[WIP] fix(cold_start): capture trace context before finishing spans#746
Open
jchrostek-dd wants to merge 1 commit intomainfrom
Open
[WIP] fix(cold_start): capture trace context before finishing spans#746jchrostek-dd wants to merge 1 commit intomainfrom
jchrostek-dd wants to merge 1 commit intomainfrom
Conversation
76fa712 to
137668c
Compare
Move trace context capture BEFORE span.finish() so ColdStartTracer creates spans with the correct trace_id. Previously, tracer.current_trace_context() was called AFTER span.finish(), which returned a stale context, causing cold start spans (aws.lambda.load and import spans) to have a different trace_id than the main aws.lambda span. Added unit test assertions to verify trace_id consistency. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
137668c to
fd9f1cb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Root Cause
tracer.current_trace_context()was being called afterspan.finish(), which could return a stale or empty context since the span was no longer active in the context provider.How Node.js Correctly Handles This
The Node.js tracer library (
datadog-lambda-js) passes the live parent span object toColdStartTracerbefore callingfinish():Then in
cold-start-tracer.ts, the cold_start span is created as a child of this live span:Changes
Moved trace context capture to before any spans are finished, ensuring
aws.lambda.cold_startandaws.lambda.loadspans inherit the correct trace ID. This mirrors the Node.js approach of capturing context while spans are still active.Test plan
datadog-lambda-extensionvalidate this fix (all 22 tests passing)🤖 Generated with Claude Code