Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log the attribute's key when encoding an attribute fails #3838

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

danielhochman
Copy link

Description

Include the attribute key that failed to encode. Very hard to track down otherwise.

Before

Invalid type <class 'NoneType'> of value None

After

Failed to encode key namespace: Invalid type <class 'NoneType'> of value None

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Unit tests

Does This PR Require a Contrib Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@danielhochman danielhochman requested a review from a team as a code owner April 5, 2024 18:12
Copy link

CLA Not Signed

@xrmx
Copy link
Contributor

xrmx commented Apr 8, 2024

@danielhochman you have to sign the CLA for contributing to OpenTelemetry

)
def test_encode_attributes_error_logs_key(self, mock_logger_exception):
result = _encode_attributes({"a": 1, "bad_key": None, "b": 2})
mock_logger_exception.assert_called_once()
Copy link
Contributor

@emdneto emdneto Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's no need to mock. What do you think about use assertLogs instead of this? and also assert the len of the log records?

self.assertEqual(
mock_logger_exception.call_args_list[0].args[1], "bad_key"
)
self.assertTrue(
Copy link
Contributor

@emdneto emdneto Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of assertIsInstance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants