Skip to content

Skip ClassCastException on every DynamoDB request in AWS SDK v2 instrumentation#11285

Open
dougqh wants to merge 2 commits intomasterfrom
dougqh/aws-sdk-v2-skip-dynamodb-cce
Open

Skip ClassCastException on every DynamoDB request in AWS SDK v2 instrumentation#11285
dougqh wants to merge 2 commits intomasterfrom
dougqh/aws-sdk-v2-skip-dynamodb-cce

Conversation

@dougqh
Copy link
Copy Markdown
Contributor

@dougqh dougqh commented May 5, 2026

Summary

  • AwsSdkClientDecorator.onSdkRequest called getValueForField("Key", String.class) for every AWS SDK v2 request and silently caught a ClassCastException on every DynamoDB Get/Put/Update/Delete item call (DynamoDB models Key as Map<String, AttributeValue>).
  • The CCE was already noted in the original code's comment (// Key is not always a string, like for dynamodb GetItemRequest), but the JVM still filled in a stack trace per request on a hot path.
  • Gate Key extraction to S3 — the only AWS service whose top-level Key field is a String — and inline the helper so the dead try/catch goes away.
  • Behavior unchanged: setObjectKey writes the same aws.object.key tag the DSM-only branch was writing; the DSM branch is preserved for http.request.content_length only.

Test plan

  • CI green on :dd-java-agent:instrumentation:aws-java:aws-java-sdk-2.2:test (existing S3 GetObject/PutObject cases assert aws.object.key is set).
  • CI green on :dd-java-agent:instrumentation:aws-java:aws-java-dynamodb-2.0:test (verifies no regression on DynamoDB span tagging).
  • Spot-check a Localstack DynamoDB GetItem trace to confirm spans are unchanged.

🤖 Generated with Claude Code

…orator

`getValueForField("Key", String.class)` was called on every AWS SDK v2
request and a `ClassCastException` was caught on every DynamoDB
Get/Put/Update/Delete item call (Key is `Map<String, AttributeValue>`).
This forced the JVM to fill in a stack trace per request on a hot path.

Gate the `Key` extraction to S3 (the only service whose top-level `Key`
is a `String`), inline the helper, and drop the dead try/catch. Behavior
for S3 is unchanged — `setObjectKey` already wrote the same tag the
DSM-only branch was writing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@dougqh dougqh added inst: aws sdk AWS SDK instrumentation tag: ai generated Largely based on code generated by an AI or LLM tag: performance Performance related changes type: bug Bug report and fix labels May 5, 2026
@dougqh dougqh requested a review from ValentinZakharov May 5, 2026 20:21
@dougqh dougqh marked this pull request as ready for review May 6, 2026 19:20
@dougqh dougqh requested a review from a team as a code owner May 6, 2026 19:20
Copy link
Copy Markdown
Contributor

@ValentinZakharov ValentinZakharov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inst: aws sdk AWS SDK instrumentation tag: ai generated Largely based on code generated by an AI or LLM tag: performance Performance related changes type: bug Bug report and fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants