Skip to content

Commit d723f96

Browse files
authored
fix: update bedrock guardrail cfn primary id to be arn (#278)
### *Summary of Changes:* - Updating the CFN Primary Id for Guardrail to be the ARN. (Verified this in the AWS Cloudformation Console) ![Screenshot 2024-10-09 at 12 44 12 PM](https://github.com/user-attachments/assets/1a7437f1-4269-42f0-b4d9-db9f5f37b3a7) ### *Testing Plan:* Set up sample apps and manually verified correct span attributes were generated via auto-instrumentation. ![bedrock-guardrail-span-data-verification-python](https://github.com/user-attachments/assets/802b95c9-85d0-404b-b64b-be53f38f3964) By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent 75af98a commit d723f96

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_attribute_keys.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
AWS_BEDROCK_KNOWLEDGE_BASE_ID: str = "aws.bedrock.knowledge_base.id"
2424
AWS_BEDROCK_AGENT_ID: str = "aws.bedrock.agent.id"
2525
AWS_BEDROCK_GUARDRAIL_ID: str = "aws.bedrock.guardrail.id"
26+
AWS_BEDROCK_GUARDRAIL_ARN: str = "aws.bedrock.guardrail.arn"
2627
AWS_SECRETSMANAGER_SECRET_ARN: str = "aws.secretsmanager.secret.arn"
2728
AWS_SNS_TOPIC_ARN: str = "aws.sns.topic.arn"
2829
AWS_STEPFUNCTIONS_STATEMACHINE_ARN: str = "aws.stepfunctions.state_machine.arn"

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_metric_attribute_generator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from amazon.opentelemetry.distro._aws_attribute_keys import (
99
AWS_BEDROCK_AGENT_ID,
1010
AWS_BEDROCK_DATA_SOURCE_ID,
11+
AWS_BEDROCK_GUARDRAIL_ARN,
1112
AWS_BEDROCK_GUARDRAIL_ID,
1213
AWS_BEDROCK_KNOWLEDGE_BASE_ID,
1314
AWS_CLOUDFORMATION_PRIMARY_IDENTIFIER,
@@ -423,6 +424,7 @@ def _set_remote_type_and_identifier(span: ReadableSpan, attributes: BoundedAttri
423424
elif is_key_present(span, AWS_BEDROCK_GUARDRAIL_ID):
424425
remote_resource_type = _NORMALIZED_BEDROCK_SERVICE_NAME + "::Guardrail"
425426
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_BEDROCK_GUARDRAIL_ID))
427+
cloudformation_primary_identifier = _escape_delimiters(span.attributes.get(AWS_BEDROCK_GUARDRAIL_ARN))
426428
elif is_key_present(span, AWS_BEDROCK_KNOWLEDGE_BASE_ID):
427429
remote_resource_type = _NORMALIZED_BEDROCK_SERVICE_NAME + "::KnowledgeBase"
428430
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_BEDROCK_KNOWLEDGE_BASE_ID))

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/patches/_bedrock_patches.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from amazon.opentelemetry.distro._aws_attribute_keys import (
88
AWS_BEDROCK_AGENT_ID,
99
AWS_BEDROCK_DATA_SOURCE_ID,
10+
AWS_BEDROCK_GUARDRAIL_ARN,
1011
AWS_BEDROCK_GUARDRAIL_ID,
1112
AWS_BEDROCK_KNOWLEDGE_BASE_ID,
1213
)
@@ -23,6 +24,7 @@
2324
_KNOWLEDGE_BASE_ID: str = "knowledgeBaseId"
2425
_DATA_SOURCE_ID: str = "dataSourceId"
2526
_GUARDRAIL_ID: str = "guardrailId"
27+
_GUARDRAIL_ARN: str = "guardrailArn"
2628
_MODEL_ID: str = "modelId"
2729
_AWS_BEDROCK_SYSTEM: str = "aws_bedrock"
2830

@@ -217,6 +219,13 @@ def on_success(self, span: Span, result: _BotoResultT):
217219
guardrail_id,
218220
)
219221

222+
guardrail_arn = result.get(_GUARDRAIL_ARN)
223+
if guardrail_arn:
224+
span.set_attribute(
225+
AWS_BEDROCK_GUARDRAIL_ARN,
226+
guardrail_arn,
227+
)
228+
220229

221230
class _BedrockRuntimeExtension(_AwsSdkExtension):
222231
"""

0 commit comments

Comments
 (0)