Skip to content

SDK-1056: Add opt-in exception capture to the Unity Audience SDK - #834

Open
nattb8 wants to merge 1 commit into
mainfrom
feat/sdk-1056-exception-capture
Open

nattb8 wants to merge 1 commit into
mainfrom
feat/sdk-1056-exception-capture

Conversation

@nattb8

@nattb8 nattb8 commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

What

  • New ErrorTrackingConfig.CaptureExceptions, off by default
  • When on, the SDK listens for uncaught C# exceptions via Application.logMessageReceivedThreaded, filtered to LogType.Exception only
  • Each one is sent through the existing Track pipeline as a new exception_captured event, with exception type, message, and stack trace as properties
  • Rate limited per exception type via a token bucket: burst up to 20, refills 1 every 10 seconds. A repeating bug settles into a steady trickle instead of going silent, and can't crowd out a different, unrelated exception type. Matches how PostHog's own client-side exception rate limiter works
  • Pure C#, works the same on Windows, Mac, Linux, iOS, and Android
  • Sample app: adds a Capture Exceptions toggle and a Throw Test Exception button to the Setup tab, so this is covered by the same PlayMode E2E suite every other feature is

Why

Right now an uncaught exception only shows up in a studio's own local Unity console, nothing reaches Immutable. This is the cheap first step before real native crash reporting (segfaults, ANRs), which is separate, bigger work.

Test plan

  • Manually verified end to end in the sample app: forced the config on, triggered a real exception via Debug.LogException, and confirmed the actual outgoing payload contained "eventName":"exception_captured" with the right properties
  • Unit tests for the rate limiter itself (burst capacity, refill over time, independent buckets per exception type, reset) using an injectable fake clock, no real waiting
  • Integration tests on ImmutableAudience.CaptureException: disabled by default, consent gating, burst-then-stop, different types not sharing a bucket, refill over time, and the cap resetting on a fresh Init after Shutdown
  • New PlayMode E2E tests: capture enabled queues the event and flush reports no errors; capture disabled leaves the queue untouched
  • Sample app E2E CI check can be flaky, unrelated to this change if it fails, commitlint/unit tests/lint are the ones that should be clean

Ticket: SDK-1056

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Audience SDK — Build Size

Platform SDK Size Change
Android 0.40 / 20.00 MB +0.04 MB ✅
Windows 0.17 / 20.00 MB +0.01 MB ✅
iOS 8.62 / 20.00 MB +0.10 MB ✅
macOS 1.04 / 20.00 MB +0.13 MB ✅

SDK Size = build minus empty app. Change = vs baseline. Fails if any platform exceeds its absolute size limit.

@nattb8
nattb8 force-pushed the feat/sdk-1056-exception-capture branch 4 times, most recently from 6f63d91 to a77c189 Compare September 29, 2026 02:22
Adds ErrorTrackingConfig.CaptureExceptions, off by default. When set,
the SDK listens for uncaught C# exceptions via Unity's
logMessageReceivedThreaded and sends them as an exception_captured
event through the existing Track pipeline.

Rate limited per exception type via a token bucket (burst 20, refills
1 every 10s), not one shared counter, so a repeating exception can't
flood the queue or crowd out a different, unrelated one. Matches how
PostHog's client-side exception rate limiter is designed.

Adds a Capture Exceptions toggle and a Throw Test Exception button to
the sample app's Setup tab, plus PlayMode E2E coverage confirming the
event queues when enabled and doesn't when disabled.

No native crash capture (segfaults, ANRs). Managed exceptions only.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@nattb8
nattb8 force-pushed the feat/sdk-1056-exception-capture branch from a77c189 to efd5005 Compare September 29, 2026 02:30
@nattb8
nattb8 marked this pull request as ready for review September 29, 2026 08:16
@nattb8
nattb8 requested review from a team as code owners September 29, 2026 08:16

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants