Skip to content

fix: Preserve exception stack frame paths#215

Closed
marandaneto wants to merge 2 commits into
mainfrom
fix/relative-exception-filenames
Closed

fix: Preserve exception stack frame paths#215
marandaneto wants to merge 2 commits into
mainfrom
fix/relative-exception-filenames

Conversation

@marandaneto

@marandaneto marandaneto commented Jul 3, 2026

Copy link
Copy Markdown
Member

💡 Motivation and Context

Fixes #212.

Captured exception stack frames currently set filename to File.basename(abs_path), which drops project-relative directories such as app/services/foo/bar.rb. PostHog Error Tracking renders filename, so frames with the same basename become hard to distinguish.

This change preserves useful relative paths for stack frame filenames while keeping abs_path unchanged. The changeset covers both posthog-ruby and posthog-rails because Rails users are affected by the captured exception payload.

💚 How did you test it?

  • bundle exec rspec spec/posthog/exception_capture_spec.rb
  • bundle exec rspec
  • bundle exec rubocop

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Pi coding agent implemented this change in a dedicated git worktree. The implementation follows the issue recommendation by computing stack frame filenames from known roots: Rails.root or the current working directory for in-app frames, and the longest matching $LOAD_PATH entry for gem frames. The fallback keeps the original path rather than collapsing to a basename, so directory context is preserved.

Follow-up review feedback replaced the trailing slash regex with a linear implementation, evaluated Rails.root only once, and added the Rails changeset entry.

@marandaneto marandaneto self-assigned this Jul 3, 2026
Comment thread lib/posthog/exception_capture.rb Fixed
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

posthog-ruby Compliance Report

Date: 2026-07-03 09:39:13 UTC
Duration: 98227ms

✅ All Tests Passed!

46/46 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 108ms
Format Validation.Event Has Uuid 107ms
Format Validation.Event Has Lib Properties 109ms
Format Validation.Distinct Id Is String 107ms
Format Validation.Token Is Present 107ms
Format Validation.Custom Properties Preserved 106ms
Format Validation.Event Has Timestamp 107ms
Retry Behavior.Retries On 503 5312ms
Retry Behavior.Does Not Retry On 400 2111ms
Retry Behavior.Does Not Retry On 401 2109ms
Retry Behavior.Respects Retry After Header 8118ms
Retry Behavior.Implements Backoff 15623ms
Retry Behavior.Retries On 500 5212ms
Retry Behavior.Retries On 502 5212ms
Retry Behavior.Retries On 504 5212ms
Retry Behavior.Max Retries Respected 15514ms
Deduplication.Generates Unique Uuids 113ms
Deduplication.Preserves Uuid On Retry 5212ms
Deduplication.Preserves Uuid And Timestamp On Retry 10310ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5215ms
Deduplication.No Duplicate Events In Batch 112ms
Deduplication.Different Events Have Different Uuids 109ms
Compression.Sends Gzip When Enabled 107ms
Batch Format.Uses Proper Batch Structure 108ms
Batch Format.Flush With No Events Sends Nothing 5ms
Batch Format.Multiple Events Batched Together 109ms
Error Handling.Does Not Retry On 403 2109ms
Error Handling.Does Not Retry On 413 2109ms
Error Handling.Retries On 408 5212ms

Feature_Flags Tests

17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 109ms
Request Payload.Flags Request Uses V2 Query Param 107ms
Request Payload.Flags Request Hits Flags Path Not Decide 108ms
Request Payload.Flags Request Omits Authorization Header 108ms
Request Payload.Token In Flags Body Matches Init 108ms
Request Payload.Groups Round Trip 109ms
Request Payload.Groups Default To Empty Object 108ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 108ms
Request Payload.Disable Geoip Omitted Defaults To False 108ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 107ms
Request Lifecycle.No Flags Request On Init Alone 3ms
Request Lifecycle.No Flags Request On Normal Capture 106ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 112ms
Request Lifecycle.Mock Response Value Is Returned To Caller 106ms
Retry Behavior.Retries Flags On 502 239ms
Retry Behavior.Retries Flags On 504 211ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 109ms

@greptile-apps

greptile-apps Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix: Preserve relative exception filenam..." | Re-trigger Greptile

Comment thread lib/posthog/exception_capture.rb Outdated
@marandaneto marandaneto requested review from a team, ablaszkiewicz, cat-ph and hpouillot July 3, 2026 09:42
@marandaneto

Copy link
Copy Markdown
Member Author

@PostHog/team-error-tracking not sure if thats what we want, but opened a pr with a possible fix, lemme know

@hpouillot

Copy link
Copy Markdown
Contributor

Yes, it should be fixed with this PR: #214

@marandaneto

Copy link
Copy Markdown
Member Author

closing in favor of #214

@marandaneto marandaneto closed this Jul 3, 2026
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.

Error tracking: stack trace filename is reduced to File.basename, dropping the project-relative path

3 participants