Skip to content

Handle "LogRecord.exc_info" being a string#4699

Closed
jourdanrodrigues wants to merge 6 commits intoopen-telemetry:mainfrom
jourdanrodrigues:logging-handler-exc-info-str
Closed

Handle "LogRecord.exc_info" being a string#4699
jourdanrodrigues wants to merge 6 commits intoopen-telemetry:mainfrom
jourdanrodrigues:logging-handler-exc-info-str

Conversation

@jourdanrodrigues
Copy link
Copy Markdown

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
Comment thread opentelemetry-sdk/tests/logs/test_handler.py
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py Outdated
attributes[code_attributes.CODE_FUNCTION_NAME] = record.funcName
attributes[code_attributes.CODE_LINE_NUMBER] = record.lineno

if isinstance(record.exc_info, str):
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 Python PR digest Aug 18, 2025
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 5, 2026

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions Bot added the Stale label Mar 5, 2026
@github-actions
Copy link
Copy Markdown

This PR has been closed due to inactivity. Please reopen if you would like to continue working on it.

@github-actions github-actions Bot closed this Mar 19, 2026
@github-project-automation github-project-automation Bot moved this from Reviewed PRs that need fixes to Done in Python PR digest Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants