1010
1111from amazon .base .contract_test_base import NETWORK_NAME , ContractTestBase
1212from amazon .utils .application_signals_constants import (
13+ AWS_CLOUDFORMATION_PRIMARY_IDENTIFIER ,
1314 AWS_LOCAL_OPERATION ,
1415 AWS_LOCAL_SERVICE ,
1516 AWS_REMOTE_OPERATION ,
@@ -99,6 +100,7 @@ def test_s3_create_bucket(self):
99100 remote_operation = "CreateBucket" ,
100101 remote_resource_type = "AWS::S3::Bucket" ,
101102 remote_resource_identifier = "test-bucket-name" ,
103+ cloudformation_primary_identifier = "test-bucket-name" ,
102104 request_specific_attributes = {
103105 SpanAttributes .AWS_S3_BUCKET : "test-bucket-name" ,
104106 },
@@ -116,6 +118,7 @@ def test_s3_create_object(self):
116118 remote_operation = "PutObject" ,
117119 remote_resource_type = "AWS::S3::Bucket" ,
118120 remote_resource_identifier = "test-put-object-bucket-name" ,
121+ cloudformation_primary_identifier = "test-put-object-bucket-name" ,
119122 request_specific_attributes = {
120123 SpanAttributes .AWS_S3_BUCKET : "test-put-object-bucket-name" ,
121124 },
@@ -133,6 +136,7 @@ def test_s3_get_object(self):
133136 remote_operation = "GetObject" ,
134137 remote_resource_type = "AWS::S3::Bucket" ,
135138 remote_resource_identifier = "test-get-object-bucket-name" ,
139+ cloudformation_primary_identifier = "test-get-object-bucket-name" ,
136140 request_specific_attributes = {
137141 SpanAttributes .AWS_S3_BUCKET : "test-get-object-bucket-name" ,
138142 },
@@ -150,6 +154,7 @@ def test_s3_error(self):
150154 remote_operation = "CreateBucket" ,
151155 remote_resource_type = "AWS::S3::Bucket" ,
152156 remote_resource_identifier = "-" ,
157+ cloudformation_primary_identifier = "-" ,
153158 request_specific_attributes = {
154159 SpanAttributes .AWS_S3_BUCKET : "-" ,
155160 },
@@ -167,6 +172,7 @@ def test_s3_fault(self):
167172 remote_operation = "CreateBucket" ,
168173 remote_resource_type = "AWS::S3::Bucket" ,
169174 remote_resource_identifier = "valid-bucket-name" ,
175+ cloudformation_primary_identifier = "valid-bucket-name" ,
170176 request_specific_attributes = {
171177 SpanAttributes .AWS_S3_BUCKET : "valid-bucket-name" ,
172178 },
@@ -184,6 +190,7 @@ def test_dynamodb_create_table(self):
184190 remote_operation = "CreateTable" ,
185191 remote_resource_type = "AWS::DynamoDB::Table" ,
186192 remote_resource_identifier = "test_table" ,
193+ cloudformation_primary_identifier = "test_table" ,
187194 request_specific_attributes = {
188195 SpanAttributes .AWS_DYNAMODB_TABLE_NAMES : ["test_table" ],
189196 },
@@ -201,6 +208,7 @@ def test_dynamodb_put_item(self):
201208 remote_operation = "PutItem" ,
202209 remote_resource_type = "AWS::DynamoDB::Table" ,
203210 remote_resource_identifier = "put_test_table" ,
211+ cloudformation_primary_identifier = "put_test_table" ,
204212 request_specific_attributes = {
205213 SpanAttributes .AWS_DYNAMODB_TABLE_NAMES : ["put_test_table" ],
206214 },
@@ -218,6 +226,7 @@ def test_dynamodb_error(self):
218226 remote_operation = "PutItem" ,
219227 remote_resource_type = "AWS::DynamoDB::Table" ,
220228 remote_resource_identifier = "invalid_table" ,
229+ cloudformation_primary_identifier = "invalid_table" ,
221230 request_specific_attributes = {
222231 SpanAttributes .AWS_DYNAMODB_TABLE_NAMES : ["invalid_table" ],
223232 },
@@ -235,6 +244,7 @@ def test_dynamodb_fault(self):
235244 remote_operation = "PutItem" ,
236245 remote_resource_type = "AWS::DynamoDB::Table" ,
237246 remote_resource_identifier = "invalid_table" ,
247+ cloudformation_primary_identifier = "invalid_table" ,
238248 request_specific_attributes = {
239249 SpanAttributes .AWS_DYNAMODB_TABLE_NAMES : ["invalid_table" ],
240250 },
@@ -407,6 +417,7 @@ def test_bedrock_get_guardrail(self):
407417 remote_operation = "GetGuardrail" ,
408418 remote_resource_type = "AWS::Bedrock::Guardrail" ,
409419 remote_resource_identifier = "bt4o77i015cu" ,
420+ cloudformation_primary_identifier = "arn:aws:bedrock:us-east-1:000000000000:guardrail/bt4o77i015cu" ,
410421 request_specific_attributes = {
411422 _AWS_BEDROCK_GUARDRAIL_ID : "bt4o77i015cu" ,
412423 },
@@ -519,6 +530,7 @@ def _assert_aws_span_attributes(self, resource_scope_spans: List[ResourceScopeSp
519530 "LOCAL_ROOT" ,
520531 kwargs .get ("remote_resource_type" , "None" ),
521532 kwargs .get ("remote_resource_identifier" , "None" ),
533+ kwargs .get ("cloudformation_primary_identifier" , "None" ),
522534 )
523535
524536 def _assert_aws_attributes (
@@ -529,6 +541,7 @@ def _assert_aws_attributes(
529541 span_kind : str ,
530542 remote_resource_type : str ,
531543 remote_resource_identifier : str ,
544+ cloudformation_primary_identifier : str ,
532545 ) -> None :
533546 attributes_dict : Dict [str , AnyValue ] = self ._get_attributes_dict (attributes_list )
534547 self ._assert_str_attribute (attributes_dict , AWS_LOCAL_SERVICE , self .get_application_otel_service_name ())
@@ -541,6 +554,8 @@ def _assert_aws_attributes(
541554 self ._assert_str_attribute (attributes_dict , AWS_REMOTE_RESOURCE_TYPE , remote_resource_type )
542555 if remote_resource_identifier != "None" :
543556 self ._assert_str_attribute (attributes_dict , AWS_REMOTE_RESOURCE_IDENTIFIER , remote_resource_identifier )
557+ if cloudformation_primary_identifier != "None" :
558+ self ._assert_str_attribute (attributes_dict , AWS_CLOUDFORMATION_PRIMARY_IDENTIFIER , cloudformation_primary_identifier )
544559 # See comment above AWS_LOCAL_OPERATION
545560 self ._assert_str_attribute (attributes_dict , AWS_SPAN_KIND , span_kind )
546561
0 commit comments