@logbrew/react-native 0.1.41 → 0.1.43
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.
- package/README.md +1 -1
- package/index.cjs +1 -1
- package/instrumentation-values.cjs +9 -1
- package/ios/AppleDiagnostics/LBRNAppleNativeDiagnostics.swift +1 -1
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngine.swift +1 -1
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngineAutomatic.swift +45 -12
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryLifecycle.swift +1 -1
- package/ios/GeneratedAppleDiagnostics/SOURCE-MANIFEST.json +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -860,7 +860,7 @@ await resourceFetch("https://api.example.com/graphql?email=hidden", {
|
|
|
860
860
|
});
|
|
861
861
|
```
|
|
862
862
|
|
|
863
|
-
`createReactNativeResourceFetch()` wraps the fetch function your app supplies, or the runtime `fetch` when available. It records status, method, duration, response-start timing, sanitized route template, screen, session, primitive metadata, response size when `Content-Length` is available, and trace correlation. `metadataFactory` is called after each fetch completes or fails so apps can add low-cardinality request metadata such as `graphqlOperationName` or `graphqlOperationType`; by default LogBrew does not parse GraphQL payloads. If you set `measureResponseBodySize: true`, LogBrew can fall back to measuring a cloned response body's byte length when the response omits `Content-Length`; it returns the original response untouched and does not store the response content. Metadata returned from the factory keeps only primitive values and drops sensitive request fields. It does not patch global `fetch` or XHR, inspect request or response bodies by default, capture arbitrary headers, or attach `traceparent` outside `tracePropagationTargets`. Pass `trace` explicitly after `await` boundaries or build the wrapper from provider/hook state so async resource spans stay correlated.
|
|
863
|
+
`createReactNativeResourceFetch()` wraps the fetch function your app supplies, or the runtime `fetch` when available. It records status, method, duration, response-start timing, sanitized route template, screen, session, primitive metadata, response size when `Content-Length` is available, and trace correlation. Without `routeTemplate` or `routeTemplateFactory`, the route template is the URL path with each numeric, UUID, or long hex (16 or more characters) segment replaced by `:id`, so `/orders/8412/items/77` becomes `/orders/:id/items/:id`. Pass `routeTemplateFactory: ({ url }) => name` to name requests yourself, or `routeTemplate` for one fixed name. `metadataFactory` is called after each fetch completes or fails so apps can add low-cardinality request metadata such as `graphqlOperationName` or `graphqlOperationType`; by default LogBrew does not parse GraphQL payloads. If you set `measureResponseBodySize: true`, LogBrew can fall back to measuring a cloned response body's byte length when the response omits `Content-Length`; it returns the original response untouched and does not store the response content. Metadata returned from the factory keeps only primitive values and drops sensitive request fields. It does not patch global `fetch` or XHR, inspect request or response bodies by default, capture arbitrary headers, or attach `traceparent` outside `tracePropagationTargets`. Pass `trace` explicitly after `await` boundaries or build the wrapper from provider/hook state so async resource spans stay correlated.
|
|
864
864
|
`createReactNativeGraphQLMetadataFactory()` is an explicit helper for GraphQL requests your app already owns. Pass `endpoint` as a route template, absolute URL without query/hash, `RegExp`, predicate, or an array of those when you use it with broader fetch/XHR instrumentation; LogBrew compares route templates and query-stripped URL paths before parsing. It reads only a JSON string request body to derive `graphqlOperationName` and `graphqlOperationType`, drops variables/query text/body fields, ignores large or non-JSON bodies, and can compose an existing primitive metadata factory. Do not use it on unrelated endpoints without an endpoint matcher.
|
|
865
865
|
|
|
866
866
|
If your app uses Apollo Client, use the optional Apollo subpath with the `ApolloLink` constructor your app already imports:
|
package/index.cjs
CHANGED
|
@@ -36,7 +36,7 @@ const { getReactNativeContext } = require("./index-values.cjs");
|
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
38
|
const DEFAULT_SDK_NAME = "logbrew-react-native";
|
|
39
|
-
const DEFAULT_SDK_VERSION = "0.1.
|
|
39
|
+
const DEFAULT_SDK_VERSION = "0.1.43";
|
|
40
40
|
const DEFAULT_REACT_NATIVE_DELIVERY_INTERVAL_MS = 1000;
|
|
41
41
|
const DEFAULT_MAX_RETRIES = 2;
|
|
42
42
|
|
|
@@ -253,13 +253,21 @@ function toText(value) {
|
|
|
253
253
|
return typeof value === "string" ? value : String(value);
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
+
const RECORD_ID_SEGMENT = /^(?:\d+|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|[0-9a-f]{16,})$/iu;
|
|
257
|
+
|
|
256
258
|
/**
|
|
259
|
+
* Names a request by its path with numeric, UUID, and long hex segments replaced by `:id`, so the
|
|
260
|
+
* name holds no record ID and stays low-cardinality.
|
|
257
261
|
* @param {{ readonly url: unknown }} context
|
|
258
262
|
* @returns {string}
|
|
259
263
|
*/
|
|
260
264
|
function defaultRouteTemplateFactory({ url }) {
|
|
261
265
|
const parsedUrl = parseUrl(url);
|
|
262
|
-
|
|
266
|
+
const pathname = parsedUrl === undefined ? stripQueryAndHash(toText(url)) : parsedUrl.pathname;
|
|
267
|
+
return pathname
|
|
268
|
+
.split("/")
|
|
269
|
+
.map((segment) => (RECORD_ID_SEGMENT.test(segment) ? ":id" : segment))
|
|
270
|
+
.join("/");
|
|
263
271
|
}
|
|
264
272
|
|
|
265
273
|
module.exports = {
|
|
@@ -3,7 +3,7 @@ import Foundation
|
|
|
3
3
|
@objc(LBRNAppleNativeDiagnostics)
|
|
4
4
|
public final class LBRNAppleNativeDiagnostics: NSObject, @unchecked Sendable {
|
|
5
5
|
private static let shared = LBRNAppleNativeDiagnostics()
|
|
6
|
-
private static let sdkVersion = "0.1.
|
|
6
|
+
private static let sdkVersion = "0.1.43"
|
|
7
7
|
|
|
8
8
|
private let lock = NSLock()
|
|
9
9
|
private let replayQueue = DispatchQueue(label: "co.logbrew.react-native.apple-diagnostics-replay")
|
|
@@ -106,7 +106,7 @@ final class DeliveryEngine: @unchecked Sendable {
|
|
|
106
106
|
consecutiveFailures: consecutiveFailures,
|
|
107
107
|
lastOutcome: lastOutcome,
|
|
108
108
|
pauseReason: pauseReason,
|
|
109
|
-
nextRetryDelay: state == .retrying ? nextWakeNanoseconds.map { deadline in
|
|
109
|
+
nextRetryDelay: state == .retrying || state == .paused ? nextWakeNanoseconds.map { deadline in
|
|
110
110
|
let now = DispatchTime.now().uptimeNanoseconds
|
|
111
111
|
return TimeInterval(deadline > now ? deadline - now : 0) / 1_000_000_000
|
|
112
112
|
} : nil,
|
|
@@ -15,7 +15,7 @@ extension DeliveryEngine {
|
|
|
15
15
|
return
|
|
16
16
|
}
|
|
17
17
|
nextWakeNanoseconds = nil
|
|
18
|
-
let active = automaticTransport != nil &&
|
|
18
|
+
let active = automaticTransport != nil && sendsAutomaticallyLocked
|
|
19
19
|
stateLock.unlock()
|
|
20
20
|
guard active else {
|
|
21
21
|
return
|
|
@@ -49,16 +49,22 @@ extension DeliveryEngine {
|
|
|
49
49
|
private func transportForAutomaticRun(generation currentGeneration: UInt64) -> (any Transport)? {
|
|
50
50
|
stateLock.lock()
|
|
51
51
|
defer { stateLock.unlock() }
|
|
52
|
-
guard generation == currentGeneration,
|
|
52
|
+
guard generation == currentGeneration, sendsAutomaticallyLocked else {
|
|
53
53
|
return nil
|
|
54
54
|
}
|
|
55
55
|
return automaticTransport
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/// Running and retrying deliveries send on their schedule; a paused one sends only its probe.
|
|
59
|
+
private var sendsAutomaticallyLocked: Bool {
|
|
60
|
+
state == .running || state == .retrying || (state == .paused && pauseReason != .storage)
|
|
61
|
+
}
|
|
62
|
+
|
|
58
63
|
private func finishEmptyAutomaticRun(generation currentGeneration: UInt64) {
|
|
59
64
|
stateLock.lock()
|
|
60
|
-
if generation == currentGeneration, state != .paused {
|
|
65
|
+
if generation == currentGeneration, state != .paused || pauseReason != .storage {
|
|
61
66
|
state = .running
|
|
67
|
+
pauseReason = .none
|
|
62
68
|
}
|
|
63
69
|
stateLock.unlock()
|
|
64
70
|
}
|
|
@@ -129,14 +135,13 @@ extension DeliveryEngine {
|
|
|
129
135
|
private func applyAutomaticResultLocked(_ result: AttemptResult, prefix: FrozenPrefix) -> Bool {
|
|
130
136
|
switch result {
|
|
131
137
|
case .accepted:
|
|
132
|
-
|
|
138
|
+
applyAcceptedResultLocked(prefix)
|
|
133
139
|
case .retryable:
|
|
134
|
-
|
|
140
|
+
applyRetryableResultLocked()
|
|
135
141
|
case let .terminal(reason, _, _):
|
|
136
142
|
applyTerminalResultLocked(reason: reason)
|
|
137
|
-
return false
|
|
138
143
|
case let .rateLimited(retryAfter, _, _):
|
|
139
|
-
|
|
144
|
+
applyRateLimitedResultLocked(retryAfter: retryAfter)
|
|
140
145
|
}
|
|
141
146
|
}
|
|
142
147
|
|
|
@@ -172,6 +177,7 @@ extension DeliveryEngine {
|
|
|
172
177
|
return false
|
|
173
178
|
}
|
|
174
179
|
state = .running
|
|
180
|
+
pauseReason = .none
|
|
175
181
|
return scheduleLiveQueueLocked()
|
|
176
182
|
}
|
|
177
183
|
|
|
@@ -184,20 +190,45 @@ extension DeliveryEngine {
|
|
|
184
190
|
guard retryAttempt < maxRetries else {
|
|
185
191
|
state = .paused
|
|
186
192
|
pauseReason = .retryExhausted
|
|
187
|
-
return
|
|
193
|
+
return schedulePauseProbeLocked()
|
|
188
194
|
}
|
|
189
195
|
retryAttempt += 1
|
|
190
196
|
state = .retrying
|
|
191
197
|
return scheduleRetryLocked()
|
|
192
198
|
}
|
|
193
199
|
|
|
194
|
-
private func applyTerminalResultLocked(reason: DeliveryPauseReason) {
|
|
200
|
+
private func applyTerminalResultLocked(reason: DeliveryPauseReason) -> Bool {
|
|
195
201
|
consecutiveFailures += 1
|
|
196
202
|
lastOutcome = .terminalFailure
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
pauseReason = reason
|
|
203
|
+
guard state != .shuttingDown else {
|
|
204
|
+
return false
|
|
200
205
|
}
|
|
206
|
+
state = .paused
|
|
207
|
+
pauseReason = reason
|
|
208
|
+
return schedulePauseProbeLocked()
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/// Schedules one resend of a paused delivery, so it resumes on its own once ingest accepts it again.
|
|
212
|
+
/// A storage pause waits for explicit recovery, because sending could lose or repeat durable data.
|
|
213
|
+
private func schedulePauseProbeLocked() -> Bool {
|
|
214
|
+
guard let options = automaticOptions, state == .paused, pauseReason != .storage else {
|
|
215
|
+
return false
|
|
216
|
+
}
|
|
217
|
+
nextWakeNanoseconds = nil
|
|
218
|
+
let delay = Self.pauseProbeDelay(maxRetryDelay: options.maxRetryDelay, failures: consecutiveFailures)
|
|
219
|
+
return setWakeLocked(delay: delay, replaceLaterWake: true)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/// Doubles from `maxRetryDelay` with each consecutive failure up to 5 minutes, or up to
|
|
223
|
+
/// `maxRetryDelay` when it is longer, then keeps half to all of that ceiling as jitter.
|
|
224
|
+
static func pauseProbeDelay(
|
|
225
|
+
maxRetryDelay: TimeInterval,
|
|
226
|
+
failures: Int,
|
|
227
|
+
jitter: Double = .random(in: 0 ... 1),
|
|
228
|
+
) -> TimeInterval {
|
|
229
|
+
let maximum = max(maxRetryDelay, 5 * 60)
|
|
230
|
+
let ceiling = min(maxRetryDelay * pow(2, Double(max(0, failures - 1))), maximum)
|
|
231
|
+
return ceiling / 2 + ceiling / 2 * jitter
|
|
201
232
|
}
|
|
202
233
|
|
|
203
234
|
func scheduleCaptureLocked() -> Bool {
|
|
@@ -279,6 +310,8 @@ extension DeliveryEngine {
|
|
|
279
310
|
let shouldSchedule: Bool
|
|
280
311
|
if state == .retrying, nextWakeNanoseconds != nil {
|
|
281
312
|
shouldSchedule = true
|
|
313
|
+
} else if state == .paused, pauseReason != .storage {
|
|
314
|
+
shouldSchedule = schedulePauseProbeLocked()
|
|
282
315
|
} else if automaticTransport != nil, state != .paused, state != .shuttingDown, state != .closed {
|
|
283
316
|
state = .running
|
|
284
317
|
retryAttempt = 0
|
|
@@ -67,6 +67,6 @@ public struct DeliveryHealth: Codable, Equatable, Sendable {
|
|
|
67
67
|
public let consecutiveFailures: Int
|
|
68
68
|
public let lastOutcome: DeliveryOutcome
|
|
69
69
|
public let pauseReason: DeliveryPauseReason
|
|
70
|
-
/// Seconds until the scheduled automatic retry, or `nil` when
|
|
70
|
+
/// Seconds until the scheduled automatic retry or paused-delivery probe, or `nil` when none is scheduled.
|
|
71
71
|
public let nextRetryDelay: TimeInterval?
|
|
72
72
|
}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"sources": {
|
|
4
4
|
"swift/logbrew-swift/Sources/LogBrew/AutomaticTelemetryContext.swift": "76ab7f8a7c79db1d54ba13da8d61d96af62c509116b7df0f9d220d5c88364c00",
|
|
5
|
-
"swift/logbrew-swift/Sources/LogBrew/DeliveryEngine.swift": "
|
|
6
|
-
"swift/logbrew-swift/Sources/LogBrew/DeliveryEngineAutomatic.swift": "
|
|
5
|
+
"swift/logbrew-swift/Sources/LogBrew/DeliveryEngine.swift": "274ca2ed671add1f7c51494e2a4e254b0fecd6fd7d80321ee0836e3521c2b02b",
|
|
6
|
+
"swift/logbrew-swift/Sources/LogBrew/DeliveryEngineAutomatic.swift": "d261e2364edffe82ccb7e962f12e6864a0077d41204e0b021c8160635cc843b2",
|
|
7
7
|
"swift/logbrew-swift/Sources/LogBrew/DeliveryEngineDurable.swift": "b0d2ca07cce7fe01fc110238c7d10aa9c8ada0d28509e4c022e7fa950a4c79b9",
|
|
8
8
|
"swift/logbrew-swift/Sources/LogBrew/DeliveryEngineQueue.swift": "e187a737e18dd88a4be8719f1a3a07776c6d6eb0edb5b1904a82c5059a0aef57",
|
|
9
|
-
"swift/logbrew-swift/Sources/LogBrew/DeliveryLifecycle.swift": "
|
|
9
|
+
"swift/logbrew-swift/Sources/LogBrew/DeliveryLifecycle.swift": "48cc8d89bbdcdff2f73a188d4824b03c3614cade8e3e3a85a710eaf827f6c413",
|
|
10
10
|
"swift/logbrew-swift/Sources/LogBrew/DurableDeliveryStore.swift": "7c292dda68efc3de790daf44733b25e4392226793343c21ba5df4f51fc1b402b",
|
|
11
11
|
"swift/logbrew-swift/Sources/LogBrew/DurableDeliveryStoreRecovery.swift": "79fee27975b6571954bf0b3692a50e60bbbcf53b5ab47f653a474db5c56d68ba",
|
|
12
12
|
"swift/logbrew-swift/Sources/LogBrew/EventEncoding.swift": "b88b6b2d17f7d0cee9ac1a1f34ef35b192cd33d213ef3c9e1c2d21cbcc304a97",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logbrew/react-native",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.43",
|
|
4
4
|
"description": "React Native offline delivery, native diagnostics, screen, error, trace, action, and network timeline helpers for LogBrew.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.cjs",
|