diff --git a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_metric_attribute_generator.py b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_metric_attribute_generator.py index f945254fb..060d902a0 100644 --- a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_metric_attribute_generator.py +++ b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_metric_attribute_generator.py @@ -453,10 +453,12 @@ def _escape_delimiters(input_str: str) -> Optional[str]: return None return input_str.replace("^", "^^").replace("|", "^|") + def _set_remote_db_user(span: ReadableSpan, attributes: BoundedAttributes) -> None: if is_db_span(span) and is_key_present(span, _DB_USER): attributes[AWS_REMOTE_DB_USER] = span.attributes.get(_DB_USER) + def _set_span_kind_for_dependency(span: ReadableSpan, attributes: BoundedAttributes) -> None: span_kind: str = span.kind.name attributes[AWS_SPAN_KIND] = span_kind diff --git a/aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_metric_attribute_generator.py b/aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_metric_attribute_generator.py index d15f6f34d..11845522f 100644 --- a/aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_metric_attribute_generator.py +++ b/aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_metric_attribute_generator.py @@ -13,13 +13,13 @@ AWS_LOCAL_SERVICE, AWS_QUEUE_NAME, AWS_QUEUE_URL, + AWS_REMOTE_DB_USER, AWS_REMOTE_OPERATION, AWS_REMOTE_RESOURCE_IDENTIFIER, AWS_REMOTE_RESOURCE_TYPE, AWS_REMOTE_SERVICE, AWS_SPAN_KIND, AWS_STREAM_NAME, - AWS_REMOTE_DB_USER, ) from amazon.opentelemetry.distro._aws_metric_attribute_generator import _AwsMetricAttributeGenerator from amazon.opentelemetry.distro.metric_attribute_generator import DEPENDENCY_METRIC, SERVICE_METRIC @@ -788,7 +788,7 @@ def test_db_user_attribute_absent(self): self._mock_attribute(SpanAttributes.DB_USER, None) self.span_mock.kind = SpanKind.CLIENT - actual_attributes = _GENERATOR.generate_metric_attributes_dict_from_span( + actual_attributes: Attributes = _GENERATOR.generate_metric_attributes_dict_from_span( self.span_mock, self.resource ).get(DEPENDENCY_METRIC) self.assertIsNone(actual_attributes.get(AWS_REMOTE_DB_USER)) @@ -798,7 +798,7 @@ def test_db_user_attribute_not_present_in_service_metric_for_server_span(self): self._mock_attribute([SpanAttributes.DB_USER], [db_user]) self.span_mock.kind = SpanKind.SERVER - actual_attributes = _GENERATOR.generate_metric_attributes_dict_from_span( + actual_attributes: Attributes = _GENERATOR.generate_metric_attributes_dict_from_span( self.span_mock, self.resource ).get(SERVICE_METRIC) self.assertIsNone(actual_attributes.get(AWS_REMOTE_DB_USER)) @@ -808,7 +808,7 @@ def test_db_user_attribute_with_different_values(self): self._mock_attribute([SpanAttributes.DB_USER], [db_user]) self.span_mock.kind = SpanKind.CLIENT - actual_attributes = _GENERATOR.generate_metric_attributes_dict_from_span( + actual_attributes: Attributes = _GENERATOR.generate_metric_attributes_dict_from_span( self.span_mock, self.resource ).get(DEPENDENCY_METRIC) self.assertEqual(actual_attributes.get(AWS_REMOTE_DB_USER), db_user) diff --git a/contract-tests/tests/test/amazon/base/database_contract_test_base.py b/contract-tests/tests/test/amazon/base/database_contract_test_base.py index f5380622f..0a4c44580 100644 --- a/contract-tests/tests/test/amazon/base/database_contract_test_base.py +++ b/contract-tests/tests/test/amazon/base/database_contract_test_base.py @@ -27,6 +27,7 @@ DATABASE_NAME: str = "testdb" DB_USER: str = "db.user" + class DatabaseContractTestBase(ContractTestBase): @staticmethod def get_remote_service() -> str: