Skip to content

Commit 06d874e

Browse files
committed
Align with Python
1 parent 2ce0833 commit 06d874e

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed

awsagentprovider/src/main/java/software/amazon/opentelemetry/javaagent/providers/AwsAttributeKeys.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,11 @@ private AwsAttributeKeys() {}
5656
static final AttributeKey<String> AWS_QUEUE_NAME = AttributeKey.stringKey("aws.queue.name");
5757
static final AttributeKey<String> AWS_STREAM_NAME = AttributeKey.stringKey("aws.stream.name");
5858
static final AttributeKey<String> AWS_TABLE_NAME = AttributeKey.stringKey("aws.table.name");
59-
static final AttributeKey<String> AWS_AGENT_ID = AttributeKey.stringKey("aws.bedrock.agent_id");
59+
static final AttributeKey<String> AWS_AGENT_ID = AttributeKey.stringKey("aws.bedrock.agent.id");
6060
static final AttributeKey<String> AWS_KNOWLEDGEBASE_ID =
61-
AttributeKey.stringKey("aws.bedrock.knowledgebase_id");
61+
AttributeKey.stringKey("aws.bedrock.knowledgebase.id");
6262
static final AttributeKey<String> AWS_DATASOURCE_ID =
63-
AttributeKey.stringKey("aws.bedrock.datasource_id");
63+
AttributeKey.stringKey("aws.bedrock.datasource.id");
6464
static final AttributeKey<String> AWS_GUARDRAIL_ID =
65-
AttributeKey.stringKey("aws.bedrock.guardrail_id");
66-
static final AttributeKey<String> AWS_BEDROCK_RUNTIME_MODEL_ID =
67-
AttributeKey.stringKey("gen_ai.request.model");
65+
AttributeKey.stringKey("aws.bedrock.guardrail.id");
6866
}

awsagentprovider/src/main/java/software/amazon/opentelemetry/javaagent/providers/AwsMetricAttributeGenerator.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import static io.opentelemetry.semconv.SemanticAttributes.SERVER_SOCKET_PORT;
4343
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_BUCKET_NAME;
4444
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_AGENT_ID;
45-
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_BEDROCK_RUNTIME_MODEL_ID;
4645
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_DATASOURCE_ID;
4746
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_GUARDRAIL_ID;
4847
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_KNOWLEDGEBASE_ID;
@@ -63,6 +62,7 @@
6362
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.UNKNOWN_REMOTE_OPERATION;
6463
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.UNKNOWN_REMOTE_SERVICE;
6564
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.UNKNOWN_SERVICE;
65+
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.GEN_AI_REQUEST_MODEL;
6666
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.isAwsSDKSpan;
6767
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.isDBSpan;
6868
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.isKeyPresent;
@@ -367,12 +367,14 @@ private static String normalizeRemoteServiceName(SpanData span, String serviceNa
367367
case "AmazonSQS": // AWS SDK v1
368368
case "Sqs": // AWS SDK v2
369369
return NORMALIZED_SQS_SERVICE_NAME;
370+
// For Bedrock, Bedrock Agent, and Bedrock Agent Runtime, we can align with AWS Cloud Control and use AWS::Bedrock for RemoteService.
370371
case "Bedrock": // AWS SDK v2 & v1
371372
case "AWSBedrockAgentRuntime": // AWS SDK v1
372373
case "BedrockAgentRuntime": // AWS SDK v2
373374
case "AWSBedrockAgent": // AWS SDK v1
374375
case "BedrockAgent": // AWS SDK v2
375376
return NORMALIZED_BEDROCK_SERVICE_NAME;
377+
// For BedrockRuntime, we are using AWS::BedrockRuntime as the associated remote resource (Model) is not listed in Cloud Control.
376378
case "AmazonBedrockRuntime": // AWS SDK v1
377379
case "BedrockRuntime": // AWS SDK v2
378380
return NORMALIZED_BEDROCK_RUNTIME_SERVICE_NAME;
@@ -435,11 +437,11 @@ private static void setRemoteResourceTypeAndIdentifier(SpanData span, Attributes
435437
remoteResourceType = Optional.of(NORMALIZED_BEDROCK_SERVICE_NAME + "::Guardrail");
436438
remoteResourceIdentifier =
437439
Optional.ofNullable(escapeDelimiters(span.getAttributes().get(AWS_GUARDRAIL_ID)));
438-
} else if (isKeyPresent(span, AWS_BEDROCK_RUNTIME_MODEL_ID)) {
440+
} else if (isKeyPresent(span, GEN_AI_REQUEST_MODEL)) {
439441
remoteResourceType = Optional.of(NORMALIZED_BEDROCK_SERVICE_NAME + "::Model");
440442
remoteResourceIdentifier =
441443
Optional.ofNullable(
442-
escapeDelimiters(span.getAttributes().get(AWS_BEDROCK_RUNTIME_MODEL_ID)));
444+
escapeDelimiters(span.getAttributes().get(GEN_AI_REQUEST_MODEL)));
443445
}
444446
} else if (isDBSpan(span)) {
445447
remoteResourceType = Optional.of(DB_CONNECTION_RESOURCE_TYPE);

awsagentprovider/src/main/java/software/amazon/opentelemetry/javaagent/providers/AwsSpanProcessingUtil.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ final class AwsSpanProcessingUtil {
5656
// The current longest command word is DATETIME_INTERVAL_PRECISION at 27 characters.
5757
// If we add a longer keyword to the sql dialect keyword list, need to update the constant below.
5858
static final int MAX_KEYWORD_LENGTH = 27;
59+
// TODO: Use Semantic Conventions once upgrade once upgrade to v1.26.0
60+
static final AttributeKey<String> GEN_AI_REQUEST_MODEL =
61+
AttributeKey.stringKey("gen_ai.request.model");
5962
static final Pattern SQL_DIALECT_PATTERN =
6063
Pattern.compile("^(?:" + String.join("|", getDialectKeywords()) + ")\\b");
6164

awsagentprovider/src/test/java/software/amazon/opentelemetry/javaagent/providers/AwsMetricAttributeGeneratorTest.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import static org.mockito.Mockito.mock;
2323
import static org.mockito.Mockito.when;
2424
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_AGENT_ID;
25-
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_BEDROCK_RUNTIME_MODEL_ID;
2625
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_BUCKET_NAME;
2726
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_DATASOURCE_ID;
2827
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_GUARDRAIL_ID;
@@ -40,6 +39,7 @@
4039
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_TABLE_NAME;
4140
import static software.amazon.opentelemetry.javaagent.providers.MetricAttributeGenerator.DEPENDENCY_METRIC;
4241
import static software.amazon.opentelemetry.javaagent.providers.MetricAttributeGenerator.SERVICE_METRIC;
42+
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.GEN_AI_REQUEST_MODEL;
4343

4444
import io.opentelemetry.api.common.AttributeKey;
4545
import io.opentelemetry.api.common.Attributes;
@@ -710,25 +710,51 @@ public void testSdkClientSpanWithRemoteResourceAttributes() {
710710
validateRemoteResourceAttributes("AWS::Bedrock::Agent", "test_agent_id");
711711
mockAttribute(AWS_AGENT_ID, null);
712712

713+
// Validate behaviour of AWS_BEDROCK_AGENT_ID attribute with special chars(^), then remove it.
714+
mockAttribute(AWS_AGENT_ID, "test_agent_^id");
715+
validateRemoteResourceAttributes("AWS::Bedrock::Agent", "test_agent_^^id");
716+
mockAttribute(AWS_AGENT_ID, null);
717+
713718
// Validate behaviour of AWS_KNOWLEDGEBASE_ID attribute, then remove it.
714719
mockAttribute(AWS_KNOWLEDGEBASE_ID, "test_knowledgeBase_id");
715720
validateRemoteResourceAttributes("AWS::Bedrock::KnowledgeBase", "test_knowledgeBase_id");
716721
mockAttribute(AWS_KNOWLEDGEBASE_ID, null);
717722

723+
// Validate behaviour of AWS_KNOWLEDGEBASE_ID attribute with special chars(^), then remove it.
724+
mockAttribute(AWS_KNOWLEDGEBASE_ID, "test_knowledgeBase_^id");
725+
validateRemoteResourceAttributes("AWS::Bedrock::KnowledgeBase", "test_knowledgeBase_^^id");
726+
mockAttribute(AWS_KNOWLEDGEBASE_ID, null);
727+
718728
// Validate behaviour of AWS_BEDROCK_DATASOURCE_ID attribute, then remove it.
719729
mockAttribute(AWS_DATASOURCE_ID, "test_datasource_id");
720730
validateRemoteResourceAttributes("AWS::Bedrock::DataSource", "test_datasource_id");
721731
mockAttribute(AWS_DATASOURCE_ID, null);
722732

733+
// Validate behaviour of AWS_BEDROCK_DATASOURCE_ID attribute with special chars(^), then remove it.
734+
mockAttribute(AWS_DATASOURCE_ID, "test_datasource_^id");
735+
validateRemoteResourceAttributes("AWS::Bedrock::DataSource", "test_datasource_^^id");
736+
mockAttribute(AWS_DATASOURCE_ID, null);
737+
723738
// Validate behaviour of AWS_GUARDRAIL_ID attribute, then remove it.
724739
mockAttribute(AWS_GUARDRAIL_ID, "test_guardrail_id");
725740
validateRemoteResourceAttributes("AWS::Bedrock::Guardrail", "test_guardrail_id");
726741
mockAttribute(AWS_GUARDRAIL_ID, null);
727742

743+
// Validate behaviour of AWS_GUARDRAIL_ID attribute with special chars(^), then remove it.
744+
mockAttribute(AWS_GUARDRAIL_ID, "test_guardrail_^id");
745+
validateRemoteResourceAttributes("AWS::Bedrock::Guardrail", "test_guardrail_^^id");
746+
mockAttribute(AWS_GUARDRAIL_ID, null);
747+
728748
// Validate behaviour of AWS_BEDROCK_RUNTIME_MODEL_ID attribute, then remove it.
729-
mockAttribute(AWS_BEDROCK_RUNTIME_MODEL_ID, "test.service-id");
730-
validateRemoteResourceAttributes("AWS::Bedrock::Model", "test.service-id");
731-
mockAttribute(AWS_BEDROCK_RUNTIME_MODEL_ID, null);
749+
mockAttribute(GEN_AI_REQUEST_MODEL, "test.service_id");
750+
validateRemoteResourceAttributes("AWS::Bedrock::Model", "test.service_id");
751+
mockAttribute(GEN_AI_REQUEST_MODEL, null);
752+
mockAttribute(RPC_SYSTEM, "null");
753+
754+
// Validate behaviour of AWS_BEDROCK_RUNTIME_MODEL_ID attribute with special chars(^), then remove it.
755+
mockAttribute(GEN_AI_REQUEST_MODEL, "test.service_^id");
756+
validateRemoteResourceAttributes("AWS::Bedrock::Model", "test.service_^^id");
757+
mockAttribute(GEN_AI_REQUEST_MODEL, null);
732758
mockAttribute(RPC_SYSTEM, "null");
733759
}
734760

0 commit comments

Comments
 (0)