Skip to content

Commit e3892f7

Browse files
authored
Merge branch 'main' into update-dockerfile-with-scratch
2 parents 978f0b4 + 7a90ee5 commit e3892f7

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
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
@@ -4,6 +4,7 @@
44
AWS_SPAN_KIND: str = "aws.span.kind"
55
AWS_LOCAL_SERVICE: str = "aws.local.service"
66
AWS_LOCAL_OPERATION: str = "aws.local.operation"
7+
AWS_REMOTE_DB_USER: str = "aws.remote.db.user"
78
AWS_REMOTE_SERVICE: str = "aws.remote.service"
89
AWS_REMOTE_OPERATION: str = "aws.remote.operation"
910
AWS_REMOTE_RESOURCE_TYPE: str = "aws.remote.resource.type"

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
AWS_LOCAL_SERVICE,
1111
AWS_QUEUE_NAME,
1212
AWS_QUEUE_URL,
13+
AWS_REMOTE_DB_USER,
1314
AWS_REMOTE_OPERATION,
1415
AWS_REMOTE_RESOURCE_IDENTIFIER,
1516
AWS_REMOTE_RESOURCE_TYPE,
@@ -52,6 +53,7 @@
5253
_DB_OPERATION: str = SpanAttributes.DB_OPERATION
5354
_DB_STATEMENT: str = SpanAttributes.DB_STATEMENT
5455
_DB_SYSTEM: str = SpanAttributes.DB_SYSTEM
56+
_DB_USER: str = SpanAttributes.DB_USER
5557
_FAAS_INVOKED_NAME: str = SpanAttributes.FAAS_INVOKED_NAME
5658
_FAAS_TRIGGER: str = SpanAttributes.FAAS_TRIGGER
5759
_GRAPHQL_OPERATION_TYPE: str = SpanAttributes.GRAPHQL_OPERATION_TYPE
@@ -126,6 +128,7 @@ def _generate_dependency_metric_attributes(span: ReadableSpan, resource: Resourc
126128
_set_egress_operation(span, attributes)
127129
_set_remote_service_and_operation(span, attributes)
128130
_set_remote_type_and_identifier(span, attributes)
131+
_set_remote_db_user(span, attributes)
129132
_set_span_kind_for_dependency(span, attributes)
130133
return attributes
131134

@@ -451,6 +454,11 @@ def _escape_delimiters(input_str: str) -> Optional[str]:
451454
return input_str.replace("^", "^^").replace("|", "^|")
452455

453456

457+
def _set_remote_db_user(span: ReadableSpan, attributes: BoundedAttributes) -> None:
458+
if is_db_span(span) and is_key_present(span, _DB_USER):
459+
attributes[AWS_REMOTE_DB_USER] = span.attributes.get(_DB_USER)
460+
461+
454462
def _set_span_kind_for_dependency(span: ReadableSpan, attributes: BoundedAttributes) -> None:
455463
span_kind: str = span.kind.name
456464
attributes[AWS_SPAN_KIND] = span_kind

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_metric_attribute_generator.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
AWS_LOCAL_SERVICE,
1414
AWS_QUEUE_NAME,
1515
AWS_QUEUE_URL,
16+
AWS_REMOTE_DB_USER,
1617
AWS_REMOTE_OPERATION,
1718
AWS_REMOTE_RESOURCE_IDENTIFIER,
1819
AWS_REMOTE_RESOURCE_TYPE,
@@ -773,6 +774,52 @@ def test_both_metric_when_local_root_consumer_process(self):
773774
self.assertIsNotNone(service_attributes)
774775
self.assertIsNotNone(dependency_attributes)
775776

777+
def test_db_user_attribute(self):
778+
self._mock_attribute([SpanAttributes.DB_OPERATION, SpanAttributes.DB_USER], ["db_operation", "db_user"])
779+
self.span_mock.kind = SpanKind.CLIENT
780+
781+
actual_attributes: Attributes = _GENERATOR.generate_metric_attributes_dict_from_span(
782+
self.span_mock, self.resource
783+
).get(DEPENDENCY_METRIC)
784+
self.assertEqual(actual_attributes.get(AWS_REMOTE_OPERATION), "db_operation")
785+
self.assertEqual(actual_attributes.get(AWS_REMOTE_DB_USER), "db_user")
786+
787+
def test_db_user_attribute_absent(self):
788+
self._mock_attribute([SpanAttributes.DB_SYSTEM], ["db_system"])
789+
self.span_mock.kind = SpanKind.CLIENT
790+
791+
actual_attributes: Attributes = _GENERATOR.generate_metric_attributes_dict_from_span(
792+
self.span_mock, self.resource
793+
).get(DEPENDENCY_METRIC)
794+
self.assertIsNone(actual_attributes.get(AWS_REMOTE_DB_USER))
795+
796+
def test_db_user_attribute_not_present_in_service_metric_for_server_span(self):
797+
self._mock_attribute([SpanAttributes.DB_USER, SpanAttributes.DB_SYSTEM], ["db_user", "db_system"])
798+
self.span_mock.kind = SpanKind.SERVER
799+
800+
actual_attributes: Attributes = _GENERATOR.generate_metric_attributes_dict_from_span(
801+
self.span_mock, self.resource
802+
).get(SERVICE_METRIC)
803+
self.assertIsNone(actual_attributes.get(AWS_REMOTE_DB_USER))
804+
805+
def test_db_user_attribute_with_different_values(self):
806+
self._mock_attribute([SpanAttributes.DB_OPERATION, SpanAttributes.DB_USER], ["db_operation", "non_db_user"])
807+
self.span_mock.kind = SpanKind.CLIENT
808+
809+
actual_attributes: Attributes = _GENERATOR.generate_metric_attributes_dict_from_span(
810+
self.span_mock, self.resource
811+
).get(DEPENDENCY_METRIC)
812+
self.assertEqual(actual_attributes.get(AWS_REMOTE_DB_USER), "non_db_user")
813+
814+
def test_db_user_present_and_is_db_span_false(self):
815+
self._mock_attribute([SpanAttributes.DB_USER], ["db_user"])
816+
self.span_mock.kind = SpanKind.CLIENT
817+
818+
actual_attributes: Attributes = _GENERATOR.generate_metric_attributes_dict_from_span(
819+
self.span_mock, self.resource
820+
).get(DEPENDENCY_METRIC)
821+
self.assertIsNone(actual_attributes.get(AWS_REMOTE_DB_USER))
822+
776823
def test_local_root_boto3_span(self):
777824
self._update_resource_with_service_name()
778825
self.parent_span_context.is_valid = False

contract-tests/tests/test/amazon/base/database_contract_test_base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from amazon.utils.application_signals_constants import (
1010
AWS_LOCAL_OPERATION,
1111
AWS_LOCAL_SERVICE,
12+
AWS_REMOTE_DB_USER,
1213
AWS_REMOTE_OPERATION,
1314
AWS_REMOTE_RESOURCE_IDENTIFIER,
1415
AWS_REMOTE_RESOURCE_TYPE,
@@ -109,6 +110,7 @@ def _assert_aws_attributes(self, attributes_list: List[KeyValue], **kwargs) -> N
109110
self._assert_str_attribute(attributes_dict, AWS_REMOTE_SERVICE, self.get_remote_service())
110111
self._assert_str_attribute(attributes_dict, AWS_REMOTE_OPERATION, kwargs.get("sql_command"))
111112
self._assert_str_attribute(attributes_dict, AWS_REMOTE_RESOURCE_TYPE, "DB::Connection")
113+
self._assert_str_attribute(attributes_dict, AWS_REMOTE_DB_USER, DATABASE_USER)
112114
self._assert_str_attribute(
113115
attributes_dict, AWS_REMOTE_RESOURCE_IDENTIFIER, self.get_remote_resource_identifier()
114116
)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# Attribute names
1313
AWS_LOCAL_SERVICE: str = "aws.local.service"
1414
AWS_LOCAL_OPERATION: str = "aws.local.operation"
15+
AWS_REMOTE_DB_USER: str = "aws.remote.db.user"
1516
AWS_REMOTE_SERVICE: str = "aws.remote.service"
1617
AWS_REMOTE_OPERATION: str = "aws.remote.operation"
1718
AWS_REMOTE_RESOURCE_TYPE: str = "aws.remote.resource.type"

0 commit comments

Comments
 (0)