Skip to content

Commit

Permalink
Add support for remote resource in psycopg2 contract tests. (#187)
Browse files Browse the repository at this point in the history
Add support for `AWS_REMOTE_RESOURCE_TYPE` and
`AWS_REMOTE_RESOURCE_IDENTIFIER` for psycopg2 contract tests.

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
  • Loading branch information
zzhlogin authored May 17, 2024
1 parent 0ea3ebd commit 9041a31
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions contract-tests/tests/test/amazon/psycopg2/psycopg2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
AWS_LOCAL_OPERATION,
AWS_LOCAL_SERVICE,
AWS_REMOTE_OPERATION,
AWS_REMOTE_RESOURCE_IDENTIFIER,
AWS_REMOTE_RESOURCE_TYPE,
AWS_REMOTE_SERVICE,
AWS_SPAN_KIND,
)
Expand Down Expand Up @@ -78,6 +80,8 @@ def _assert_aws_attributes(self, attributes_list: List[KeyValue], **kwargs) -> N
self._assert_str_attribute(attributes_dict, AWS_REMOTE_SERVICE, "postgresql")
command: str = kwargs.get("sql_command")
self._assert_str_attribute(attributes_dict, AWS_REMOTE_OPERATION, f"{command}")
self._assert_str_attribute(attributes_dict, AWS_REMOTE_RESOURCE_TYPE, "DB::Connection")
self._assert_str_attribute(attributes_dict, AWS_REMOTE_RESOURCE_IDENTIFIER, "postgres|mydb|5432")
# See comment above AWS_LOCAL_OPERATION
self._assert_str_attribute(attributes_dict, AWS_SPAN_KIND, "LOCAL_ROOT")

Expand All @@ -104,6 +108,10 @@ def _assert_semantic_conventions_attributes(self, attributes_list: List[KeyValue
self.assertTrue(attributes_dict.get("db.statement").string_value.startswith(command))
self._assert_str_attribute(attributes_dict, "db.system", "postgresql")
self._assert_str_attribute(attributes_dict, "db.name", "postgres")
self._assert_str_attribute(attributes_dict, "net.peer.name", "mydb")
self._assert_int_attribute(attributes_dict, "net.peer.port", 5432)
self.assertTrue("server.address" not in attributes_dict)
self.assertTrue("server.port" not in attributes_dict)
self.assertTrue("db.operation" not in attributes_dict)

@override
Expand Down Expand Up @@ -131,6 +139,8 @@ def _assert_metric_attributes(
self._assert_str_attribute(attribute_dict, AWS_LOCAL_OPERATION, "InternalOperation")
self._assert_str_attribute(attribute_dict, AWS_REMOTE_SERVICE, "postgresql")
self._assert_str_attribute(attribute_dict, AWS_REMOTE_OPERATION, kwargs.get("sql_command"))
self._assert_str_attribute(attribute_dict, AWS_REMOTE_RESOURCE_TYPE, "DB::Connection")
self._assert_str_attribute(attribute_dict, AWS_REMOTE_RESOURCE_IDENTIFIER, "postgres|mydb|5432")
self._assert_str_attribute(attribute_dict, AWS_SPAN_KIND, "CLIENT")
self.check_sum(metric_name, dependency_dp.sum, expected_sum)

Expand Down

0 comments on commit 9041a31

Please sign in to comment.