Skip to content

Commit 1fec593

Browse files
committed
feat: Add new attribute for Cloudformation Primary Identifier
1 parent 6c23981 commit 1fec593

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
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
@@ -1,6 +1,7 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
"""Utility module holding attribute keys with special meaning to AWS components"""
4+
AWS_CLOUDFORMATION_PRIMARY_IDENTIFIER: str = "aws.remote.resource.cfn.primary.identifier"
45
AWS_SPAN_KIND: str = "aws.span.kind"
56
AWS_LOCAL_SERVICE: str = "aws.local.service"
67
AWS_LOCAL_OPERATION: str = "aws.local.operation"

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
AWS_BEDROCK_DATA_SOURCE_ID,
1111
AWS_BEDROCK_GUARDRAIL_ID,
1212
AWS_BEDROCK_KNOWLEDGE_BASE_ID,
13+
AWS_CLOUDFORMATION_PRIMARY_IDENTIFIER,
1314
AWS_KINESIS_STREAM_NAME,
1415
AWS_LOCAL_OPERATION,
1516
AWS_LOCAL_SERVICE,
@@ -377,54 +378,68 @@ def _set_remote_type_and_identifier(span: ReadableSpan, attributes: BoundedAttri
377378
"""
378379
remote_resource_type: Optional[str] = None
379380
remote_resource_identifier: Optional[str] = None
381+
cloudformation_primary_identifier: Optional[str] = None
380382

381383
if is_aws_sdk_span(span):
382384
# Only extract the table name when _AWS_TABLE_NAMES has size equals to one
383385
if is_key_present(span, _AWS_TABLE_NAMES) and len(span.attributes.get(_AWS_TABLE_NAMES)) == 1:
384386
remote_resource_type = _NORMALIZED_DYNAMO_DB_SERVICE_NAME + "::Table"
385387
remote_resource_identifier = _escape_delimiters(span.attributes.get(_AWS_TABLE_NAMES)[0])
388+
cloudformation_primary_identifier = ""
386389
elif is_key_present(span, AWS_KINESIS_STREAM_NAME):
387390
remote_resource_type = _NORMALIZED_KINESIS_SERVICE_NAME + "::Stream"
388391
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_KINESIS_STREAM_NAME))
392+
cloudformation_primary_identifier = ""
389393
elif is_key_present(span, _AWS_BUCKET_NAME):
390394
remote_resource_type = _NORMALIZED_S3_SERVICE_NAME + "::Bucket"
391395
remote_resource_identifier = _escape_delimiters(span.attributes.get(_AWS_BUCKET_NAME))
396+
cloudformation_primary_identifier = ""
392397
elif is_key_present(span, AWS_SQS_QUEUE_NAME):
393398
remote_resource_type = _NORMALIZED_SQS_SERVICE_NAME + "::Queue"
394399
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_SQS_QUEUE_NAME))
400+
cloudformation_primary_identifier = ""
395401
elif is_key_present(span, AWS_SQS_QUEUE_URL):
396402
remote_resource_type = _NORMALIZED_SQS_SERVICE_NAME + "::Queue"
397403
remote_resource_identifier = _escape_delimiters(
398404
SqsUrlParser.get_queue_name(span.attributes.get(AWS_SQS_QUEUE_URL))
399405
)
406+
cloudformation_primary_identifier = ""
400407
elif is_key_present(span, AWS_BEDROCK_AGENT_ID):
401408
remote_resource_type = _NORMALIZED_BEDROCK_SERVICE_NAME + "::Agent"
402409
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_BEDROCK_AGENT_ID))
410+
cloudformation_primary_identifier = ""
403411
elif is_key_present(span, AWS_BEDROCK_DATA_SOURCE_ID):
404412
remote_resource_type = _NORMALIZED_BEDROCK_SERVICE_NAME + "::DataSource"
405413
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_BEDROCK_DATA_SOURCE_ID))
414+
cloudformation_primary_identifier = ""
406415
elif is_key_present(span, AWS_BEDROCK_GUARDRAIL_ID):
407416
remote_resource_type = _NORMALIZED_BEDROCK_SERVICE_NAME + "::Guardrail"
408417
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_BEDROCK_GUARDRAIL_ID))
418+
cloudformation_primary_identifier = ""
409419
elif is_key_present(span, AWS_BEDROCK_KNOWLEDGE_BASE_ID):
410420
remote_resource_type = _NORMALIZED_BEDROCK_SERVICE_NAME + "::KnowledgeBase"
411421
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_BEDROCK_KNOWLEDGE_BASE_ID))
422+
cloudformation_primary_identifier = ""
412423
elif is_key_present(span, GEN_AI_REQUEST_MODEL):
413424
remote_resource_type = _NORMALIZED_BEDROCK_SERVICE_NAME + "::Model"
414425
remote_resource_identifier = _escape_delimiters(span.attributes.get(GEN_AI_REQUEST_MODEL))
426+
cloudformation_primary_identifier = ""
415427
elif is_key_present(span, AWS_SNS_TOPIC_ARN):
416428
remote_resource_type = _NORMALIZED_SNS_SERVICE_NAME + "::Topic"
417429
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_SNS_TOPIC_ARN))
430+
cloudformation_primary_identifier = remote_resource_identifier
418431
elif is_key_present(span, AWS_SECRETSMANAGER_SECRET_ARN):
419432
remote_resource_type = _NORMALIZED_SECRETSMANAGER_SERVICE_NAME + "::Secret"
420433
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_SECRETSMANAGER_SECRET_ARN))
434+
cloudformation_primary_identifier = remote_resource_identifier
421435
elif is_db_span(span):
422436
remote_resource_type = _DB_CONNECTION_STRING_TYPE
423437
remote_resource_identifier = _get_db_connection(span)
424438

425-
if remote_resource_type is not None and remote_resource_identifier is not None:
439+
if remote_resource_type is not None and remote_resource_identifier is not None and cloudformation_primary_identifier is not None:
426440
attributes[AWS_REMOTE_RESOURCE_TYPE] = remote_resource_type
427441
attributes[AWS_REMOTE_RESOURCE_IDENTIFIER] = remote_resource_identifier
442+
attributes[AWS_CLOUDFORMATION_PRIMARY_IDENTIFIER] = cloudformation_primary_identifier
428443

429444

430445
def _get_db_connection(span: ReadableSpan) -> None:

0 commit comments

Comments
 (0)