Skip to content

Conversation

jourdanrodrigues
Copy link

Description

Faced random logs at work that had LogRecord.exc_info set to a string. Couldn't track down where it came from so I monkey-patched it in my project.

Decided to propose here in case this is of interest to include in the lib.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • New tests added at opentelemetry-sdk/tests/logs/test_handler.py

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

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

@jourdanrodrigues jourdanrodrigues requested a review from a team as a code owner July 25, 2025 16:31
@@ -568,6 +569,9 @@ def _get_attributes(record: logging.LogRecord) -> _ExtendedAttributes:
attributes[code_attributes.CODE_FUNCTION_NAME] = record.funcName
attributes[code_attributes.CODE_LINE_NUMBER] = record.lineno

if isinstance(record.exc_info, str):
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a comment here to explain the motivation?

Copy link
Author

@jourdanrodrigues jourdanrodrigues Jul 28, 2025

Choose a reason for hiding this comment

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

I wasn't able to track down why nor how this happens (I tried as hard as I could), like if this was some misconfiguration in my work's project or some lib doing this, and I left such comment in the test that preserves this behavior.

Unfortunately, the only thing I know is that it can be a string and this fixed it in my case.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps a line explaining the motivation would help readers? Doesn't have to be specific, just that the check and overwrite are defensive, preventing errors in some implementations.

Copy link
Member

Choose a reason for hiding this comment

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

@jourdanrodrigues are you setting any kind of logging.Filter in the LoggingHandler?

@xrmx xrmx moved this to Reviewed PR that needs fixing in @xrmx's Python PR digest Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Reviewed PR that needs fixing
Development

Successfully merging this pull request may close these issues.

4 participants