Skip to content

Commit 0015e8c

Browse files
dougqhdevflow.devflow-routing-intake
andauthored
Avoid ClassCastException on every DynamoDB request in AwsSdkClientDecorator (#11285)
Avoid ClassCastException on every DynamoDB request in AwsSdkClientDecorator `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> Merge branch 'master' into dougqh/aws-sdk-v2-skip-dynamodb-cce Merge branch 'master' into dougqh/aws-sdk-v2-skip-dynamodb-cce Merge branch 'master' into dougqh/aws-sdk-v2-skip-dynamodb-cce Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
1 parent 4d2adea commit 0015e8c

1 file changed

Lines changed: 6 additions & 17 deletions

File tree

  • dd-java-agent/instrumentation/aws-java/aws-java-sdk-2.2/src/main/java/datadog/trace/instrumentation/aws/v2

dd-java-agent/instrumentation/aws-java/aws-java-sdk-2.2/src/main/java/datadog/trace/instrumentation/aws/v2/AwsSdkClientDecorator.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ public Context onSdkRequest(
133133

134134
// S3
135135
request.getValueForField("Bucket", String.class).ifPresent(name -> setBucketName(span, name));
136-
if ("s3".equalsIgnoreCase(awsServiceName) && traceConfig().isDataStreamsEnabled()) {
137-
request
138-
.getValueForField("Key", String.class)
139-
.ifPresent(key -> span.setTag(InstrumentationTags.AWS_OBJECT_KEY, key));
140-
span.setTag(Tags.HTTP_REQUEST_CONTENT_LENGTH, getRequestContentLength(httpRequest));
136+
if ("s3".equalsIgnoreCase(awsServiceName)) {
137+
// gate "Key" extraction to S3 — DynamoDB's Key is Map<String, AttributeValue>, would CCE
138+
request.getValueForField("Key", String.class).ifPresent(key -> setObjectKey(span, key));
139+
if (traceConfig().isDataStreamsEnabled()) {
140+
span.setTag(Tags.HTTP_REQUEST_CONTENT_LENGTH, getRequestContentLength(httpRequest));
141+
}
141142
}
142143

143-
getRequestKey(request).ifPresent(key -> setObjectKey(span, key));
144144
request
145145
.getValueForField("StorageClass", String.class)
146146
.ifPresent(
@@ -279,17 +279,6 @@ private static void setBucketName(AgentSpan span, String name) {
279279
setPeerService(span, InstrumentationTags.AWS_BUCKET_NAME, name);
280280
}
281281

282-
private static Optional<String> getRequestKey(SdkRequest request) {
283-
Optional<String> key = Optional.empty();
284-
try {
285-
key = request.getValueForField("Key", String.class);
286-
} catch (ClassCastException ignored) {
287-
// Key is not always a string, like for dynamodb GetItemRequest
288-
}
289-
290-
return key;
291-
}
292-
293282
private static void setObjectKey(AgentSpan span, String key) {
294283
span.setTag(InstrumentationTags.AWS_OBJECT_KEY, key);
295284
}

0 commit comments

Comments
 (0)