Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -47,6 +47,8 @@ dependencies {
testLibrary("com.amazonaws:aws-java-sdk-kinesis:1.11.106")
testLibrary("com.amazonaws:aws-java-sdk-dynamodb:1.11.106")
testLibrary("com.amazonaws:aws-java-sdk-sns:1.11.106")
testLibrary("com.amazonaws:aws-java-sdk-stepfunctions:1.11.106")
testLibrary("com.amazonaws:aws-java-sdk-lambda:1.11.106")

testImplementation(project(":instrumentation:aws-sdk:aws-sdk-1.11:testing"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static SpanDataAssert sns(SpanDataAssert span, String topicArn, String rpcMethod
.hasAttributesSatisfyingExactly(
equalTo(stringKey("aws.agent"), "java-aws-sdk"),
equalTo(MESSAGING_DESTINATION_NAME, topicArn),
satisfies(stringKey("aws.sns.topic.arn"), v -> v.isInstanceOf(String.class)),
satisfies(AWS_REQUEST_ID, v -> v.isInstanceOf(String.class)),
equalTo(RPC_METHOD, rpcMethod),
equalTo(RPC_SYSTEM, "aws-api"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.awssdk.v1_11;

import com.amazonaws.services.lambda.AWSLambdaClientBuilder;
import io.opentelemetry.instrumentation.awssdk.v1_11.AbstractLambdaClientTest;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import org.junit.jupiter.api.extension.RegisterExtension;

class LambdaClientTest extends AbstractLambdaClientTest {
@RegisterExtension
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();

@Override
protected InstrumentationExtension testing() {
return testing;
}

@Override
public AWSLambdaClientBuilder configureClient(AWSLambdaClientBuilder clientBuilder) {
return clientBuilder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.awssdk.v1_11;

import com.amazonaws.services.stepfunctions.AWSStepFunctionsClientBuilder;
import io.opentelemetry.instrumentation.awssdk.v1_11.AbstractStepFunctionsClientTest;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import org.junit.jupiter.api.extension.RegisterExtension;

class StepFunctionsClientTest extends AbstractStepFunctionsClientTest {
@RegisterExtension
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();

@Override
protected InstrumentationExtension testing() {
return testing;
}

@Override
public AWSStepFunctionsClientBuilder configureClient(
AWSStepFunctionsClientBuilder clientBuilder) {
return clientBuilder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ dependencies {
testLibrary("com.amazonaws:aws-java-sdk-kinesis:1.11.106")
testLibrary("com.amazonaws:aws-java-sdk-dynamodb:1.11.106")
testLibrary("com.amazonaws:aws-java-sdk-sns:1.11.106")
testLibrary("com.amazonaws:aws-java-sdk-stepfunctions:1.11.106")
testLibrary("com.amazonaws:aws-java-sdk-lambda:1.11.106")

// Tests on the MacBook indicate that this keeps the core at version 1.11.0.
testLibrary("com.amazonaws:aws-java-sdk-secretsmanager:1.11.309")

// last version that does not use json protocol
latestDepTestLibrary("com.amazonaws:aws-java-sdk-sqs:1.12.583") // documented limitation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ 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_STATE_MACHINE_ARN =
stringKey("aws.stepfunctions.state_machine.arn");
static final AttributeKey<String> AWS_STEP_FUNCTIONS_ACTIVITY_ARN =
stringKey("aws.stepfunctions.activity.arn");
static final AttributeKey<String> AWS_SNS_TOPIC_ARN = stringKey("aws.sns.topic.arn");
static final AttributeKey<String> AWS_SECRET_ARN = stringKey("aws.secretsmanager.secret.arn");
static final AttributeKey<String> AWS_LAMBDA_NAME = stringKey("aws.lambda.function.name");
static final AttributeKey<String> AWS_LAMBDA_RESOURCE_ID =
stringKey("aws.lambda.resource_mapping.id");

private AwsExperimentalAttributes() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@

import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_AGENT;
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_BUCKET_NAME;
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_LAMBDA_NAME;
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_LAMBDA_RESOURCE_ID;
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_QUEUE_NAME;
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_QUEUE_URL;
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_SECRET_ARN;
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_SNS_TOPIC_ARN;
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_STATE_MACHINE_ARN;
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_STEP_FUNCTIONS_ACTIVITY_ARN;
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_STREAM_NAME;
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_TABLE_NAME;

Expand All @@ -35,6 +41,18 @@ public void onStart(AttributesBuilder attributes, Context parentContext, Request
setRequestAttribute(attributes, AWS_QUEUE_NAME, originalRequest, RequestAccess::getQueueName);
setRequestAttribute(attributes, AWS_STREAM_NAME, originalRequest, RequestAccess::getStreamName);
setRequestAttribute(attributes, AWS_TABLE_NAME, originalRequest, RequestAccess::getTableName);
setRequestAttribute(
attributes, AWS_STATE_MACHINE_ARN, originalRequest, RequestAccess::getStateMachineArn);
setRequestAttribute(
attributes,
AWS_STEP_FUNCTIONS_ACTIVITY_ARN,
originalRequest,
RequestAccess::getStepFunctionsActivityArn);
setRequestAttribute(attributes, AWS_SNS_TOPIC_ARN, originalRequest, RequestAccess::getTopicArn);
setRequestAttribute(attributes, AWS_SECRET_ARN, originalRequest, RequestAccess::getSecretArn);
setRequestAttribute(attributes, AWS_LAMBDA_NAME, originalRequest, RequestAccess::getLambdaName);
setRequestAttribute(
attributes, AWS_LAMBDA_RESOURCE_ID, originalRequest, RequestAccess::getLambdaResourceId);
}

private static void setRequestAttribute(
Expand All @@ -54,5 +72,18 @@ public void onEnd(
Context context,
Request<?> request,
@Nullable Response<?> response,
@Nullable Throwable error) {}
@Nullable Throwable error) {
if (response != null) {
Object awsResp = response.getAwsResponse();
setRequestAttribute(
attributes, AWS_STATE_MACHINE_ARN, awsResp, RequestAccess::getStateMachineArn);
setRequestAttribute(
attributes,
AWS_STEP_FUNCTIONS_ACTIVITY_ARN,
awsResp,
RequestAccess::getStepFunctionsActivityArn);
setRequestAttribute(attributes, AWS_SNS_TOPIC_ARN, awsResp, RequestAccess::getTopicArn);
setRequestAttribute(attributes, AWS_SECRET_ARN, awsResp, RequestAccess::getSecretArn);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import javax.annotation.Nullable;

final class RequestAccess {
private static final String LAMBDA_REQUEST_CLASS_PREFIX = "com.amazonaws.services.lambda.model.";
private static final String SECRETS_MANAGER_REQUEST_CLASS_PREFIX =
"com.amazonaws.services.secretsmanager.model.";

private static final ClassValue<RequestAccess> REQUEST_ACCESSORS =
new ClassValue<RequestAccess>() {
Expand All @@ -20,6 +23,51 @@ protected RequestAccess computeValue(Class<?> type) {
}
};

@Nullable
static String getLambdaName(Object request) {
if (request == null) {
return null;
}
RequestAccess access = REQUEST_ACCESSORS.get(request.getClass());
return invokeOrNull(access.getLambdaName, request);
}

@Nullable
static String getLambdaResourceId(Object request) {
if (request == null) {
return null;
}
RequestAccess access = REQUEST_ACCESSORS.get(request.getClass());
return invokeOrNull(access.getLambdaResourceId, request);
}

@Nullable
static String getSecretArn(Object request) {
if (request == null) {
return null;
}
RequestAccess access = REQUEST_ACCESSORS.get(request.getClass());
return invokeOrNull(access.getSecretArn, request);
}

@Nullable
static String getStepFunctionsActivityArn(Object request) {
if (request == null) {
return null;
}
RequestAccess access = REQUEST_ACCESSORS.get(request.getClass());
return invokeOrNull(access.getStepFunctionsActivityArn, request);
}

@Nullable
static String getStateMachineArn(Object request) {
if (request == null) {
return null;
}
RequestAccess access = REQUEST_ACCESSORS.get(request.getClass());
return invokeOrNull(access.getStateMachineArn, request);
}

@Nullable
static String getBucketName(Object request) {
RequestAccess access = REQUEST_ACCESSORS.get(request.getClass());
Expand Down Expand Up @@ -52,6 +100,9 @@ static String getTableName(Object request) {

@Nullable
static String getTopicArn(Object request) {
if (request == null) {
return null;
}
RequestAccess access = REQUEST_ACCESSORS.get(request.getClass());
return invokeOrNull(access.getTopicArn, request);
}
Expand All @@ -74,22 +125,40 @@ private static String invokeOrNull(@Nullable MethodHandle method, Object obj) {
}
}

@Nullable private final MethodHandle getBucketName;
@Nullable private final MethodHandle getQueueUrl;
@Nullable private final MethodHandle getQueueName;
@Nullable private final MethodHandle getStreamName;
@Nullable private final MethodHandle getTableName;
@Nullable private final MethodHandle getTopicArn;
@Nullable private final MethodHandle getTargetArn;
@Nullable private MethodHandle getBucketName;
@Nullable private MethodHandle getQueueUrl;
@Nullable private MethodHandle getQueueName;
@Nullable private MethodHandle getStreamName;
@Nullable private MethodHandle getTableName;
@Nullable private MethodHandle getTopicArn;
@Nullable private MethodHandle getTargetArn;
@Nullable private MethodHandle getStateMachineArn;
@Nullable private MethodHandle getStepFunctionsActivityArn;
@Nullable private MethodHandle getSecretArn;
@Nullable private MethodHandle getLambdaName;
@Nullable private MethodHandle getLambdaResourceId;

private RequestAccess(Class<?> clz) {
if (clz == null) {
return;
}
getBucketName = findAccessorOrNull(clz, "getBucketName");
getQueueUrl = findAccessorOrNull(clz, "getQueueUrl");
getQueueName = findAccessorOrNull(clz, "getQueueName");
getStreamName = findAccessorOrNull(clz, "getStreamName");
getTableName = findAccessorOrNull(clz, "getTableName");
getTopicArn = findAccessorOrNull(clz, "getTopicArn");
getTargetArn = findAccessorOrNull(clz, "getTargetArn");
getStateMachineArn = findAccessorOrNull(clz, "getStateMachineArn");
getStepFunctionsActivityArn = findAccessorOrNull(clz, "getActivityArn");
String className = clz.getName();
if (className.startsWith(SECRETS_MANAGER_REQUEST_CLASS_PREFIX)) {
getSecretArn = findAccessorOrNull(clz, "getARN");
}
if (className.startsWith(LAMBDA_REQUEST_CLASS_PREFIX)) {
getLambdaName = findAccessorOrNull(clz, "getFunctionName");
getLambdaResourceId = findAccessorOrNull(clz, "getUUID");
}
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.awssdk.v1_11;

import com.amazonaws.services.lambda.AWSLambdaClientBuilder;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
import org.junit.jupiter.api.extension.RegisterExtension;

class LambdaClientTest extends AbstractLambdaClientTest {
@RegisterExtension
private static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();

@Override
protected InstrumentationExtension testing() {
return testing;
}

@Override
public AWSLambdaClientBuilder configureClient(AWSLambdaClientBuilder clientBuilder) {
return clientBuilder.withRequestHandlers(
AwsSdkTelemetry.builder(testing().getOpenTelemetry())
.setCaptureExperimentalSpanAttributes(true)
.build()
.newRequestHandler());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.awssdk.v1_11;

import com.amazonaws.services.secretsmanager.AWSSecretsManagerClientBuilder;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
import org.junit.jupiter.api.extension.RegisterExtension;

class SecretsManagerClientTest extends AbstractSecretsManagerClientTest {
@RegisterExtension
private static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();

@Override
protected InstrumentationExtension testing() {
return testing;
}

@Override
public AWSSecretsManagerClientBuilder configureClient(
AWSSecretsManagerClientBuilder clientBuilder) {

return clientBuilder.withRequestHandlers(
AwsSdkTelemetry.builder(testing().getOpenTelemetry())
.setCaptureExperimentalSpanAttributes(true)
.build()
.newRequestHandler());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.awssdk.v1_11;

import com.amazonaws.services.stepfunctions.AWSStepFunctionsClientBuilder;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
import org.junit.jupiter.api.extension.RegisterExtension;

class StepFunctionsClientTest extends AbstractStepFunctionsClientTest {
@RegisterExtension
private static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();

@Override
protected InstrumentationExtension testing() {
return testing;
}

@Override
public AWSStepFunctionsClientBuilder configureClient(
AWSStepFunctionsClientBuilder clientBuilder) {
return clientBuilder.withRequestHandlers(
AwsSdkTelemetry.builder(testing().getOpenTelemetry())
.setCaptureExperimentalSpanAttributes(true)
.build()
.newRequestHandler());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ dependencies {
compileOnly("com.amazonaws:aws-java-sdk-dynamodb:1.11.106")
compileOnly("com.amazonaws:aws-java-sdk-sns:1.11.106")
compileOnly("com.amazonaws:aws-java-sdk-sqs:1.11.106")
compileOnly("com.amazonaws:aws-java-sdk-secretsmanager:1.11.309")
compileOnly("com.amazonaws:aws-java-sdk-stepfunctions:1.11.106")
compileOnly("com.amazonaws:aws-java-sdk-lambda:1.11.106")

// needed for SQS - using emq directly as localstack references emq v0.15.7 ie WITHOUT AWS trace header propagation
implementation("org.elasticmq:elasticmq-rest-sqs_2.13")
Expand Down
Loading
Loading