Skip to content

Commit

Permalink
Adding data base user attribute in Python EMF logs
Browse files Browse the repository at this point in the history
  • Loading branch information
ektabj committed Jul 1, 2024
1 parent edbe524 commit 462edb6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
DATABASE_NAME: str = "testdb"
DB_USER: str = "db.user"


class DatabaseContractTestBase(ContractTestBase):
@staticmethod
def get_remote_service() -> str:
Expand Down

0 comments on commit 462edb6

Please sign in to comment.