Enhanced PostHog Error Tracking with Detailed Messages #6176
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Noticed we weren't sending the error context and also covered some more key places we were missing.
Overview
This PR improves PostHog error telemetry by including detailed, sanitized error messages alongside error types. Previously, only categorical error types (e.g., "auth", "rate_limit") were sent, making it difficult to diagnose issues. Now, the actual error content is included for better observability.
Changes
Backend (Rust)
crates/goose/src/posthog.rsErrorContextstruct with newerror_messagefieldemit_error()signature to accepterror_typeanderror_messagecrates/goose/src/agents/agent.rsemit_errorcalls for:tool_execution_failed- includes tool name and errorcontext_lengthand otherProviderErrorvariantscompaction_failed- new tracking for compaction failurescrates/goose/src/agents/retry.rsretry_max_exceedederror tracking when max retry attempts are reachedcrates/goose/src/scheduler.rsscheduler_job_failederror tracking for scheduled job failurescrates/goose-server/src/routes/agent.rsrecipe_deeplink_decode_failedsession_create_failedsession_resume_failedextension_load_failed(during session resume)extension_add_failed(via API)crates/goose-server/src/routes/session.rssession_copy_failedsession_truncate_failedcrates/goose-server/src/routes/recipe.rsrecipe_create_failedrecipe_encode_failedrecipe_decode_failedrecipe_schedule_failedFrontend (TypeScript)
ui/desktop/src/App.tsxtrackErrorWithContextfor:create_sessioninPairRouteWrapper- catches session creation failures from recipesopen_shared_sessioninAppInner- catches shared session deeplink failuresError Types Added
tool_execution_failedcompaction_failedretry_max_exceededscheduler_job_failedrecipe_deeplink_decode_failedsession_create_failedsession_resume_failedextension_load_failedextension_add_failedsession_copy_failedsession_truncate_failedrecipe_create_failedrecipe_encode_failedrecipe_decode_failedrecipe_schedule_failedPrivacy
All error messages are sanitized using the existing
sanitize_string()function before being sent to PostHog, which redacts API keys, tokens, and PII patterns.