Skip to content

feat(error-tracking): add opt-in .NET unhandled exception capture - #356

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog/opt-in-unhandled-exception-capture
Draft

posthog[bot] wants to merge 1 commit into
mainfrom
posthog/opt-in-unhandled-exception-capture

Conversation

@posthog

@posthog posthog Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Why: .NET applications currently miss unhandled process and background task failures unless callers report each exception manually. This adds opt-in runtime capture while preserving the existing default behavior. Closes #205.

Public API: Adds PostHogOptions.CaptureUnhandledExceptions (default false). Enabled clients subscribe to runtime exception events, deduplicate the same exception across request and runtime hooks, and attempt a bounded flush for terminating failures. Escaping ASP.NET Core request exceptions now carry unhandled middleware metadata.

The exception event metadata spec defines the new boundary values used here. The existing exception builder still emits legacy empty mechanism.source values and omits exception tree IDs; that structure is unchanged by this PR.

💚 How did you test it?

Added focused tests for both runtime handlers, default-off behavior, middleware metadata, and duplicate suppression. git diff --check passed. The local environment has no dotnet executable, so build and test execution await CI.

📝 Checklist

  • All commits are signed (see Commit signing)
  • 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 (changeset added directly)

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Codex used PostHog MCP to review the Inbox report, the published SDK metadata spec, and repository code. The core option is opt-in to avoid changing existing capture behavior. The PR is awaiting human review.


Created with PostHog Desktop from an inbox report

Origin

  • Issues: #205
  • First signal: 2026-10-23
  • Inbox report: open
  • Likely cause: 479f5ca
  • Task started by: a person, from the inbox

Generated-By: PostHog Desktop
Task-Id: f32040d6-a160-4f5f-96d9-59daaf4a7ee8
@posthog posthog Bot added the self-driving label Oct 25, 2026
@posthog
posthog Bot requested a review from dustinbyrne October 25, 2026 13:14
@posthog posthog Bot changed the title Add opt-in .NET unhandled exception capture feat(error-tracking): add opt-in .NET unhandled exception capture Oct 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

posthog-dotnet Compliance Report

Date: 2026-10-25T13:18:02.452922+00:00
Duration: 124744ms

✅ All Tests Passed!

47/47 tests passed


Capture Tests

✅ 30/30 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 226ms
Format Validation.Event Has Uuid ✅ 122ms
Format Validation.Event Has Lib Properties ✅ 108ms
Format Validation.Distinct Id Is String ✅ 113ms
Format Validation.Token Is Present ✅ 109ms
Format Validation.Custom Properties Preserved ✅ 114ms
Format Validation.Event Has Timestamp ✅ 109ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ✅ 118ms
Retry Behavior.Retries On 503 ✅ 8120ms
Retry Behavior.Does Not Retry On 400 ✅ 2115ms
Retry Behavior.Does Not Retry On 401 ✅ 2112ms
Retry Behavior.Respects Retry After Header ✅ 8117ms
Retry Behavior.Implements Backoff ✅ 22128ms
Retry Behavior.Retries On 500 ✅ 6116ms
Retry Behavior.Retries On 502 ✅ 6117ms
Retry Behavior.Retries On 504 ✅ 6116ms
Retry Behavior.Max Retries Respected ✅ 22132ms
Deduplication.Generates Unique Uuids ✅ 113ms
Deduplication.Preserves Uuid On Retry ✅ 6110ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 13125ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 6118ms
Deduplication.No Duplicate Events In Batch ✅ 114ms
Deduplication.Different Events Have Different Uuids ✅ 109ms
Compression.Sends Gzip When Enabled ✅ 107ms
Batch Format.Uses Proper Batch Structure ✅ 107ms
Batch Format.Flush With No Events Sends Nothing ✅ 105ms
Batch Format.Multiple Events Batched Together ✅ 112ms
Error Handling.Does Not Retry On 403 ✅ 2110ms
Error Handling.Does Not Retry On 413 ✅ 2111ms
Error Handling.Retries On 408 ✅ 6115ms

Feature_Flags Tests

✅ 17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 137ms
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 ✅ 111ms
Request Payload.Groups Default To Empty Object ✅ 107ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 107ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 107ms
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 ✅ 107ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 210ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 110ms
Retry Behavior.Retries Flags On 502 ✅ 1111ms
Retry Behavior.Retries Flags On 504 ✅ 1110ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 210ms

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error tracking auto capture

0 participants