Skip to content

feat: log captured exceptions#215

Merged
daibhin merged 4 commits intomasterfrom
err-dn/log-captured-exceptions
Apr 10, 2025
Merged

feat: log captured exceptions#215
daibhin merged 4 commits intomasterfrom
err-dn/log-captured-exceptions

Conversation

@daibhin
Copy link
Contributor

@daibhin daibhin commented Apr 10, 2025

Adds a log_captured_exceptions config option so that all $exception events can also be logged

This is useful internally to capture exceptions if our own product is unavailable.

We have a version of this already in https://github.com/PostHog/posthog/blob/c2c65827b31b13c8e2e84d4ddc33df34b5924487/posthog/exceptions.py#L58-L66 but that only applies to DFR views.

By doing this at the SDK level we can log any exception that is being captured. One difference is that the logger in the SDK is not structured but I think that's ok

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR adds a new configuration option log_captured_exceptions to the PostHog Python SDK, allowing exceptions captured via capture_exception to be logged locally in addition to being sent to PostHog.

  • Added log_captured_exceptions boolean parameter to Client class constructor with default value of False
  • Implemented logging logic in capture_exception method to log exceptions with additional context when enabled
  • Added **kwargs parameter to module-level capture_exception function to pass through additional context
  • Added test case test_capture_exception_logs_when_enabled to verify logging behavior
  • Updated version from 3.23.0 to 3.24.0 in version.py and documented the feature in CHANGELOG.md

5 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@daibhin
Copy link
Contributor Author

daibhin commented Apr 10, 2025

Currently blocked by failing tests. Fix in #216

@daibhin daibhin requested review from a team, hpouillot, oliverb123 and timgl April 10, 2025 10:53
@daibhin daibhin merged commit 51380ac into master Apr 10, 2025
6 checks passed
@daibhin daibhin deleted the err-dn/log-captured-exceptions branch April 10, 2025 11:14
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.

2 participants

Comments