Commit cf4a852
committed
feat(server): opt-in uncaught exception capture
Adds captureUncaughtExceptions (default false) to the server PostHogConfig.
When enabled, the core PostHogErrorTrackingAutoCaptureIntegration installs a
Thread.defaultUncaughtExceptionHandler that captures the throwable as a fatal,
unhandled $exception (mechanism UncaughtExceptionHandler), flushes, then
delegates to the previously installed handler.
Core changes (all additive; Android behavior and the released
install(PostHogInterface) path unchanged):
- Gate strategy seam on the integration so the server can install with a
local-only gate (no remote config, which the server SDK never fetches);
Android keeps the remote errorTracking.autocaptureExceptions gate.
- Captures flow through an internal CaptureTarget seam so the server's
stateless client can drive the integration.
- Handler-install ownership is tracked per integration instance, so closing a
second opted-in client (whose install was a process-wide no-op) does not
tear down the handler a still-open first client owns.
- New @PostHogInternal PostHogCapturedThrowables identity marker (weak,
ReferenceQueue-pruned). The guard is directional: log mirrors consult it,
the uncaught handler only marks — a crash is always captured as the
authoritative fatal/unhandled record even if the same instance was logged
first (logger.error(..., e); throw e), and marking keeps post-crash log
mirrors from re-reporting it.
- Repeated setup() cannot replace the owning integration with a non-owning
one, which would leave the global handler installed after close().
- With no previous default handler to chain to, the handler reproduces the
JVM's built-in stderr crash output so enabling capture never hides crashes
from stderr log collection.
- Server config KDoc documents the flushAt implication for the crash path.1 parent 2174c3c commit cf4a852
12 files changed
Lines changed: 736 additions & 9 deletions
File tree
- .changeset
- posthog-server
- api
- src
- main/java/com/posthog/server
- test/java/com/posthog/server
- posthog
- api
- src
- main/java/com/posthog
- errortracking
- internal/errortracking
- test/java/com/posthog
- errortracking
- internal/errortracking
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| 137 | + | |
137 | 138 | | |
138 | 139 | | |
139 | 140 | | |
| |||
158 | 159 | | |
159 | 160 | | |
160 | 161 | | |
| 162 | + | |
161 | 163 | | |
162 | 164 | | |
163 | 165 | | |
| |||
185 | 187 | | |
186 | 188 | | |
187 | 189 | | |
| 190 | + | |
188 | 191 | | |
189 | 192 | | |
190 | 193 | | |
| |||
Lines changed: 44 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
30 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
31 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
32 | 74 | | |
33 | 75 | | |
34 | 76 | | |
| 77 | + | |
| 78 | + | |
35 | 79 | | |
36 | 80 | | |
37 | 81 | | |
| |||
Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
202 | 224 | | |
203 | 225 | | |
204 | 226 | | |
| |||
374 | 396 | | |
375 | 397 | | |
376 | 398 | | |
| 399 | + | |
377 | 400 | | |
378 | 401 | | |
379 | 402 | | |
| |||
580 | 603 | | |
581 | 604 | | |
582 | 605 | | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
583 | 615 | | |
584 | 616 | | |
585 | 617 | | |
| |||
614 | 646 | | |
615 | 647 | | |
616 | 648 | | |
| 649 | + | |
617 | 650 | | |
618 | 651 | | |
619 | 652 | | |
| |||
0 commit comments