Merged
Conversation
…modb-span-pointers
duncanista
reviewed
Mar 24, 2025
Comment on lines
+183
to
+207
| let (primary_key1, value1, primary_key2, value2) = if self.dynamodb.keys.len() == 1 { | ||
| // Single primary key case | ||
| let (key, attr_value) = self | ||
| .dynamodb | ||
| .keys | ||
| .iter() | ||
| .next() | ||
| .expect("No DynamoDB keys found"); | ||
|
|
||
| let value = attr_value.to_string()?; | ||
| (key.clone(), value, String::new(), String::new()) | ||
| } else { | ||
| // Two keys case, sort lexicographically for consistent ordering | ||
| let mut keys: Vec<(&String, &AttributeValue)> = self.dynamodb.keys.iter().collect(); | ||
| keys.sort_by(|a, b| a.0.cmp(b.0)); | ||
|
|
||
| let (k1, attr1) = keys[0]; | ||
| // If unable to get string value, just return None | ||
| let v1 = attr1.to_string()?; | ||
|
|
||
| let (k2, attr2) = keys[1]; | ||
| let v2 = attr2.to_string()?; | ||
|
|
||
| (k1.clone(), v1, k2.clone(), v2) | ||
| }; |
Contributor
There was a problem hiding this comment.
Suggested change
| let (primary_key1, value1, primary_key2, value2) = if self.dynamodb.keys.len() == 1 { | |
| // Single primary key case | |
| let (key, attr_value) = self | |
| .dynamodb | |
| .keys | |
| .iter() | |
| .next() | |
| .expect("No DynamoDB keys found"); | |
| let value = attr_value.to_string()?; | |
| (key.clone(), value, String::new(), String::new()) | |
| } else { | |
| // Two keys case, sort lexicographically for consistent ordering | |
| let mut keys: Vec<(&String, &AttributeValue)> = self.dynamodb.keys.iter().collect(); | |
| keys.sort_by(|a, b| a.0.cmp(b.0)); | |
| let (k1, attr1) = keys[0]; | |
| // If unable to get string value, just return None | |
| let v1 = attr1.to_string()?; | |
| let (k2, attr2) = keys[1]; | |
| let v2 = attr2.to_string()?; | |
| (k1.clone(), v1, k2.clone(), v2) | |
| }; | |
| let (primary_key1, value1, primary_key2, value2) = match self.dynamodb.keys.len() { | |
| 1 => { | |
| let (key, attr_value) = self.dynamodb.keys.iter() | |
| .next() | |
| .expect("No DynamoDB keys found"); | |
| (key.clone(), attr_value.to_string()?, String::new(), String::new()) | |
| }, | |
| _ => { | |
| let mut sorted_keys: Vec<_> = self.dynamodb.keys.iter() | |
| .collect::<Vec<_>>() | |
| .into_iter() | |
| .sorted_by_key(|k| k.0.clone()) | |
| .collect(); | |
| let (k1, attr1) = sorted_keys[0]; | |
| let (k2, attr2) = sorted_keys[1]; | |
| (k1.clone(), attr1.to_string()?, k2.clone(), attr2.to_string()?) | |
| } | |
| }; |
Contributor
There was a problem hiding this comment.
Ideally, I'd not even return anything, but maybe push to the array that you're creating? Although if you push and someone modifies the code, they might break the order (in case the order matters), anyhow, looks good if you don't decide to change the return thing,
Nonetheless, I'd encourage the suggestion above
duncanista
approved these changes
Mar 24, 2025
Contributor
duncanista
left a comment
There was a problem hiding this comment.
LGTM – left a comment
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.
What does this PR do?
Adds span pointers to spans for Lambdas triggered by DynamoDB streams. This change will affect the downstream case for Universal Instrumentation Lambda runtimes (Java, .NET, Golang).
Span pointers are similar to Span Links, but for cases when it is impossible to pass the Trace ID and Span ID between the spans that need to be linked.
When the calculated hashes for the upstream and downstream lambdas match, the Datadog frontend will automatically link the two traces together.
Upstream case (requires tracer to be instrumented):

Downstream case (this code):

When clicking on the linked span, a new tab opens linking to the opposite Lambda function.
Describe how you validated your changes
Mostly manual testing, but I also added unit tests. There are also functional tests in https://github.com/DataDog/serverless-e2e-tests -- DynamoDB is TODO but will be implemented soon.