Skip to content

Commit

Permalink
Align bedrock attributes naming. (#9)
Browse files Browse the repository at this point in the history
* Align bedrock attributes naming.
  • Loading branch information
zzhlogin authored Jul 10, 2024
1 parent debb9be commit d40b453
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
package io.opentelemetry.instrumentation.awssdk.v1_11;

import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_AGENT_ID;
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_DATASOURCE_ID;
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_KNOWLEDGEBASE_ID;
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_DATA_SOURCE_ID;
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_KNOWLEDGE_BASE_ID;

import io.opentelemetry.api.common.AttributeKey;
import java.util.Arrays;
Expand All @@ -18,8 +18,8 @@

enum AwsBedrockResourceType {
AGENT_TYPE(AWS_AGENT_ID, RequestAccess::getAgentId),
DATA_SOURCE_TYPE(AWS_DATASOURCE_ID, RequestAccess::getDataSourceId),
KNOWLEDGE_BASE_TYPE(AWS_KNOWLEDGEBASE_ID, RequestAccess::getKnowledgeBaseId);
DATA_SOURCE_TYPE(AWS_DATA_SOURCE_ID, RequestAccess::getDataSourceId),
KNOWLEDGE_BASE_TYPE(AWS_KNOWLEDGE_BASE_ID, RequestAccess::getKnowledgeBaseId);

@SuppressWarnings("ImmutableEnumChecker")
private final AttributeKey<String> keyAttribute;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ final class AwsExperimentalAttributes {
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_AGENT_ID = stringKey("aws.bedrock.agent.id");
static final AttributeKey<String> AWS_KNOWLEDGEBASE_ID =
stringKey("aws.bedrock.knowledgebase.id");
static final AttributeKey<String> AWS_DATASOURCE_ID = stringKey("aws.bedrock.datasource.id");
static final AttributeKey<String> AWS_KNOWLEDGE_BASE_ID =
stringKey("aws.bedrock.knowledge_base.id");
static final AttributeKey<String> AWS_DATA_SOURCE_ID = stringKey("aws.bedrock.data_source.id");
static final AttributeKey<String> AWS_GUARDRAIL_ID = stringKey("aws.bedrock.guardrail.id");

// TODO: Merge in gen_ai attributes in opentelemetry-semconv-incubating once upgrade to v1.26.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_BUCKET_NAME;
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_ENDPOINT;
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_GUARDRAIL_ID;
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_KNOWLEDGEBASE_ID;
import static io.opentelemetry.instrumentation.awssdk.v1_11.AwsExperimentalAttributes.AWS_KNOWLEDGE_BASE_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_REQUEST_ID;
Expand Down Expand Up @@ -107,7 +107,7 @@ private static void bedrockOnStart(
case BEDROCK_AGENT_RUNTIME_SERVICE:
setAttribute(attributes, AWS_AGENT_ID, originalRequest, RequestAccess::getAgentId);
setAttribute(
attributes, AWS_KNOWLEDGEBASE_ID, originalRequest, RequestAccess::getKnowledgeBaseId);
attributes, AWS_KNOWLEDGE_BASE_ID, originalRequest, RequestAccess::getKnowledgeBaseId);
break;
case BEDROCK_RUNTIME_SERVICE:
if (!Objects.equals(requestClassName, "InvokeModelRequest")) {
Expand Down Expand Up @@ -143,7 +143,7 @@ private static void bedrockOnEnd(
break;
case BEDROCK_AGENT_RUNTIME_SERVICE:
setAttribute(attributes, AWS_AGENT_ID, awsResp, RequestAccess::getAgentId);
setAttribute(attributes, AWS_KNOWLEDGEBASE_ID, awsResp, RequestAccess::getKnowledgeBaseId);
setAttribute(attributes, AWS_KNOWLEDGE_BASE_ID, awsResp, RequestAccess::getKnowledgeBaseId);
break;
default:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ abstract class AbstractAws1ClientTest extends InstrumentationSpecification {
}
"""
"AWSBedrockAgent" | "GetAgent" | "GET" | "/" | AWSBedrockAgentClientBuilder.standard() | { c -> c.getAgent(new GetAgentRequest().withAgentId("agentId")) } | ["aws.bedrock.agent.id": "agentId"] | ""
"AWSBedrockAgent" | "GetKnowledgeBase" | "GET" | "/" | AWSBedrockAgentClientBuilder.standard() | { c -> c.getKnowledgeBase(new GetKnowledgeBaseRequest().withKnowledgeBaseId("knowledgeBaseId")) } | ["aws.bedrock.knowledgebase.id": "knowledgeBaseId"] | ""
"AWSBedrockAgent" | "GetDataSource" | "GET" | "/" | AWSBedrockAgentClientBuilder.standard() | { c -> c.getDataSource(new GetDataSourceRequest().withDataSourceId("datasourceId").withKnowledgeBaseId("knowledgeBaseId")) } | ["aws.bedrock.datasource.id": "datasourceId"] | ""
"AWSBedrockAgent" | "GetKnowledgeBase" | "GET" | "/" | AWSBedrockAgentClientBuilder.standard() | { c -> c.getKnowledgeBase(new GetKnowledgeBaseRequest().withKnowledgeBaseId("knowledgeBaseId")) } | ["aws.bedrock.knowledge_base.id": "knowledgeBaseId"] | ""
"AWSBedrockAgent" | "GetDataSource" | "GET" | "/" | AWSBedrockAgentClientBuilder.standard() | { c -> c.getDataSource(new GetDataSourceRequest().withDataSourceId("datasourceId").withKnowledgeBaseId("knowledgeBaseId")) } | ["aws.bedrock.data_source.id": "datasourceId"] | ""
"BedrockRuntime" | "InvokeModel" | "POST" | "/" | AmazonBedrockRuntimeClientBuilder.standard() |
{ c -> c.invokeModel(
new InvokeModelRequest().withModelId("anthropic.claude-v2").withBody(StandardCharsets.UTF_8.encode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ 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_BEDROCK_GUARDRAIL_ID =
stringKey("aws.bedrock.guardrail.id");
static final AttributeKey<String> AWS_BEDROCK_AGENT_ID = stringKey("aws.bedrock.agent.id");
static final AttributeKey<String> AWS_BEDROCK_DATASOURCE_ID =
stringKey("aws.bedrock.data_source.id");
static final AttributeKey<String> AWS_BEDROCK_KNOWLEDGEBASE_ID =
static final AttributeKey<String> AWS_GUARDRAIL_ID = stringKey("aws.bedrock.guardrail.id");
static final AttributeKey<String> AWS_AGENT_ID = stringKey("aws.bedrock.agent.id");
static final AttributeKey<String> AWS_DATA_SOURCE_ID = stringKey("aws.bedrock.data_source.id");
static final AttributeKey<String> AWS_KNOWLEDGE_BASE_ID =
stringKey("aws.bedrock.knowledge_base.id");

// TODO: Merge in gen_ai attributes in opentelemetry-semconv-incubating once upgrade to v1.26.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

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_AGENT_ID;
import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsExperimentalAttributes.AWS_BUCKET_NAME;
import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsExperimentalAttributes.AWS_DATA_SOURCE_ID;
import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsExperimentalAttributes.AWS_GUARDRAIL_ID;
import static io.opentelemetry.instrumentation.awssdk.v2_2.AwsExperimentalAttributes.AWS_KNOWLEDGE_BASE_ID;
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;
Expand All @@ -27,16 +27,15 @@ enum AwsSdkRequestType {
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")),
BEDROCK(request(AWS_GUARDRAIL_ID.getKey(), "guardrailIdentifier")),
BEDROCKAGENTOPERATION(
request(AWS_BEDROCK_AGENT_ID.getKey(), "agentId"),
response(AWS_BEDROCK_AGENT_ID.getKey(), "agentId")),
request(AWS_AGENT_ID.getKey(), "agentId"), response(AWS_AGENT_ID.getKey(), "agentId")),
BEDROCKDATASOURCEOPERATION(
request(AWS_BEDROCK_DATASOURCE_ID.getKey(), "dataSourceId"),
response(AWS_BEDROCK_DATASOURCE_ID.getKey(), "dataSourceId")),
request(AWS_DATA_SOURCE_ID.getKey(), "dataSourceId"),
response(AWS_DATA_SOURCE_ID.getKey(), "dataSourceId")),
BEDROCKKNOWLEDGEBASEOPERATION(
request(AWS_BEDROCK_KNOWLEDGEBASE_ID.getKey(), "knowledgeBaseId"),
response(AWS_BEDROCK_KNOWLEDGEBASE_ID.getKey(), "knowledgeBaseId")),
request(AWS_KNOWLEDGE_BASE_ID.getKey(), "knowledgeBaseId"),
response(AWS_KNOWLEDGE_BASE_ID.getKey(), "knowledgeBaseId")),
BEDROCKRUNTIME(request(GEN_AI_MODEL.getKey(), "modelId"));

// Wrapping in unmodifiableMap
Expand Down

0 comments on commit d40b453

Please sign in to comment.