Skip to content

Commit eb3b7f6

Browse files
committed
feat: update contract tests for cfn primary id
1 parent 75af98a commit eb3b7f6

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

contract-tests/images/applications/botocore/botocore_server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def _handle_bedrock_request(self) -> None:
246246
set_main_status(200)
247247
bedrock_client.meta.events.register(
248248
"before-call.bedrock.GetGuardrail",
249-
lambda **kwargs: inject_200_success(guardrailId="bt4o77i015cu", **kwargs),
249+
lambda **kwargs: inject_200_success(guardrailId="bt4o77i015cu", guardrailArn="arn:aws:bedrock:us-east-1:000000000000:guardrail/bt4o77i015cu", **kwargs),
250250
)
251251
bedrock_client.get_guardrail(
252252
guardrailIdentifier="arn:aws:bedrock:us-east-1:000000000000:guardrail/bt4o77i015cu"
@@ -363,6 +363,9 @@ def inject_200_success(**kwargs):
363363
guardrail_id = kwargs.get("guardrailId")
364364
if guardrail_id is not None:
365365
response_body["guardrailId"] = guardrail_id
366+
guardrail_arn = kwargs.get("guardrailArn")
367+
if guardrail_arn is not None:
368+
response_body["guardrailArn"] = guardrail_arn
366369

367370
HTTPResponse = namedtuple("HTTPResponse", ["status_code", "headers", "body"])
368371
headers = kwargs.get("headers", {})

contract-tests/tests/test/amazon/botocore/botocore_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from amazon.base.contract_test_base import NETWORK_NAME, ContractTestBase
1212
from 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

contract-tests/tests/test/amazon/utils/application_signals_constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
FAULT_METRIC: str = "fault"
1111

1212
# Attribute names
13+
AWS_CLOUDFORMATION_PRIMARY_IDENTIFIER: str = "aws.remote.resource.cfn.primary.identifier"
1314
AWS_LOCAL_SERVICE: str = "aws.local.service"
1415
AWS_LOCAL_OPERATION: str = "aws.local.operation"
1516
AWS_REMOTE_DB_USER: str = "aws.remote.db.user"

0 commit comments

Comments
 (0)