fix: parent lazily imported module spans to the function span - #856
Merged
Merged
Conversation
Modules imported during the invocation were parented to whatever span was active at import time. When that is a client span (e.g. botocore lazily importing helpers on the first DynamoDB call), the backend peer service pipeline learns the client's host -> the import span's service and sets peer.service=aws.lambda on DynamoDB spans (APMS-20524). Parent them to the function span instead. Imports during init are unchanged, and span service, names and metrics are not affected. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
purple4reina
approved these changes
Sep 24, 2026
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.
https://datadoghq.atlassian.net/browse/APMS-20524
What does this PR do?
Parents
aws.lambda.importspans for modules lazily imported during the invocationto the function span, instead of to whatever span was active at import time.
Imports during init are unchanged (still children of
aws.lambda.load).Motivation
APMS-20524 / APMS-20380:
peer.service=aws.lambdawas being set on DynamoDB clientspans. The first botocore call in a handler lazily imports
ddtrace._trace.utils_botocore*, and those import spans were nested under theactive
dynamodb.commandclient span withservice:aws.lambda. The backend peerservice pipeline learns "client host → callee service" from exactly that shape, so
it mapped the DynamoDB host to
aws.lambda. Reproduced locally with ddtrace 4.15.2and a stubbed DynamoDB client.
The function span is a server span, so parenting to it gives the pipeline no client
span to learn from.
Why not change the service instead?
The extension (Go since 2021, Rust since v67) and the Forwarder already rewrite
aws.lambdadownstream. Changing the service at the source either does nothing or,on the Forwarder path, splits cold start spans from the function span. The bad edge
comes from the parenting.
What changes for customers
under the function span. They keep their timing, name, service and nested imports.
Testing
dynamodb.command.also tested in real lambdas
🤖 Generated with Claude Code