Skip to content

fix(logging): Send structlog exceptions to Sentry as exception events - #301

Merged
khvn26 merged 6 commits into
mainfrom
fix/structlog-sentry-exceptions
Nov 25, 2026
Merged

khvn26 merged 6 commits into
mainfrom
fix/structlog-sentry-exceptions

Conversation

@khvn26

@khvn26 khvn26 commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

In this PR, we make sure the structured error logs reach Sentry with original exception tracebacks, and Sentry uses log event name to display as log message rather than the entire log dictionary.

format_exc_info consumed exc_info before the record reached stdlib, so
Sentry's LoggingIntegration saw no exception for `.error(..., exc_info=...)`
and captured a plain message. Sentry also stringified the whole event dict
as the message, which made titles unreadable and broke grouping.

Keep the exception tuple through the processor chain and pass it to
stdlib as `exc_info`, and make the event dict stringify as the event name.
@codecov-commenter

codecov-commenter commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.75%. Comparing base (e441e38) to head (cfeaab3).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #301      +/-   ##
==========================================
+ Coverage   97.73%   97.75%   +0.02%     
==========================================
  Files         114      114              
  Lines        5112     5176      +64     
==========================================
+ Hits         4996     5060      +64     
  Misses        116      116              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Logger._log already turns exception instances and `True` into an exc_info
tuple, so pass the original value through instead of reimplementing that.
@khvn26
khvn26 marked this pull request as ready for review November 24, 2026 19:39
@khvn26
khvn26 requested a review from a team as a code owner November 24, 2026 19:39
@khvn26
khvn26 requested review from emyller and removed request for a team November 24, 2026 19:39
cubic-dev-ai[bot]
cubic-dev-ai Bot previously approved these changes Nov 24, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: Focused logging fix: structlog exceptions now reach Sentry as true exception events titled by event name, while OTel still receives the rendered exception; covered by new unit tests.

Turn on auto-fix | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: Focused logging fix: structlog exceptions reach Sentry as true exception events titled by the event name, while OTel still receives the rendered exception; covered by new unit tests.

Turn on auto-fix | Re-trigger cubic

@emyller emyller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One non-blocking design question.

Comment thread src/common/core/logging.py Resolved
@khvn26
khvn26 merged commit 02151ac into main Nov 25, 2026
4 checks passed
@khvn26
khvn26 deleted the fix/structlog-sentry-exceptions branch November 25, 2026 10:29
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.

3 participants