diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsExperimentalAttributes.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsExperimentalAttributes.java new file mode 100644 index 000000000000..049410cec77a --- /dev/null +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsExperimentalAttributes.java @@ -0,0 +1,31 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.awssdk.v2_2; + +import static io.opentelemetry.api.common.AttributeKey.stringKey; + +import io.opentelemetry.api.common.AttributeKey; + +final class AwsExperimentalAttributes { + static final AttributeKey AWS_BUCKET_NAME = stringKey("aws.bucket.name"); + static final AttributeKey AWS_QUEUE_URL = stringKey("aws.queue.url"); + static final AttributeKey AWS_QUEUE_NAME = stringKey("aws.queue.name"); + static final AttributeKey AWS_STREAM_NAME = stringKey("aws.stream.name"); + static final AttributeKey AWS_TABLE_NAME = stringKey("aws.table.name"); + static final AttributeKey AWS_BEDROCK_GUARDRAIL_ID = + stringKey("aws.bedrock.guardrail.id"); + static final AttributeKey AWS_BEDROCK_AGENT_ID = stringKey("aws.bedrock.agent.id"); + static final AttributeKey AWS_BEDROCK_DATASOURCE_ID = + stringKey("aws.bedrock.data_source.id"); + static final AttributeKey AWS_BEDROCK_KNOWLEDGEBASE_ID = + stringKey("aws.bedrock.knowledge_base.id"); + + // TODO: Merge in gen_ai attributes in opentelemetry-semconv-incubating once upgrade to v1.26.0 + static final AttributeKey GEN_AI_MODEL = stringKey("gen_ai.request.model"); + static final AttributeKey GEN_AI_SYSTEM = stringKey("gen_ai.system"); + + private AwsExperimentalAttributes() {} +} diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkRequest.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkRequest.java index 54253d0f7bcb..aa570c8ce34b 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkRequest.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkRequest.java @@ -5,6 +5,11 @@ package io.opentelemetry.instrumentation.awssdk.v2_2; +import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsSdkRequestType.BEDROCK; +import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsSdkRequestType.BEDROCKAGENTOPERATION; +import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsSdkRequestType.BEDROCKDATASOURCEOPERATION; +import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsSdkRequestType.BEDROCKKNOWLEDGEBASEOPERATION; +import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsSdkRequestType.BEDROCKRUNTIME; import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsSdkRequestType.DYNAMODB; import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsSdkRequestType.KINESIS; import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsSdkRequestType.S3; @@ -32,6 +37,45 @@ enum AwsSdkRequest { S3Request(S3, "S3Request"), SqsRequest(SQS, "SqsRequest"), KinesisRequest(KINESIS, "KinesisRequest"), + BedrockRequest(BEDROCK, "BedrockRequest"), + BedrockAgentRuntimeRequest(BEDROCKAGENTOPERATION, "BedrockAgentRuntimeRequest"), + BedrockRuntimeRequest(BEDROCKRUNTIME, "BedrockRuntimeRequest"), + // BedrockAgent API based requests. We only support operations that are related to + // Agent/DataSources/KnowledgeBases + // resources and the request/response context contains the resource ID. + BedrockCreateAgentActionGroupRequest(BEDROCKAGENTOPERATION, "CreateAgentActionGroupRequest"), + BedrockCreateAgentAliasRequest(BEDROCKAGENTOPERATION, "CreateAgentAliasRequest"), + BedrockDeleteAgentActionGroupRequest(BEDROCKAGENTOPERATION, "DeleteAgentActionGroupRequest"), + BedrockDeleteAgentAliasRequest(BEDROCKAGENTOPERATION, "DeleteAgentAliasRequest"), + BedrockDeleteAgentVersionRequest(BEDROCKAGENTOPERATION, "DeleteAgentVersionRequest"), + BedrockGetAgentActionGroupRequest(BEDROCKAGENTOPERATION, "GetAgentActionGroupRequest"), + BedrockGetAgentAliasRequest(BEDROCKAGENTOPERATION, "GetAgentAliasRequest"), + BedrockGetAgentRequest(BEDROCKAGENTOPERATION, "GetAgentRequest"), + BedrockGetAgentVersionRequest(BEDROCKAGENTOPERATION, "GetAgentVersionRequest"), + BedrockListAgentActionGroupsRequest(BEDROCKAGENTOPERATION, "ListAgentActionGroupsRequest"), + BedrockListAgentAliasesRequest(BEDROCKAGENTOPERATION, "ListAgentAliasesRequest"), + BedrockListAgentKnowledgeBasesRequest(BEDROCKAGENTOPERATION, "ListAgentKnowledgeBasesRequest"), + BedrocListAgentVersionsRequest(BEDROCKAGENTOPERATION, "ListAgentVersionsRequest"), + BedrockPrepareAgentRequest(BEDROCKAGENTOPERATION, "PrepareAgentRequest"), + BedrockUpdateAgentActionGroupRequest(BEDROCKAGENTOPERATION, "UpdateAgentActionGroupRequest"), + BedrockUpdateAgentAliasRequest(BEDROCKAGENTOPERATION, "UpdateAgentAliasRequest"), + BedrockUpdateAgentRequest(BEDROCKAGENTOPERATION, "UpdateAgentRequest"), + BedrockBedrockAgentRequest(BEDROCKAGENTOPERATION, "BedrockAgentRequest"), + BedrockDeleteDataSourceRequest(BEDROCKDATASOURCEOPERATION, "DeleteDataSourceRequest"), + BedrockGetDataSourceRequest(BEDROCKDATASOURCEOPERATION, "GetDataSourceRequest"), + BedrockUpdateDataSourceRequest(BEDROCKDATASOURCEOPERATION, "UpdateDataSourceRequest"), + BedrocAssociateAgentKnowledgeBaseRequest( + BEDROCKKNOWLEDGEBASEOPERATION, "AssociateAgentKnowledgeBaseRequest"), + BedrockCreateDataSourceRequest(BEDROCKKNOWLEDGEBASEOPERATION, "CreateDataSourceRequest"), + BedrockDeleteKnowledgeBaseRequest(BEDROCKKNOWLEDGEBASEOPERATION, "DeleteKnowledgeBaseRequest"), + BedrockDisassociateAgentKnowledgeBaseRequest( + BEDROCKKNOWLEDGEBASEOPERATION, "DisassociateAgentKnowledgeBaseRequest"), + BedrockGetAgentKnowledgeBaseRequest( + BEDROCKKNOWLEDGEBASEOPERATION, "GetAgentKnowledgeBaseRequest"), + BedrockGetKnowledgeBaseRequest(BEDROCKKNOWLEDGEBASEOPERATION, "GetKnowledgeBaseRequest"), + BedrockListDataSourcesRequest(BEDROCKKNOWLEDGEBASEOPERATION, "ListDataSourcesRequest"), + BedrockUpdateAgentKnowledgeBaseRequest( + BEDROCKKNOWLEDGEBASEOPERATION, "UpdateAgentKnowledgeBaseRequest"), // specific requests BatchGetItem( DYNAMODB, diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkRequestType.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkRequestType.java index 9062f2aa1738..fe9f4803e3f2 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkRequestType.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkRequestType.java @@ -5,17 +5,39 @@ package io.opentelemetry.instrumentation.awssdk.v2_2; +import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsExperimentalAttributes.AWS_BEDROCK_AGENT_ID; +import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsExperimentalAttributes.AWS_BEDROCK_DATASOURCE_ID; +import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsExperimentalAttributes.AWS_BEDROCK_GUARDRAIL_ID; +import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsExperimentalAttributes.AWS_BEDROCK_KNOWLEDGEBASE_ID; +import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsExperimentalAttributes.AWS_BUCKET_NAME; +import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsExperimentalAttributes.AWS_QUEUE_NAME; +import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsExperimentalAttributes.AWS_QUEUE_URL; +import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsExperimentalAttributes.AWS_STREAM_NAME; +import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsExperimentalAttributes.AWS_TABLE_NAME; +import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsExperimentalAttributes.GEN_AI_MODEL; import static io.opentelemetry.instrumentation.awssdk.v2_2.FieldMapping.request; +import static io.opentelemetry.instrumentation.awssdk.v2_2.FieldMapping.response; import java.util.Collections; import java.util.List; import java.util.Map; enum AwsSdkRequestType { - S3(request("aws.bucket.name", "Bucket")), - SQS(request("aws.queue.url", "QueueUrl"), request("aws.queue.name", "QueueName")), - KINESIS(request("aws.stream.name", "StreamName")), - DYNAMODB(request("aws.table.name", "TableName")); + S3(request(AWS_BUCKET_NAME.getKey(), "Bucket")), + SQS(request(AWS_QUEUE_URL.getKey(), "QueueUrl"), request(AWS_QUEUE_NAME.getKey(), "QueueName")), + KINESIS(request(AWS_STREAM_NAME.getKey(), "StreamName")), + DYNAMODB(request(AWS_TABLE_NAME.getKey(), "TableName")), + BEDROCK(request(AWS_BEDROCK_GUARDRAIL_ID.getKey(), "guardrailIdentifier")), + BEDROCKAGENTOPERATION( + request(AWS_BEDROCK_AGENT_ID.getKey(), "agentId"), + response(AWS_BEDROCK_AGENT_ID.getKey(), "agentId")), + BEDROCKDATASOURCEOPERATION( + request(AWS_BEDROCK_DATASOURCE_ID.getKey(), "dataSourceId"), + response(AWS_BEDROCK_DATASOURCE_ID.getKey(), "dataSourceId")), + BEDROCKKNOWLEDGEBASEOPERATION( + request(AWS_BEDROCK_KNOWLEDGEBASE_ID.getKey(), "knowledgeBaseId"), + response(AWS_BEDROCK_KNOWLEDGEBASE_ID.getKey(), "knowledgeBaseId")), + BEDROCKRUNTIME(request(GEN_AI_MODEL.getKey(), "modelId")); // Wrapping in unmodifiableMap @SuppressWarnings("ImmutableEnumChecker") diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/TracingExecutionInterceptor.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/TracingExecutionInterceptor.java index f717b1efc44c..352b02093ef9 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/TracingExecutionInterceptor.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/TracingExecutionInterceptor.java @@ -5,6 +5,8 @@ package io.opentelemetry.instrumentation.awssdk.v2_2; +import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsExperimentalAttributes.GEN_AI_SYSTEM; +import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsSdkRequestType.BEDROCKRUNTIME; import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsSdkRequestType.DYNAMODB; import io.opentelemetry.api.common.AttributeKey; @@ -42,6 +44,7 @@ /** AWS request execution interceptor. */ final class TracingExecutionInterceptor implements ExecutionInterceptor { + private static final String GEN_AI_SYSTEM_BEDROCK = "aws_bedrock"; // the class name is part of the attribute name, so that it will be shaded when used in javaagent // instrumentation, and won't conflict with usage outside javaagent instrumentation @@ -317,6 +320,10 @@ private void populateRequestAttributes( span.setAttribute(SemanticAttributes.DB_OPERATION, operation); } } + + if (awsSdkRequest.type() == BEDROCKRUNTIME) { + span.setAttribute(GEN_AI_SYSTEM, GEN_AI_SYSTEM_BEDROCK); + } } @Override diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientTest.groovy b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientTest.groovy index 53390c8d8524..2833570ca2b6 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientTest.groovy +++ b/instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/groovy/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientTest.groovy @@ -120,7 +120,19 @@ abstract class AbstractAws2ClientTest extends AbstractAws2ClientCoreTest { "$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS" } else if (service == "Kinesis") { "aws.stream.name" "somestream" + } else if (service == "Bedrock" && operation == "GetGuardrail") { + "aws.bedrock.guardrail.id" "guardrailId" + } else if (service == "BedrockAgent" && operation == "GetAgent") { + "aws.bedrock.agent.id" "agentId" + } else if (service == "BedrockAgent" && operation == "GetKnowledgeBase") { + "aws.bedrock.knowledge_base.id" "knowledgeBaseId" + } else if (service == "BedrockAgent" && operation == "GetDataSource") { + "aws.bedrock.data_source.id" "datasourceId" + } else if (service == "BedrockRuntime" && operation == "InvokeModel") { + "gen_ai.request.model" "meta.llama2-13b-chat-v1" + "gen_ai.system" "aws_bedrock" } + } } }