Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ class S3TracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"rpc.method" "CreateQueue"
"aws.queue.name" queueName
"aws.request_id" String
"rpc.method" "CreateQueue"
"rpc.system" "aws-api"
"rpc.service" "AmazonSQS"
"$HttpAttributes.HTTP_REQUEST_METHOD" "POST"
Expand All @@ -82,10 +83,10 @@ class S3TracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"aws.bucket.name" bucketName
"rpc.method" "CreateBucket"
"rpc.system" "aws-api"
"rpc.service" "Amazon S3"
"aws.bucket.name" bucketName
"$HttpAttributes.HTTP_REQUEST_METHOD" "PUT"
"$HttpAttributes.HTTP_RESPONSE_STATUS_CODE" 200
"$UrlAttributes.URL_FULL" { it.startsWith("http://") }
Expand All @@ -104,8 +105,9 @@ class S3TracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"rpc.method" "GetQueueAttributes"
"aws.queue.url" queueUrl
"aws.request_id" String
"rpc.method" "GetQueueAttributes"
"rpc.system" "aws-api"
"rpc.service" "AmazonSQS"
"$HttpAttributes.HTTP_REQUEST_METHOD" "POST"
Expand All @@ -126,8 +128,9 @@ class S3TracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"rpc.method" "SetQueueAttributes"
"aws.queue.url" queueUrl
"aws.request_id" String
"rpc.method" "SetQueueAttributes"
"rpc.system" "aws-api"
"rpc.service" "AmazonSQS"
"$HttpAttributes.HTTP_REQUEST_METHOD" "POST"
Expand Down Expand Up @@ -188,8 +191,9 @@ class S3TracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"rpc.method" "ReceiveMessage"
"aws.queue.url" queueUrl
"aws.request_id" String
"rpc.method" "ReceiveMessage"
"rpc.system" "aws-api"
"rpc.service" "AmazonSQS"
"$HttpAttributes.HTTP_REQUEST_METHOD" "POST"
Expand Down Expand Up @@ -282,8 +286,9 @@ class S3TracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"rpc.method" "PurgeQueue"
"aws.queue.url" queueUrl
"aws.request_id" String
"rpc.method" "PurgeQueue"
"rpc.system" "aws-api"
"rpc.service" "AmazonSQS"
"$HttpAttributes.HTTP_REQUEST_METHOD" "POST"
Expand Down Expand Up @@ -336,8 +341,9 @@ class S3TracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"rpc.method" "CreateQueue"
"aws.queue.name" queueName
"aws.request_id" String
"rpc.method" "CreateQueue"
"rpc.system" "aws-api"
"rpc.service" "AmazonSQS"
"$HttpAttributes.HTTP_REQUEST_METHOD" "POST"
Expand All @@ -357,8 +363,9 @@ class S3TracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"rpc.method" "GetQueueAttributes"
"aws.queue.url" queueUrl
"aws.request_id" String
"rpc.method" "GetQueueAttributes"
"rpc.system" "aws-api"
"rpc.service" "AmazonSQS"
"$HttpAttributes.HTTP_REQUEST_METHOD" "POST"
Expand Down Expand Up @@ -399,6 +406,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"aws.request_id" String
"rpc.method" "CreateTopic"
"rpc.system" "aws-api"
"rpc.service" "AmazonSNS"
Expand All @@ -419,6 +427,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"aws.request_id" String
"rpc.method" "Subscribe"
"rpc.system" "aws-api"
"rpc.service" "AmazonSNS"
Expand All @@ -440,8 +449,9 @@ class S3TracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"rpc.method" "SetQueueAttributes"
"aws.queue.url" queueUrl
"aws.request_id" String
"rpc.method" "SetQueueAttributes"
"rpc.system" "aws-api"
"rpc.service" "AmazonSQS"
"$HttpAttributes.HTTP_REQUEST_METHOD" "POST"
Expand All @@ -461,6 +471,7 @@ class S3TracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"aws.request_id" String
"rpc.method" "SetTopicAttributes"
"rpc.system" "aws-api"
"rpc.service" "AmazonSNS"
Expand Down Expand Up @@ -524,8 +535,9 @@ class S3TracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"rpc.method" "ReceiveMessage"
"aws.queue.url" queueUrl
"aws.request_id" String
"rpc.method" "ReceiveMessage"
"rpc.system" "aws-api"
"rpc.service" "AmazonSQS"
"$HttpAttributes.HTTP_REQUEST_METHOD" "POST"
Expand Down Expand Up @@ -618,8 +630,9 @@ class S3TracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"rpc.method" "PurgeQueue"
"aws.queue.url" queueUrl
"aws.request_id" String
"rpc.method" "PurgeQueue"
"rpc.system" "aws-api"
"rpc.service" "AmazonSQS"
"$HttpAttributes.HTTP_REQUEST_METHOD" "POST"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"rpc.method" "CreateQueue"
"aws.queue.name" queueName
"aws.request_id" String
"rpc.method" "CreateQueue"
"rpc.system" "aws-api"
"rpc.service" "AmazonSQS"
"$HttpAttributes.HTTP_REQUEST_METHOD" "POST"
Expand All @@ -74,8 +75,9 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"rpc.method" "GetQueueAttributes"
"aws.queue.url" queueUrl
"aws.request_id" String
"rpc.method" "GetQueueAttributes"
"rpc.system" "aws-api"
"rpc.service" "AmazonSQS"
"$HttpAttributes.HTTP_REQUEST_METHOD" "POST"
Expand All @@ -96,8 +98,9 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"rpc.method" "SetQueueAttributes"
"aws.queue.url" queueUrl
"aws.request_id" String
"rpc.method" "SetQueueAttributes"
"rpc.system" "aws-api"
"rpc.service" "AmazonSQS"
"$HttpAttributes.HTTP_REQUEST_METHOD" "POST"
Expand All @@ -118,6 +121,7 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"aws.request_id" String
"rpc.method" "CreateTopic"
"rpc.system" "aws-api"
"rpc.service" "AmazonSNS"
Expand All @@ -139,6 +143,7 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"aws.request_id" String
"rpc.method" "Subscribe"
"rpc.system" "aws-api"
"rpc.service" "AmazonSNS"
Expand All @@ -160,6 +165,7 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
attributes {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"aws.request_id" String
"rpc.method" "Publish"
"rpc.system" "aws-api"
"rpc.service" "AmazonSNS"
Expand All @@ -180,6 +186,7 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
"aws.agent" "java-aws-sdk"
"aws.endpoint" String
"aws.queue.url" queueUrl
"aws.request_id" String
"rpc.system" "aws-api"
"rpc.service" "AmazonSQS"
"rpc.method" "ReceiveMessage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class AwsExperimentalAttributes {
static final AttributeKey<String> AWS_QUEUE_NAME = stringKey("aws.queue.name");
static final AttributeKey<String> AWS_STREAM_NAME = stringKey("aws.stream.name");
static final AttributeKey<String> AWS_TABLE_NAME = stringKey("aws.table.name");
static final AttributeKey<String> AWS_REQUEST_ID = stringKey("aws.requestId");
static final AttributeKey<String> AWS_REQUEST_ID = stringKey("aws.request_id");

private AwsExperimentalAttributes() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,33 @@
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_STREAM_NAME;
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_TABLE_NAME;

import com.amazonaws.AmazonWebServiceResponse;
import com.amazonaws.AmazonWebServiceResult;
import com.amazonaws.Request;
import com.amazonaws.Response;
import com.amazonaws.ResponseMetadata;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.javaagent.tooling.muzzle.NoMuzzle;
import java.util.function.Function;
import javax.annotation.Nullable;

class AwsSdkExperimentalAttributesExtractor
implements AttributesExtractor<Request<?>, Response<?>> {
private static final String COMPONENT_NAME = "java-aws-sdk";
private static final boolean CAN_GET_RESPONSE_METADATA = canGetResponseMetadata();

// AmazonWebServiceResult is only available in v1.11.33 and later
private static boolean canGetResponseMetadata() {
try {
Class<?> clazz = Class.forName("com.amazonaws.AmazonWebServiceResult");
clazz.getMethod("getSdkResponseMetadata");
return true;
} catch (ClassNotFoundException | NoSuchMethodException exception) {
return false;
}
}

@Override
public void onStart(AttributesBuilder attributes, Context parentContext, Request<?> request) {
Expand Down Expand Up @@ -59,12 +73,24 @@ public void onEnd(
Request<?> request,
@Nullable Response<?> response,
@Nullable Throwable error) {
if (response != null && response.getAwsResponse() instanceof AmazonWebServiceResponse) {
AmazonWebServiceResponse<?> awsResp = (AmazonWebServiceResponse<?>) response.getAwsResponse();
String requestId = awsResp.getRequestId();
ResponseMetadata responseMetadata = getResponseMetadata(response);

if (responseMetadata != null) {
String requestId = responseMetadata.getRequestId();
if (requestId != null) {
attributes.put(AWS_REQUEST_ID, requestId);
}
}
}

@NoMuzzle
private static ResponseMetadata getResponseMetadata(Response<?> response) {
if (CAN_GET_RESPONSE_METADATA
&& response != null
&& response.getAwsResponse() instanceof AmazonWebServiceResult) {
AmazonWebServiceResult<?> awsResp = (AmazonWebServiceResult<?>) response.getAwsResponse();
return awsResp.getSdkResponseMetadata();
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ abstract class AbstractAws1ClientTest extends InstrumentationSpecification {
client.requestHandler2s != null
client.requestHandler2s.find { it.getClass().getSimpleName() == "TracingRequestHandler" } != null

def hasRequestId = service in ["SNS", "RDS", "EC2"]

assertTraces(1) {
trace(0, 1) {
span(0) {
Expand All @@ -121,6 +123,7 @@ abstract class AbstractAws1ClientTest extends InstrumentationSpecification {
"$RpcIncubatingAttributes.RPC_METHOD" "${operation}"
"aws.endpoint" "${server.httpUri()}"
"aws.agent" "java-aws-sdk"
"aws.request_id" hasRequestId ? String : null
for (def addedTag : additionalAttributes) {
"$addedTag.key" "$addedTag.value"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ void testSimpleSqsProducerConsumerServices() {
equalTo(stringKey("aws.agent"), "java-aws-sdk"),
equalTo(stringKey("aws.endpoint"), "http://localhost:" + sqsPort),
equalTo(stringKey("aws.queue.name"), "testSdkSqs"),
satisfies(
stringKey("aws.request_id"),
val -> val.isInstanceOf(String.class)),
equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "aws-api"),
equalTo(RpcIncubatingAttributes.RPC_SERVICE, "AmazonSQS"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "CreateQueue"),
Expand All @@ -118,6 +121,9 @@ void testSimpleSqsProducerConsumerServices() {
equalTo(
stringKey("aws.queue.url"),
"http://localhost:" + sqsPort + "/000000000000/testSdkSqs"),
satisfies(
stringKey("aws.request_id"),
val -> val.isInstanceOf(String.class)),
equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "aws-api"),
equalTo(RpcIncubatingAttributes.RPC_SERVICE, "AmazonSQS"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "SendMessage"),
Expand Down Expand Up @@ -148,6 +154,9 @@ void testSimpleSqsProducerConsumerServices() {
equalTo(
stringKey("aws.queue.url"),
"http://localhost:" + sqsPort + "/000000000000/testSdkSqs"),
satisfies(
stringKey("aws.request_id"),
val -> val.isInstanceOf(String.class)),
equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "aws-api"),
equalTo(RpcIncubatingAttributes.RPC_SERVICE, "AmazonSQS"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "ReceiveMessage"),
Expand Down Expand Up @@ -206,6 +215,9 @@ void testSimpleSqsProducerConsumerServicesWithParentSpan() {
equalTo(stringKey("aws.agent"), "java-aws-sdk"),
equalTo(stringKey("aws.endpoint"), "http://localhost:" + sqsPort),
equalTo(stringKey("aws.queue.name"), "testSdkSqs"),
satisfies(
stringKey("aws.request_id"),
val -> val.isInstanceOf(String.class)),
equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "aws-api"),
equalTo(RpcIncubatingAttributes.RPC_SERVICE, "AmazonSQS"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "CreateQueue"),
Expand All @@ -227,6 +239,9 @@ void testSimpleSqsProducerConsumerServicesWithParentSpan() {
equalTo(
stringKey("aws.queue.url"),
"http://localhost:" + sqsPort + "/000000000000/testSdkSqs"),
satisfies(
stringKey("aws.request_id"),
val -> val.isInstanceOf(String.class)),
equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "aws-api"),
equalTo(RpcIncubatingAttributes.RPC_SERVICE, "AmazonSQS"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "SendMessage"),
Expand Down Expand Up @@ -257,6 +272,9 @@ void testSimpleSqsProducerConsumerServicesWithParentSpan() {
equalTo(
stringKey("aws.queue.url"),
"http://localhost:" + sqsPort + "/000000000000/testSdkSqs"),
satisfies(
stringKey("aws.request_id"),
val -> val.isInstanceOf(String.class)),
equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "aws-api"),
equalTo(RpcIncubatingAttributes.RPC_SERVICE, "AmazonSQS"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "ReceiveMessage"),
Expand Down Expand Up @@ -298,6 +316,9 @@ void testSimpleSqsProducerConsumerServicesWithParentSpan() {
equalTo(
stringKey("aws.queue.url"),
"http://localhost:" + sqsPort + "/000000000000/testSdkSqs"),
satisfies(
stringKey("aws.request_id"),
val -> val.isInstanceOf(String.class)),
equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "aws-api"),
equalTo(RpcIncubatingAttributes.RPC_SERVICE, "AmazonSQS"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "ReceiveMessage"),
Expand Down
Loading
Loading