@logbrew/react-native 0.1.34 → 0.1.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +33 -4
  2. package/android/src/main/java/co/logbrew/reactnative/AndroidDiagnosticsRuntime.java +2 -0
  3. package/android/src/main/java/co/logbrew/reactnative/AndroidNativeDiagnostics.java +56 -2
  4. package/android/src/main/java/co/logbrew/reactnative/EventRecordStore.java +25 -0
  5. package/android/src/main/java/co/logbrew/reactnative/FatalStoreModuleImpl.java +30 -3
  6. package/android/src/newarch/java/co/logbrew/reactnative/FatalStoreModule.java +6 -0
  7. package/android/src/oldarch/java/co/logbrew/reactnative/FatalStoreModule.java +6 -0
  8. package/expo.cjs +1 -1
  9. package/fatal-replay.cjs +97 -110
  10. package/global-errors.cjs +94 -130
  11. package/global-errors.d.cts +23 -3
  12. package/global-errors.d.ts +23 -3
  13. package/index.cjs +47 -20
  14. package/index.d.cts +1 -0
  15. package/index.d.ts +1 -0
  16. package/index.native.js +4 -3
  17. package/instrumentation.cjs +80 -57
  18. package/ios/AppleDiagnostics/LBRNAppleNativeDiagnostics.swift +1 -1
  19. package/ios/GeneratedAppleDiagnostics/LogBrewCrash/NativeCrashCorrelation.swift +2 -0
  20. package/ios/GeneratedAppleDiagnostics/LogBrewCrash/NativeCrashReplay.swift +31 -7
  21. package/ios/GeneratedAppleDiagnostics/SOURCE-MANIFEST.json +2 -2
  22. package/ios/LBRNEventRecordStore.h +1 -0
  23. package/ios/LBRNEventRecordStore.m +43 -0
  24. package/ios/LBRNFatalStoreModule.mm +14 -0
  25. package/metadata.cjs +1 -1
  26. package/native-bridge.cjs +112 -8
  27. package/native-bridge.d.cts +34 -0
  28. package/native-bridge.d.ts +34 -0
  29. package/native-bridge.js +2 -1
  30. package/package.json +1 -1
  31. package/persistent-delivery.native.js +12 -1
  32. package/promise-rejections.cjs +11 -1
  33. package/src/NativeLogBrewFatalStore.ts +4 -0
package/global-errors.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  const { createReactNativeErrorEvent } = require("./index.cjs");
4
- const { createFatalController } = require("./fatal-replay.cjs");
4
+ const { captureIssueWithAdmission, createFatalController } = require("./fatal-replay.cjs");
5
5
  const {
6
6
  createLogBrewReactNativePromiseRejectionHandlers,
7
7
  installLogBrewReactNativePromiseRejectionTracker
@@ -9,7 +9,6 @@ const {
9
9
 
10
10
  const AUTOMATIC_ERROR_MESSAGE = "React Native global JavaScript report";
11
11
  const MAX_STACK_BYTES = 16 * 1024;
12
- const MAX_STACK_FRAMES = 32;
13
12
  const SAFE_ERROR_NAMES = new Set([
14
13
  "Error",
15
14
  "EvalError",
@@ -19,11 +18,7 @@ const SAFE_ERROR_NAMES = new Set([
19
18
  "TypeError",
20
19
  "URIError"
21
20
  ]);
22
- const FATAL_SANITIZERS = Object.freeze({
23
- errorName: safeErrorName,
24
- isErrorName: (value) => SAFE_ERROR_NAMES.has(value),
25
- stackFrame: safeStackFrameParts
26
- });
21
+ const LAST_ROUTE = Symbol.for("co.logbrew.react-native.last-route");
27
22
  const installations = new WeakMap();
28
23
  let nextEventSequence = 0;
29
24
 
@@ -61,17 +56,19 @@ function installLogBrewReactNativeGlobalErrorHandler({
61
56
  const state = {
62
57
  active: true,
63
58
  capturedEvents: 0,
59
+ emittingDiagnostic: false,
64
60
  handling: false,
65
61
  lastOutcome: "idle",
66
62
  suppressedEvents: 0
67
63
  };
68
64
  const fatal = createFatalController({
69
65
  client,
66
+ createEvent: (error) => createAutomaticErrorEvent(error, client, true),
70
67
  eventMessage: AUTOMATIC_ERROR_MESSAGE,
71
68
  fatalStore,
69
+ isErrorName: (value) => SAFE_ERROR_NAMES.has(value),
72
70
  issue,
73
- onDiagnostic,
74
- sanitizers: FATAL_SANITIZERS
71
+ onDiagnostic: (diagnostic) => emitStateDiagnostic(state, onDiagnostic, diagnostic.code)
75
72
  });
76
73
  const capturedErrors = new WeakSet();
77
74
  const handler = (error, isFatal) => {
@@ -87,10 +84,17 @@ function installLogBrewReactNativeGlobalErrorHandler({
87
84
  try {
88
85
  if (isFatal === true) {
89
86
  if (fatal.available) {
90
- state.lastOutcome = fatal.store(error) ? "fatal_stored" : "fatal_store_failed";
87
+ if (fatal.store(error)) {
88
+ state.lastOutcome = "fatal_stored";
89
+ markPersistedFatal(client);
90
+ } else {
91
+ state.lastOutcome = fatal.health().lastOutcome === "admission_unavailable"
92
+ ? "admission_unavailable"
93
+ : "fatal_store_failed";
94
+ }
91
95
  } else {
92
96
  state.lastOutcome = "fatal_unsupported";
93
- emitDiagnostic(onDiagnostic, "fatal_capture_requires_sync_store");
97
+ emitStateDiagnostic(state, onDiagnostic, "fatal_capture_requires_sync_store");
94
98
  }
95
99
  } else if (isObjectLike(error) && capturedErrors.has(error)) {
96
100
  recordSuppression(state, onDiagnostic, "duplicate_capture_suppressed");
@@ -166,14 +170,37 @@ function installLogBrewReactNativeGlobalErrorHandler({
166
170
  return installation;
167
171
  }
168
172
 
173
+ // The last breadcrumb tells Apple crash capture that the JavaScript report already
174
+ // holds this crash, so the RCTFatalException that React Native raises next is not
175
+ // reported twice.
176
+ function markPersistedFatal(client) {
177
+ try {
178
+ client.addBreadcrumb({ category: "react-native.fatal", level: "fatal", type: "error" });
179
+ } catch {
180
+ // The report is stored; without the marker the native copy is only a duplicate.
181
+ }
182
+ }
183
+
169
184
  function captureNonfatalError(client, issue, error, capturedErrors, state, onDiagnostic) {
170
185
  const tracksIdentity = isObjectLike(error);
171
186
  if (tracksIdentity) {
172
187
  capturedErrors.add(error);
173
188
  }
174
189
  try {
175
- const event = createAutomaticErrorEvent(error);
176
- issue.call(client, event.id, event.timestamp, event.attributes);
190
+ const event = createAutomaticErrorEvent(error, client);
191
+ const admission = captureIssueWithAdmission(client, issue, event.id, event.timestamp, event.attributes);
192
+ if (admission !== "admitted") {
193
+ if (tracksIdentity) {
194
+ capturedErrors.delete(error);
195
+ }
196
+ state.lastOutcome = admission === "unavailable"
197
+ ? "admission_unavailable"
198
+ : admission === "filtered" ? "filtered" : "capture_failed";
199
+ emitStateDiagnostic(state, onDiagnostic, admission === "unavailable"
200
+ ? "capture_admission_unavailable"
201
+ : admission === "filtered" ? "capture_filtered" : "capture_failed");
202
+ return;
203
+ }
177
204
  state.capturedEvents = incrementBounded(state.capturedEvents);
178
205
  state.lastOutcome = "captured";
179
206
  } catch {
@@ -181,36 +208,51 @@ function captureNonfatalError(client, issue, error, capturedErrors, state, onDia
181
208
  capturedErrors.delete(error);
182
209
  }
183
210
  state.lastOutcome = "capture_failed";
184
- emitDiagnostic(onDiagnostic, "capture_failed");
211
+ emitStateDiagnostic(state, onDiagnostic, "capture_failed");
185
212
  }
186
213
  }
187
214
 
188
- function createAutomaticErrorEvent(error) {
215
+ function createAutomaticErrorEvent(error, client, fatal = false) {
189
216
  const sanitizedError = new Error(AUTOMATIC_ERROR_MESSAGE);
190
217
  sanitizedError.name = safeErrorName(error);
191
- const stack = safeStack(error);
192
- if (stack) {
193
- sanitizedError.stack = stack;
194
- } else {
195
- delete sanitizedError.stack;
196
- }
218
+ sanitizedError.stack = automaticStack(error);
219
+ const lastRoute = safeReadProperty(client, LAST_ROUTE);
197
220
  const event = createReactNativeErrorEvent(sanitizedError, {
198
- id: nextEventId(),
221
+ id: nextEventId(fatal ? "fatal" : "global"),
199
222
  handled: false,
200
223
  includeStack: false,
224
+ level: fatal ? "fatal" : "error",
201
225
  mechanism: "react_native_error_utils"
202
226
  });
227
+ const { exceptionChain, metadata, stackFrames } = event.attributes;
228
+ // Frames keep file basenames only; Debug IDs were already matched on the full path.
203
229
  return {
204
230
  ...event,
205
231
  attributes: {
206
232
  ...event.attributes,
233
+ exceptionChain: {
234
+ ...exceptionChain,
235
+ entries: exceptionChain.entries.map((entry) => ({
236
+ ...entry,
237
+ ...(entry.stackFrames ? { stackFrames: basenameFrames(entry.stackFrames) } : {})
238
+ }))
239
+ },
240
+ ...(stackFrames ? { stackFrames: basenameFrames(stackFrames) } : {}),
207
241
  title: AUTOMATIC_ERROR_MESSAGE,
208
242
  message: AUTOMATIC_ERROR_MESSAGE,
209
243
  metadata: {
210
- ...event.attributes.metadata,
244
+ ...metadata,
245
+ ...(metadata.errorFrameFile ? { errorFrameFile: basename(metadata.errorFrameFile) } : {}),
246
+ ...(metadata.releaseArtifactCodeFile
247
+ ? { releaseArtifactCodeFile: basename(metadata.releaseArtifactCodeFile) }
248
+ : {}),
249
+ ...(typeof metadata.issueGroupingKey === "string"
250
+ ? { issueGroupingKey: metadata.issueGroupingKey.replace(/^([^:]+:[^:]+:).*[\\/]/u, "$1") }
251
+ : {}),
211
252
  automatic: true,
212
- fatal: false,
213
- handled: true,
253
+ fatal,
254
+ handled: !fatal,
255
+ ...(typeof lastRoute === "string" ? { lastRoute } : {}),
214
256
  mechanism: "react_native_error_utils",
215
257
  source: "react-native.global_error"
216
258
  }
@@ -218,99 +260,24 @@ function createAutomaticErrorEvent(error) {
218
260
  };
219
261
  }
220
262
 
221
- function safeStack(error) {
263
+ // Hermes and V8 put the message before the frames. Keep only frame lines so
264
+ // message text cannot become a frame, even when the message changed later.
265
+ function automaticStack(error) {
222
266
  const stack = safeReadProperty(error, "stack");
223
- const candidate = typeof stack === "string"
224
- ? stack.slice(0, MAX_STACK_BYTES)
225
- : "";
226
- const frames = [];
227
- for (const line of candidate.split(/\r?\n/u)) {
228
- const frame = safeStackFrame(line);
229
- if (frame) {
230
- frames.push(` at frame (${frame})`);
231
- if (frames.length === MAX_STACK_FRAMES) {
232
- break;
233
- }
234
- }
235
- }
236
- return frames.length === 0
237
- ? undefined
238
- : `${safeErrorName(error)}: ${AUTOMATIC_ERROR_MESSAGE}\n${frames.join("\n")}`;
239
- }
240
-
241
- function safeStackFrame(line) {
242
- const frame = safeStackFrameParts(line);
243
- return frame
244
- ? `${frame.filename}:${frame.line}:${frame.column}`
245
- : undefined;
246
- }
247
-
248
- function safeStackFrameParts(line) {
249
- let location = typeof line === "string" ? line.trim() : "";
250
- if (!location) {
251
- return undefined;
252
- }
253
- if (location.startsWith("at ")) {
254
- location = location.slice(3).trim();
255
- if (location.endsWith(")") && location.includes("(")) {
256
- location = location.slice(location.lastIndexOf("(") + 1, -1);
257
- }
258
- } else if (location.includes("@")) {
259
- location = location.slice(location.lastIndexOf("@") + 1);
260
- }
261
- const parts = location.split(":");
262
- if (parts.length < 3) {
263
- return undefined;
264
- }
265
- const column = positiveInteger(parts.pop());
266
- const lineNumber = positiveInteger(parts.pop());
267
- const filename = safeStackFilename(parts.join(":"));
268
- if (!filename || lineNumber === undefined || column === undefined) {
269
- return undefined;
267
+ if (typeof stack !== "string") {
268
+ return "";
270
269
  }
271
- return {
272
- column,
273
- filename,
274
- line: lineNumber
275
- };
270
+ const lines = stack.slice(0, MAX_STACK_BYTES).split(/\r?\n/u);
271
+ const frames = lines.filter((line) => line.trimStart().startsWith("at "));
272
+ return (frames.length > 0 ? frames : lines).join("\n");
276
273
  }
277
274
 
278
- function safeStackFilename(value) {
279
- let filename = String(value ?? "").trim().replace(/\\/gu, "/");
280
- if (!filename || filename.length > 2048 || hasControlCharacter(filename)) {
281
- return undefined;
282
- }
283
- try {
284
- if (/^[a-z][a-z0-9+.-]*:/iu.test(filename)) {
285
- const parsed = new URL(filename);
286
- if (!["app:", "http:", "https:"].includes(parsed.protocol)
287
- || parsed.username
288
- || urlAuthority(filename).includes("@")) {
289
- return undefined;
290
- }
291
- filename = parsed.pathname;
292
- } else {
293
- filename = filename.split(/[?#]/u, 1)[0];
294
- if (filename.startsWith("/") || /^[A-Za-z]:\//u.test(filename)) {
295
- return undefined;
296
- }
297
- }
298
- } catch {
299
- return undefined;
300
- }
301
- return filename && filename.length <= 2048 && !hasControlCharacter(filename)
302
- ? filename
303
- : undefined;
275
+ function basenameFrames(frames) {
276
+ return frames?.map((frame) => ({ ...frame, filename: basename(frame.filename) }));
304
277
  }
305
278
 
306
- function urlAuthority(value) {
307
- const schemeMarker = value.indexOf("://");
308
- if (schemeMarker < 0) {
309
- return "";
310
- }
311
- const start = schemeMarker + 3;
312
- const end = value.indexOf("/", start);
313
- return value.slice(start, end < 0 ? value.length : end);
279
+ function basename(value) {
280
+ return typeof value === "string" ? value.replace(/^.*[\\/]/u, "") : value;
314
281
  }
315
282
 
316
283
  function safeErrorName(error) {
@@ -335,24 +302,9 @@ function safeFunction(value, property) {
335
302
  return typeof candidate === "function" ? candidate : undefined;
336
303
  }
337
304
 
338
- function hasControlCharacter(value) {
339
- return Array.from(value).some((character) => {
340
- const code = character.codePointAt(0);
341
- return code !== undefined && (code <= 31 || code === 127);
342
- });
343
- }
344
-
345
- function positiveInteger(value) {
346
- if (!/^[1-9][0-9]*$/u.test(String(value))) {
347
- return undefined;
348
- }
349
- const number = Number(value);
350
- return Number.isSafeInteger(number) && number <= 2147483647 ? number : undefined;
351
- }
352
-
353
- function nextEventId() {
305
+ function nextEventId(kind) {
354
306
  nextEventSequence = incrementBounded(nextEventSequence);
355
- return `evt_rn_global_${Date.now().toString(36)}_${nextEventSequence.toString(36)}`;
307
+ return `evt_rn_${kind}_${Date.now().toString(36)}_${nextEventSequence.toString(36)}`;
356
308
  }
357
309
 
358
310
  function incrementBounded(value) {
@@ -362,7 +314,19 @@ function incrementBounded(value) {
362
314
  function recordSuppression(state, onDiagnostic, code) {
363
315
  state.suppressedEvents = incrementBounded(state.suppressedEvents);
364
316
  state.lastOutcome = code === "recursive_capture_suppressed" ? "recursive_suppressed" : "duplicate_suppressed";
365
- emitDiagnostic(onDiagnostic, code);
317
+ emitStateDiagnostic(state, onDiagnostic, code);
318
+ }
319
+
320
+ function emitStateDiagnostic(state, onDiagnostic, code) {
321
+ if (state.emittingDiagnostic) {
322
+ return;
323
+ }
324
+ state.emittingDiagnostic = true;
325
+ try {
326
+ emitDiagnostic(onDiagnostic, code);
327
+ } finally {
328
+ state.emittingDiagnostic = false;
329
+ }
366
330
  }
367
331
 
368
332
  function emitDiagnostic(onDiagnostic, code) {
@@ -7,10 +7,17 @@ export type ReactNativeErrorUtilsLike = {
7
7
  setGlobalHandler(handler: ReactNativeGlobalErrorHandler | undefined): void;
8
8
  };
9
9
 
10
+ export type ReactNativeIssueCaptureClient = Pick<LogBrewClient, "issue"> & {
11
+ /** Optional synchronous receipt for this call. Older clients remain supported. */
12
+ issueWithAdmission?: (...args: Parameters<LogBrewClient["issue"]>) => unknown;
13
+ };
14
+
10
15
  export type ReactNativePromiseRejectionDiagnosticCode =
16
+ | "promise_rejection_admission_unavailable"
11
17
  | "promise_rejection_capture_failed"
12
18
  | "promise_rejection_configuration_invalid"
13
19
  | "promise_rejection_duplicate_suppressed"
20
+ | "promise_rejection_filtered"
14
21
  | "promise_rejection_handler_unavailable"
15
22
  | "promise_rejection_id_unavailable"
16
23
  | "promise_rejection_recursive_capture_suppressed"
@@ -24,13 +31,17 @@ export type ReactNativePromiseRejectionDiagnostic = Readonly<{
24
31
  }>;
25
32
 
26
33
  export type ReactNativeGlobalErrorDiagnosticCode =
34
+ | "capture_admission_unavailable"
27
35
  | "capture_failed"
36
+ | "capture_filtered"
28
37
  | "duplicate_capture_suppressed"
29
38
  | "fatal_acknowledge_failed"
39
+ | "fatal_admission_unavailable"
30
40
  | "fatal_capture_requires_sync_store"
31
41
  | "fatal_corrupt_record_discarded"
32
42
  | "fatal_discard_failed"
33
43
  | "fatal_record_dropped"
44
+ | "fatal_replay_admission_unavailable"
34
45
  | "fatal_replay_failed"
35
46
  | "fatal_replay_not_admitted"
36
47
  | "fatal_store_failed"
@@ -45,12 +56,14 @@ export type ReactNativeGlobalErrorHealth = Readonly<{
45
56
  active: boolean;
46
57
  capturedEvents: number;
47
58
  lastOutcome:
59
+ | "admission_unavailable"
48
60
  | "capture_failed"
49
61
  | "captured"
50
62
  | "duplicate_suppressed"
51
63
  | "fatal_stored"
52
64
  | "fatal_store_failed"
53
65
  | "fatal_unsupported"
66
+ | "filtered"
54
67
  | "handler_replaced"
55
68
  | "idle"
56
69
  | "recursive_suppressed"
@@ -66,11 +79,13 @@ export type ReactNativePromiseRejectionHealth = Readonly<{
66
79
  evictedRejections: number;
67
80
  handledLaterEvents: number;
68
81
  lastOutcome:
82
+ | "admission_unavailable"
69
83
  | "capture_failed"
70
84
  | "captured"
71
85
  | "captured_untracked"
72
86
  | "captured_with_eviction"
73
87
  | "duplicate_suppressed"
88
+ | "filtered"
74
89
  | "handled_later"
75
90
  | "handled_unknown"
76
91
  | "idle"
@@ -84,7 +99,7 @@ export type ReactNativePromiseRejectionHealth = Readonly<{
84
99
  }>;
85
100
 
86
101
  export type CreateLogBrewReactNativePromiseRejectionHandlersOptions = {
87
- client: Pick<LogBrewClient, "issue">;
102
+ client: ReactNativeIssueCaptureClient;
88
103
  /**
89
104
  * Maximum number of safe runtime rejection identifiers retained for duplicate
90
105
  * suppression and later-handled health. Defaults to 128 and must be 1-1024.
@@ -108,7 +123,7 @@ export type ReactNativePromiseRejectionTrackerLike = {
108
123
  };
109
124
 
110
125
  export type InstallLogBrewReactNativePromiseRejectionTrackerOptions = {
111
- client: Pick<LogBrewClient, "issue">;
126
+ client: ReactNativeIssueCaptureClient;
112
127
  /**
113
128
  * Confirms that LogBrew may claim the runtime's single Promise rejection
114
129
  * tracker slot. Do not install another tracker owner at the same time.
@@ -184,6 +199,7 @@ export type ReactNativeFatalReplayHealth = Readonly<{
184
199
  lastOutcome:
185
200
  | "acknowledge_failed"
186
201
  | "acknowledged"
202
+ | "admission_unavailable"
187
203
  | "corrupt_discarded"
188
204
  | "discard_failed"
189
205
  | "discarded"
@@ -201,7 +217,7 @@ export type ReactNativeFatalReplayHealth = Readonly<{
201
217
  }>;
202
218
 
203
219
  export type InstallLogBrewReactNativeGlobalErrorHandlerOptions = {
204
- client: Pick<LogBrewClient, "issue">
220
+ client: ReactNativeIssueCaptureClient
205
221
  & Partial<Pick<LogBrewClient, "droppedEvents" | "pendingEvents">>;
206
222
  errorUtils?: ReactNativeErrorUtilsLike;
207
223
  fatalStore?: ReactNativeFatalStoreLike;
@@ -221,6 +237,8 @@ export type LogBrewReactNativeGlobalErrorHandlerInstallation = Readonly<{
221
237
  * The callbacks do not install or patch Promise, Hermes, JavaScriptCore, or globals.
222
238
  * Automatic reports never inspect or emit the rejection value or runtime identifier.
223
239
  * Tracking is bounded and suppresses duplicate callbacks only while an identifier is retained.
240
+ * Capture counts and tracking require an admitted receipt. Without a receipt, each report
241
+ * calls issue once, reports admission_unavailable, and remains eligible for a later report.
224
242
  */
225
243
  export declare function createLogBrewReactNativePromiseRejectionHandlers(
226
244
  options: CreateLogBrewReactNativePromiseRejectionHandlersOptions
@@ -243,6 +261,8 @@ export declare function installLogBrewReactNativePromiseRejectionTracker(
243
261
  * The React Native conditional export admits fatal reports into its persistent event queue
244
262
  * before the previous handler runs. Direct Node ESM/CJS callers can inject a compatible
245
263
  * fatal store explicitly.
264
+ * Capture counts, duplicate suppression, and fatal acknowledgement require an admitted receipt.
265
+ * Older clients receive each report once and report admission_unavailable.
246
266
  * This helper does not claim local exactly-once delivery or install Promise rejection handling.
247
267
  */
248
268
  export declare function installLogBrewReactNativeGlobalErrorHandler(
@@ -7,10 +7,17 @@ export type ReactNativeErrorUtilsLike = {
7
7
  setGlobalHandler(handler: ReactNativeGlobalErrorHandler | undefined): void;
8
8
  };
9
9
 
10
+ export type ReactNativeIssueCaptureClient = Pick<LogBrewClient, "issue"> & {
11
+ /** Optional synchronous receipt for this call. Older clients remain supported. */
12
+ issueWithAdmission?: (...args: Parameters<LogBrewClient["issue"]>) => unknown;
13
+ };
14
+
10
15
  export type ReactNativePromiseRejectionDiagnosticCode =
16
+ | "promise_rejection_admission_unavailable"
11
17
  | "promise_rejection_capture_failed"
12
18
  | "promise_rejection_configuration_invalid"
13
19
  | "promise_rejection_duplicate_suppressed"
20
+ | "promise_rejection_filtered"
14
21
  | "promise_rejection_handler_unavailable"
15
22
  | "promise_rejection_id_unavailable"
16
23
  | "promise_rejection_recursive_capture_suppressed"
@@ -24,13 +31,17 @@ export type ReactNativePromiseRejectionDiagnostic = Readonly<{
24
31
  }>;
25
32
 
26
33
  export type ReactNativeGlobalErrorDiagnosticCode =
34
+ | "capture_admission_unavailable"
27
35
  | "capture_failed"
36
+ | "capture_filtered"
28
37
  | "duplicate_capture_suppressed"
29
38
  | "fatal_acknowledge_failed"
39
+ | "fatal_admission_unavailable"
30
40
  | "fatal_capture_requires_sync_store"
31
41
  | "fatal_corrupt_record_discarded"
32
42
  | "fatal_discard_failed"
33
43
  | "fatal_record_dropped"
44
+ | "fatal_replay_admission_unavailable"
34
45
  | "fatal_replay_failed"
35
46
  | "fatal_replay_not_admitted"
36
47
  | "fatal_store_failed"
@@ -45,12 +56,14 @@ export type ReactNativeGlobalErrorHealth = Readonly<{
45
56
  active: boolean;
46
57
  capturedEvents: number;
47
58
  lastOutcome:
59
+ | "admission_unavailable"
48
60
  | "capture_failed"
49
61
  | "captured"
50
62
  | "duplicate_suppressed"
51
63
  | "fatal_stored"
52
64
  | "fatal_store_failed"
53
65
  | "fatal_unsupported"
66
+ | "filtered"
54
67
  | "handler_replaced"
55
68
  | "idle"
56
69
  | "recursive_suppressed"
@@ -66,11 +79,13 @@ export type ReactNativePromiseRejectionHealth = Readonly<{
66
79
  evictedRejections: number;
67
80
  handledLaterEvents: number;
68
81
  lastOutcome:
82
+ | "admission_unavailable"
69
83
  | "capture_failed"
70
84
  | "captured"
71
85
  | "captured_untracked"
72
86
  | "captured_with_eviction"
73
87
  | "duplicate_suppressed"
88
+ | "filtered"
74
89
  | "handled_later"
75
90
  | "handled_unknown"
76
91
  | "idle"
@@ -84,7 +99,7 @@ export type ReactNativePromiseRejectionHealth = Readonly<{
84
99
  }>;
85
100
 
86
101
  export type CreateLogBrewReactNativePromiseRejectionHandlersOptions = {
87
- client: Pick<LogBrewClient, "issue">;
102
+ client: ReactNativeIssueCaptureClient;
88
103
  /**
89
104
  * Maximum number of safe runtime rejection identifiers retained for duplicate
90
105
  * suppression and later-handled health. Defaults to 128 and must be 1-1024.
@@ -108,7 +123,7 @@ export type ReactNativePromiseRejectionTrackerLike = {
108
123
  };
109
124
 
110
125
  export type InstallLogBrewReactNativePromiseRejectionTrackerOptions = {
111
- client: Pick<LogBrewClient, "issue">;
126
+ client: ReactNativeIssueCaptureClient;
112
127
  /**
113
128
  * Confirms that LogBrew may claim the runtime's single Promise rejection
114
129
  * tracker slot. Do not install another tracker owner at the same time.
@@ -184,6 +199,7 @@ export type ReactNativeFatalReplayHealth = Readonly<{
184
199
  lastOutcome:
185
200
  | "acknowledge_failed"
186
201
  | "acknowledged"
202
+ | "admission_unavailable"
187
203
  | "corrupt_discarded"
188
204
  | "discard_failed"
189
205
  | "discarded"
@@ -201,7 +217,7 @@ export type ReactNativeFatalReplayHealth = Readonly<{
201
217
  }>;
202
218
 
203
219
  export type InstallLogBrewReactNativeGlobalErrorHandlerOptions = {
204
- client: Pick<LogBrewClient, "issue">
220
+ client: ReactNativeIssueCaptureClient
205
221
  & Partial<Pick<LogBrewClient, "droppedEvents" | "pendingEvents">>;
206
222
  errorUtils?: ReactNativeErrorUtilsLike;
207
223
  fatalStore?: ReactNativeFatalStoreLike;
@@ -221,6 +237,8 @@ export type LogBrewReactNativeGlobalErrorHandlerInstallation = Readonly<{
221
237
  * The callbacks do not install or patch Promise, Hermes, JavaScriptCore, or globals.
222
238
  * Automatic reports never inspect or emit the rejection value or runtime identifier.
223
239
  * Tracking is bounded and suppresses duplicate callbacks only while an identifier is retained.
240
+ * Capture counts and tracking require an admitted receipt. Without a receipt, each report
241
+ * calls issue once, reports admission_unavailable, and remains eligible for a later report.
224
242
  */
225
243
  export declare function createLogBrewReactNativePromiseRejectionHandlers(
226
244
  options: CreateLogBrewReactNativePromiseRejectionHandlersOptions
@@ -243,6 +261,8 @@ export declare function installLogBrewReactNativePromiseRejectionTracker(
243
261
  * The React Native conditional export admits fatal reports into its persistent event queue
244
262
  * before the previous handler runs. Direct Node ESM/CJS callers can inject a compatible
245
263
  * fatal store explicitly.
264
+ * Capture counts, duplicate suppression, and fatal acknowledgement require an admitted receipt.
265
+ * Older clients receive each report once and report admission_unavailable.
246
266
  * This helper does not claim local exactly-once delivery or install Promise rejection handling.
247
267
  */
248
268
  export declare function installLogBrewReactNativeGlobalErrorHandler(
package/index.cjs CHANGED
@@ -16,13 +16,16 @@ const {
16
16
  } = require("./metadata.cjs");
17
17
 
18
18
  const DEFAULT_SDK_NAME = "logbrew-react-native";
19
- const DEFAULT_SDK_VERSION = "0.1.34";
19
+ const DEFAULT_SDK_VERSION = "0.1.36";
20
20
  const DEFAULT_ENDPOINT = "https://api.logbrew.co/v1/events";
21
21
  const NATIVE_RANDOM_HEX = Symbol.for("co.logbrew.react-native.secure-random-hex");
22
22
  const MAX_ACTION_NAME_LENGTH = 64;
23
23
  const MAX_PRODUCT_ANALYTICS_SURFACE_LENGTH = 256;
24
24
  const SCREEN_ACTION_PREFIX = "screen:";
25
+ const LAST_ROUTE = Symbol.for("co.logbrew.react-native.last-route");
25
26
  const BACKGROUND_APP_STATES = new Set(["background", "inactive"]);
27
+ // Mobile keeps a 5-second interval to save battery and radio wakeups; flushOnBackground sends the rest.
28
+ const DEFAULT_REACT_NATIVE_DELIVERY_INTERVAL_MS = 5000;
26
29
  const LogBrewNativeContext = React.createContext(null);
27
30
  const activeTraceScopes = [];
28
31
  let nextTraceScopeId = 0;
@@ -53,7 +56,7 @@ function createLogBrewReactNativeClient({
53
56
  apiKey: authKey,
54
57
  automaticDelivery,
55
58
  context,
56
- deliveryIntervalMs,
59
+ deliveryIntervalMs: deliveryIntervalMs ?? DEFAULT_REACT_NATIVE_DELIVERY_INTERVAL_MS,
57
60
  deliveryQueueThreshold,
58
61
  eventStore,
59
62
  maxBatchBytes,
@@ -571,27 +574,47 @@ function createReactNavigationSpanListener(client, navigationContainer, {
571
574
  }
572
575
  };
573
576
 
574
- const actionSubscription = safeNavigationListener(container, "__unsafe_action__", (event) => {
575
- pendingNavigation = {
576
- actionType: navigationActionType(event),
577
- startedAtMs: nowMs(),
578
- timestamp: now()
579
- };
580
- });
581
- if (actionSubscription) {
582
- removers.push(actionSubscription);
583
- }
584
- removers.push(addNavigationListener(container, "state", captureCurrentRoute));
585
-
586
- if (captureInitialRoute) {
587
- captureCurrentRoute();
588
- }
589
-
590
- return () => {
577
+ const removeListeners = () => {
578
+ const failures = [];
579
+ const failedRemovers = [];
591
580
  for (const remove of removers.splice(0).reverse()) {
592
- remove();
581
+ try {
582
+ remove();
583
+ } catch (error) {
584
+ failedRemovers.unshift(remove);
585
+ failures.push(error);
586
+ }
587
+ }
588
+ removers.push(...failedRemovers);
589
+ if (failures.length > 0) {
590
+ throw failures[0];
593
591
  }
594
592
  };
593
+
594
+ try {
595
+ const actionSubscription = safeNavigationListener(container, "__unsafe_action__", (event) => {
596
+ pendingNavigation = {
597
+ actionType: navigationActionType(event),
598
+ startedAtMs: nowMs(),
599
+ timestamp: now()
600
+ };
601
+ });
602
+ if (actionSubscription) {
603
+ removers.push(actionSubscription);
604
+ }
605
+ removers.push(addNavigationListener(container, "state", captureCurrentRoute));
606
+ if (captureInitialRoute) {
607
+ captureCurrentRoute();
608
+ }
609
+ } catch (error) {
610
+ try {
611
+ removeListeners();
612
+ } catch {
613
+ // Preserve the setup failure after attempting both listener removals.
614
+ }
615
+ throw error;
616
+ }
617
+ return removeListeners;
595
618
  }
596
619
 
597
620
  function createReactNativeErrorEvent(error, {
@@ -884,6 +907,10 @@ function recordIssueBreadcrumb(client, event, category, type) {
884
907
  ...(message === undefined ? {} : { message }),
885
908
  ...(status === undefined ? {} : { data: { status } })
886
909
  }, event.timestamp);
910
+ if (category === "navigation" && message !== undefined) {
911
+ // Global error reports keep the last route even after breadcrumb eviction.
912
+ client[LAST_ROUTE] = message;
913
+ }
887
914
  }
888
915
 
889
916
  function boundedBreadcrumbMessage(value) {
package/index.d.cts CHANGED
@@ -36,6 +36,7 @@ export type CreateLogBrewReactNativeClientConfig = {
36
36
  apiKey?: string;
37
37
  clientKey?: string;
38
38
  context?: TelemetryContext;
39
+ /** Automatic delivery interval in milliseconds. Defaults to 5000 on mobile to save battery. */
39
40
  deliveryIntervalMs?: number;
40
41
  deliveryQueueThreshold?: number;
41
42
  /** Advanced synchronous persistence seam. React Native apps normally use the native entry's persistentQueue mode. */
package/index.d.ts CHANGED
@@ -36,6 +36,7 @@ export type CreateLogBrewReactNativeClientConfig = {
36
36
  apiKey?: string;
37
37
  clientKey?: string;
38
38
  context?: TelemetryContext;
39
+ /** Automatic delivery interval in milliseconds. Defaults to 5000 on mobile to save battery. */
39
40
  deliveryIntervalMs?: number;
40
41
  deliveryQueueThreshold?: number;
41
42
  /** Advanced synchronous persistence seam. React Native apps normally use the native entry's persistentQueue mode. */