Skip to content

Commit 1512995

Browse files
zzhloginthpierce
authored andcommitted
Align with Python
1 parent cbf2371 commit 1512995

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
@@ -59,13 +59,11 @@ private AwsAttributeKeys() {}
5959
static final AttributeKey<String> AWS_QUEUE_NAME = AttributeKey.stringKey("aws.queue.name");
6060
static final AttributeKey<String> AWS_STREAM_NAME = AttributeKey.stringKey("aws.stream.name");
6161
static final AttributeKey<String> AWS_TABLE_NAME = AttributeKey.stringKey("aws.table.name");
62-
static final AttributeKey<String> AWS_AGENT_ID = AttributeKey.stringKey("aws.bedrock.agent_id");
62+
static final AttributeKey<String> AWS_AGENT_ID = AttributeKey.stringKey("aws.bedrock.agent.id");
6363
static final AttributeKey<String> AWS_KNOWLEDGEBASE_ID =
64-
AttributeKey.stringKey("aws.bedrock.knowledgebase_id");
64+
AttributeKey.stringKey("aws.bedrock.knowledgebase.id");
6565
static final AttributeKey<String> AWS_DATASOURCE_ID =
66-
AttributeKey.stringKey("aws.bedrock.datasource_id");
66+
AttributeKey.stringKey("aws.bedrock.datasource.id");
6767
static final AttributeKey<String> AWS_GUARDRAIL_ID =
68-
AttributeKey.stringKey("aws.bedrock.guardrail_id");
69-
static final AttributeKey<String> AWS_BEDROCK_RUNTIME_MODEL_ID =
70-
AttributeKey.stringKey("gen_ai.request.model");
68+
AttributeKey.stringKey("aws.bedrock.guardrail.id");
7169
}

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
@@ -43,7 +43,6 @@
4343
import static io.opentelemetry.semconv.SemanticAttributes.SERVER_SOCKET_PORT;
4444
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_BUCKET_NAME;
4545
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_AGENT_ID;
46-
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_BEDROCK_RUNTIME_MODEL_ID;
4746
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_DATASOURCE_ID;
4847
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_GUARDRAIL_ID;
4948
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_KNOWLEDGEBASE_ID;
@@ -65,6 +64,7 @@
6564
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.UNKNOWN_REMOTE_OPERATION;
6665
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.UNKNOWN_REMOTE_SERVICE;
6766
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.UNKNOWN_SERVICE;
67+
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.GEN_AI_REQUEST_MODEL;
6868
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.isAwsSDKSpan;
6969
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.isDBSpan;
7070
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.isKeyPresent;
@@ -370,12 +370,14 @@ private static String normalizeRemoteServiceName(SpanData span, String serviceNa
370370
case "AmazonSQS": // AWS SDK v1
371371
case "Sqs": // AWS SDK v2
372372
return NORMALIZED_SQS_SERVICE_NAME;
373+
// For Bedrock, Bedrock Agent, and Bedrock Agent Runtime, we can align with AWS Cloud Control and use AWS::Bedrock for RemoteService.
373374
case "Bedrock": // AWS SDK v2 & v1
374375
case "AWSBedrockAgentRuntime": // AWS SDK v1
375376
case "BedrockAgentRuntime": // AWS SDK v2
376377
case "AWSBedrockAgent": // AWS SDK v1
377378
case "BedrockAgent": // AWS SDK v2
378379
return NORMALIZED_BEDROCK_SERVICE_NAME;
380+
// For BedrockRuntime, we are using AWS::BedrockRuntime as the associated remote resource (Model) is not listed in Cloud Control.
379381
case "AmazonBedrockRuntime": // AWS SDK v1
380382
case "BedrockRuntime": // AWS SDK v2
381383
return NORMALIZED_BEDROCK_RUNTIME_SERVICE_NAME;
@@ -438,11 +440,11 @@ private static void setRemoteResourceTypeAndIdentifier(SpanData span, Attributes
438440
remoteResourceType = Optional.of(NORMALIZED_BEDROCK_SERVICE_NAME + "::Guardrail");
439441
remoteResourceIdentifier =
440442
Optional.ofNullable(escapeDelimiters(span.getAttributes().get(AWS_GUARDRAIL_ID)));
441-
} else if (isKeyPresent(span, AWS_BEDROCK_RUNTIME_MODEL_ID)) {
443+
} else if (isKeyPresent(span, GEN_AI_REQUEST_MODEL)) {
442444
remoteResourceType = Optional.of(NORMALIZED_BEDROCK_SERVICE_NAME + "::Model");
443445
remoteResourceIdentifier =
444446
Optional.ofNullable(
445-
escapeDelimiters(span.getAttributes().get(AWS_BEDROCK_RUNTIME_MODEL_ID)));
447+
escapeDelimiters(span.getAttributes().get(GEN_AI_REQUEST_MODEL)));
446448
}
447449
} else if (isDBSpan(span)) {
448450
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;
@@ -41,6 +40,7 @@
4140
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_TABLE_NAME;
4241
import static software.amazon.opentelemetry.javaagent.providers.MetricAttributeGenerator.DEPENDENCY_METRIC;
4342
import static software.amazon.opentelemetry.javaagent.providers.MetricAttributeGenerator.SERVICE_METRIC;
43+
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.GEN_AI_REQUEST_MODEL;
4444

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

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

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

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

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

0 commit comments

Comments
 (0)