Skip to content

Commit 7a748b3

Browse files
committed
refactor: extract guardrail remote id from cloudformation primary id
1 parent e6d6f85 commit 7a748b3

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ private static void setRemoteResourceTypeAndIdentifier(SpanData span, Attributes
455455
} else if (isKeyPresent(span, AWS_GUARDRAIL_ID)) {
456456
remoteResourceType = Optional.of(NORMALIZED_BEDROCK_SERVICE_NAME + "::Guardrail");
457457
remoteResourceIdentifier =
458-
Optional.ofNullable(escapeDelimiters(span.getAttributes().get(AWS_GUARDRAIL_ID)));
458+
getBedrockGuardrailIdentifierFromArn(
459+
Optional.ofNullable(escapeDelimiters(span.getAttributes().get(AWS_GUARDRAIL_ARN))));
459460
cloudformationPrimaryIdentifier =
460461
Optional.ofNullable(escapeDelimiters(span.getAttributes().get(AWS_GUARDRAIL_ARN)));
461462
} else if (isKeyPresent(span, GEN_AI_REQUEST_MODEL)) {
@@ -529,6 +530,11 @@ private static Optional<String> getLambdaResourceNameFromAribitraryName(
529530
return arbitraryName;
530531
}
531532

533+
private static Optional<String> getBedrockGuardrailIdentifierFromArn(Optional<String> stringArn) {
534+
Arn resourceArn = Arn.fromString(stringArn.get());
535+
return Optional.of(resourceArn.getResource().toString().split(":")[1]);
536+
}
537+
532538
private static Optional<String> getSecretsManagerResourceNameFromArn(Optional<String> stringArn) {
533539
Arn resourceArn = Arn.fromString(stringArn.get());
534540
return Optional.of(resourceArn.getResource().toString().split(":")[1]);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_AGENT_ID;
2525
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_BUCKET_NAME;
2626
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_DATA_SOURCE_ID;
27+
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_GUARDRAIL_ARN;
2728
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_GUARDRAIL_ID;
2829
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_KNOWLEDGE_BASE_ID;
2930
import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_LAMBDA_NAME;
@@ -758,13 +759,19 @@ public void testSdkClientSpanWithRemoteResourceAttributes() {
758759

759760
// Validate behaviour of AWS_GUARDRAIL_ID attribute, then remove it.
760761
mockAttribute(AWS_GUARDRAIL_ID, "test_guardrail_id");
762+
mockAttribute(
763+
AWS_GUARDRAIL_ARN, "arn:aws:bedrock:us-west-2:123456789012:guardrail/test_guardrail_id");
761764
validateRemoteResourceAttributes("AWS::Bedrock::Guardrail", "test_guardrail_id");
762765
mockAttribute(AWS_GUARDRAIL_ID, null);
766+
mockAttribute(AWS_GUARDRAIL_ARN, null);
763767

764768
// Validate behaviour of AWS_GUARDRAIL_ID attribute with special chars(^), then remove it.
765769
mockAttribute(AWS_GUARDRAIL_ID, "test_guardrail_^id");
770+
mockAttribute(
771+
AWS_GUARDRAIL_ARN, "arn:aws:bedrock:us-west-2:123456789012:guardrail/test_guardrail_^id");
766772
validateRemoteResourceAttributes("AWS::Bedrock::Guardrail", "test_guardrail_^^id");
767773
mockAttribute(AWS_GUARDRAIL_ID, null);
774+
mockAttribute(AWS_GUARDRAIL_ARN, null);
768775

769776
// Validate behaviour of GEN_AI_REQUEST_MODEL attribute, then remove it.
770777
mockAttribute(GEN_AI_REQUEST_MODEL, "test.service_id");

0 commit comments

Comments
 (0)