Use correct value for operation in aws-sdk v1
MODIFY
instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/awssdk/v1_11/AwsSdkClientTracer.java
instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/awssdk/v1_11/AwsSdkClientTracer.java
package io.opentelemetry.javaagent.instrumentation.awssdk.v1_11;
-import com.amazonaws.AmazonWebServiceRequest;
import com.amazonaws.AmazonWebServiceResponse;
import com.amazonaws.Request;
import com.amazonaws.Response;
@@ -25,6 +24,16 @@ public class AwsSdkClientTracer extends HttpClientTracer<Request<?>, Request<?>,
Config.get()
.getBooleanProperty("otel.instrumentation.aws-sdk.experimental-span-attributes", false);
+ private static final ClassValue<String> OPERATION_NAME =
+ new ClassValue<String>() {
+ @Override
+ protected String computeValue(Class<?> type) {
+ String ret = type.getSimpleName();
+ ret = ret.substring(0, ret.length() - 7); // remove 'Request'
+ return ret;
+ }
+ };
+
static final String COMPONENT_NAME = "java-aws-sdk";
private static final AwsSdkClientTracer TRACER = new AwsSdkClientTracer();
@@ -58,13 +67,11 @@ public class AwsSdkClientTracer extends HttpClientTracer<Request<?>, Request<?>,
Span span = Span.fromContext(context);
String awsServiceName = request.getServiceName();
- AmazonWebServiceRequest originalRequest = request.getOriginalRequest();
- Class<?> awsOperation = originalRequest.getClass();
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
span.setAttribute("aws.agent", COMPONENT_NAME);
span.setAttribute("aws.service", awsServiceName);
- span.setAttribute("aws.operation", awsOperation.getSimpleName());
+ span.setAttribute("aws.operation", extractOperationName(request));
span.setAttribute("aws.endpoint", request.getEndpoint().toString());
if (requestMeta != null) {
@@ -144,4 +151,8 @@ public class AwsSdkClientTracer extends HttpClientTracer<Request<?>, Request<?>,
return new ConcurrentHashMap<>();
}
}
+
+ private static String extractOperationName(Request<?> request) {
+ return OPERATION_NAME.get(request.getOriginalRequest().getClass());
+ }
}

MODIFY
instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/Aws1ClientTest.groovy
instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/Aws1ClientTest.groovy
@@ -148,7 +148,7 @@ class Aws1ClientTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.NET_PEER_NAME.key}" "localhost"
"aws.service" { it.contains(service) }
"aws.endpoint" "$server.address"
- "aws.operation" "${operation}Request"
+ "aws.operation" "${operation}"
"aws.agent" "java-aws-sdk"
for (def addedTag : additionalAttributes) {
"$addedTag.key" "$addedTag.value"
@@ -209,7 +209,7 @@ class Aws1ClientTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.NET_PEER_PORT.key}" 61
"aws.service" { it.contains(service) }
"aws.endpoint" "http://localhost:${UNUSABLE_PORT}"
- "aws.operation" "${operation}Request"
+ "aws.operation" "${operation}"
"aws.agent" "java-aws-sdk"
for (def addedTag : additionalAttributes) {
"$addedTag.key" "$addedTag.value"
@@ -256,7 +256,7 @@ class Aws1ClientTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.NET_PEER_NAME.key}" "s3.amazonaws.com"
"aws.service" "Amazon S3"
"aws.endpoint" "https://s3.amazonaws.com"
- "aws.operation" "HeadBucketRequest"
+ "aws.operation" "HeadBucket"
"aws.agent" "java-aws-sdk"
}
}
@@ -306,7 +306,7 @@ class Aws1ClientTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.HTTP_FLAVOR.key}" "1.1"
"aws.service" "Amazon S3"
"aws.endpoint" "$server.address"
- "aws.operation" "GetObjectRequest"
+ "aws.operation" "GetObject"
"aws.agent" "java-aws-sdk"
"aws.bucket.name" "someBucket"
}

MODIFY
instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/testSqs/groovy/SqsTracingTest.groovy
instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/testSqs/groovy/SqsTracingTest.groovy
@@ -63,7 +63,7 @@ class SqsTracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" "http://localhost:$sqsPort"
- "aws.operation" "CreateQueueRequest"
+ "aws.operation" "CreateQueue"
"aws.queue.name" "testSdkSqs"
"aws.service" "AmazonSQS"
"http.flavor" "1.1"
@@ -84,7 +84,7 @@ class SqsTracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" "http://localhost:$sqsPort"
- "aws.operation" "SendMessageRequest"
+ "aws.operation" "SendMessage"
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
"aws.service" "AmazonSQS"
"http.flavor" "1.1"
@@ -103,7 +103,7 @@ class SqsTracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" "http://localhost:$sqsPort"
- "aws.operation" "ReceiveMessageRequest"
+ "aws.operation" "ReceiveMessage"
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
"aws.service" "AmazonSQS"
"http.flavor" "1.1"
@@ -129,7 +129,7 @@ class SqsTracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" "http://localhost:$sqsPort"
- "aws.operation" "ReceiveMessageRequest"
+ "aws.operation" "ReceiveMessage"
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
"aws.service" "AmazonSQS"
"http.flavor" "1.1"

MODIFY
instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test_before_1_11_106/groovy/Aws0ClientTest.groovy
instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test_before_1_11_106/groovy/Aws0ClientTest.groovy
@@ -113,7 +113,7 @@ class Aws0ClientTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.NET_PEER_NAME.key}" "localhost"
"aws.service" { it.contains(service) }
"aws.endpoint" "$server.address"
- "aws.operation" "${operation}Request"
+ "aws.operation" "${operation}"
"aws.agent" "java-aws-sdk"
for (def addedTag : additionalAttributes) {
"$addedTag.key" "$addedTag.value"
@@ -172,7 +172,7 @@ class Aws0ClientTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.NET_PEER_NAME.key}" "localhost"
"aws.service" { it.contains(service) }
"aws.endpoint" "http://localhost:${UNUSABLE_PORT}"
- "aws.operation" "${operation}Request"
+ "aws.operation" "${operation}"
"aws.agent" "java-aws-sdk"
for (def addedTag : additionalAttributes) {
"$addedTag.key" "$addedTag.value"
@@ -219,7 +219,7 @@ class Aws0ClientTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.NET_PEER_NAME.key}" "s3.amazonaws.com"
"aws.service" "Amazon S3"
"aws.endpoint" "https://s3.amazonaws.com"
- "aws.operation" "GetObjectRequest"
+ "aws.operation" "GetObject"
"aws.agent" "java-aws-sdk"
"aws.bucket.name" "someBucket"
}
@@ -266,7 +266,7 @@ class Aws0ClientTest extends AgentInstrumentationSpecification {
"${SemanticAttributes.NET_PEER_NAME.key}" "localhost"
"aws.service" "Amazon S3"
"aws.endpoint" "http://localhost:$server.address.port"
- "aws.operation" "GetObjectRequest"
+ "aws.operation" "GetObject"
"aws.agent" "java-aws-sdk"
"aws.bucket.name" "someBucket"
}

Use correct value for operation in aws-sdk v1 (#2488)