@logbrew/react-native 0.1.44 → 0.1.46
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 +26 -0
- package/android/src/main/java/co/logbrew/reactnative/FatalStoreModuleImpl.java +14 -0
- package/android/src/newarch/java/co/logbrew/reactnative/FatalStoreModule.java +5 -0
- package/android/src/oldarch/java/co/logbrew/reactnative/FatalStoreModule.java +5 -0
- package/app-start.js +67 -0
- package/index.cjs +1 -1
- package/index.native.d.ts +7 -1
- package/index.native.js +7 -1
- package/ios/AppleDiagnostics/LBRNAppleNativeDiagnostics.swift +1 -1
- package/ios/LBRNFatalStoreModule.mm +17 -0
- package/package.json +4 -2
- package/src/NativeLogBrewFatalStore.ts +1 -0
package/README.md
CHANGED
|
@@ -91,6 +91,32 @@ sends after authentication, usage-limit, or non-retryable failures. Do not add a
|
|
|
91
91
|
Helpers generate a fresh opaque event ID by default. Explicit `id` and
|
|
92
92
|
`idFactory` values remain available for app-owned idempotency.
|
|
93
93
|
|
|
94
|
+
### App Start Metric
|
|
95
|
+
|
|
96
|
+
The React Native client sends one cold start metric per process. You do not
|
|
97
|
+
need extra app code. The metric has these values:
|
|
98
|
+
|
|
99
|
+
- `name`: `app.start.duration`
|
|
100
|
+
- `kind`: `histogram`, with `temporality` `delta`
|
|
101
|
+
- `unit`: `ms`
|
|
102
|
+
- `value`: the time from process start to the first frame after the package
|
|
103
|
+
loads
|
|
104
|
+
- `metadata`: `{ startType: "cold" }`
|
|
105
|
+
|
|
106
|
+
The process start time comes from the linked native module, so the metric
|
|
107
|
+
needs a development build or a bare app. Expo Go sends no metric. The metric
|
|
108
|
+
is not sent for iOS prewarmed launches or for values above 60 seconds.
|
|
109
|
+
Import the package and create the client in your app entry file, before the
|
|
110
|
+
first screen renders. To turn the metric off, set `captureAppStart: false`:
|
|
111
|
+
|
|
112
|
+
```js
|
|
113
|
+
const client = createLogBrewReactNativeClient({
|
|
114
|
+
clientKey,
|
|
115
|
+
captureAppStart: false,
|
|
116
|
+
transport: createReactNativeFetchTransport()
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
94
120
|
## Confirm Hosted Delivery And Event Visibility
|
|
95
121
|
|
|
96
122
|
Call `verifyLogBrewSetup()` once from a development-only button or setup
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
package co.logbrew.reactnative;
|
|
2
2
|
|
|
3
|
+
import android.os.Build;
|
|
4
|
+
import android.os.Process;
|
|
5
|
+
import android.os.SystemClock;
|
|
3
6
|
import com.facebook.react.bridge.Arguments;
|
|
4
7
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
5
8
|
import com.facebook.react.bridge.ReadableArray;
|
|
@@ -46,6 +49,17 @@ final class FatalStoreModuleImpl {
|
|
|
46
49
|
eventStoreParent = root;
|
|
47
50
|
}
|
|
48
51
|
|
|
52
|
+
double processStartTime() {
|
|
53
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
long startedAt =
|
|
57
|
+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
|
|
58
|
+
? Process.getStartRequestedElapsedRealtime()
|
|
59
|
+
: Process.getStartElapsedRealtime();
|
|
60
|
+
return System.currentTimeMillis() - (SystemClock.elapsedRealtime() - startedAt);
|
|
61
|
+
}
|
|
62
|
+
|
|
49
63
|
String secureRandomHex(double length) {
|
|
50
64
|
Integer byteCount = integer(length);
|
|
51
65
|
if (byteCount == null || byteCount < 1 || byteCount > 64) {
|
|
@@ -18,6 +18,11 @@ final class FatalStoreModule extends NativeLogBrewFatalStoreSpec {
|
|
|
18
18
|
return FatalStoreModuleImpl.NAME;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
@Override
|
|
22
|
+
public double processStartTime() {
|
|
23
|
+
return implementation.processStartTime();
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
@Override
|
|
22
27
|
public String secureRandomHex(double length) {
|
|
23
28
|
return implementation.secureRandomHex(length);
|
|
@@ -20,6 +20,11 @@ final class FatalStoreModule extends ReactContextBaseJavaModule {
|
|
|
20
20
|
return FatalStoreModuleImpl.NAME;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
24
|
+
public double processStartTime() {
|
|
25
|
+
return implementation.processStartTime();
|
|
26
|
+
}
|
|
27
|
+
|
|
23
28
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
24
29
|
public String secureRandomHex(double length) {
|
|
25
30
|
return implementation.secureRandomHex(length);
|
package/app-start.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import random from "./index-random.cjs";
|
|
2
|
+
import { readField } from "./native-diagnostics-values.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @import { LogBrewClient } from "@logbrew/sdk"
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const MAX_APP_START_MS = 60_000;
|
|
9
|
+
|
|
10
|
+
/** @type {Promise<number>} */
|
|
11
|
+
const firstFrameAt = new Promise((resolve) => {
|
|
12
|
+
const markFrame = () => {
|
|
13
|
+
resolve(Date.now());
|
|
14
|
+
};
|
|
15
|
+
const requestFrame = readField(globalThis, "requestAnimationFrame");
|
|
16
|
+
if (typeof requestFrame === "function") {
|
|
17
|
+
Reflect.apply(requestFrame, globalThis, [markFrame]);
|
|
18
|
+
} else {
|
|
19
|
+
setTimeout(markFrame, 0);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
let claimed = false;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {LogBrewClient} client
|
|
26
|
+
* @param {unknown} nativeRuntime
|
|
27
|
+
* @param {number} frameAt
|
|
28
|
+
*/
|
|
29
|
+
function sendAppStartMetric(client, nativeRuntime, frameAt) {
|
|
30
|
+
const processStartTime = readField(nativeRuntime, "processStartTime");
|
|
31
|
+
/** @type {unknown} */
|
|
32
|
+
const startedAt = typeof processStartTime === "function" ? Reflect.apply(processStartTime, nativeRuntime, []) : undefined;
|
|
33
|
+
if (typeof startedAt !== "number" || startedAt <= 0) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const durationMs = frameAt - startedAt;
|
|
37
|
+
if (!(durationMs >= 0 && durationMs <= MAX_APP_START_MS)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
client.metric(random.defaultEventId("app_start"), new Date(frameAt).toISOString(), {
|
|
41
|
+
name: "app.start.duration",
|
|
42
|
+
description: "Time from process start to the first frame.",
|
|
43
|
+
kind: "histogram",
|
|
44
|
+
value: durationMs,
|
|
45
|
+
unit: "ms",
|
|
46
|
+
temporality: "delta",
|
|
47
|
+
metadata: { startType: "cold" }
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Sends one cold start metric per process after the first frame.
|
|
53
|
+
*
|
|
54
|
+
* @param {LogBrewClient} client
|
|
55
|
+
* @param {unknown} nativeRuntime
|
|
56
|
+
*/
|
|
57
|
+
function captureAppStart(client, nativeRuntime) {
|
|
58
|
+
if (claimed) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
claimed = true;
|
|
62
|
+
firstFrameAt.then((frameAt) => {
|
|
63
|
+
sendAppStartMetric(client, nativeRuntime, frameAt);
|
|
64
|
+
}).catch(() => undefined);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { captureAppStart };
|
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.46";
|
|
40
40
|
const DEFAULT_REACT_NATIVE_DELIVERY_INTERVAL_MS = 1000;
|
|
41
41
|
const DEFAULT_MAX_RETRIES = 2;
|
|
42
42
|
|
package/index.native.d.ts
CHANGED
|
@@ -25,7 +25,13 @@ import type indexDefault from "./index.js";
|
|
|
25
25
|
type ReactNativePersistentQueueMode = "auto" | "required" | "disabled";
|
|
26
26
|
|
|
27
27
|
type CreateNativeLogBrewReactNativeClientConfig =
|
|
28
|
-
Omit<CreateLogBrewReactNativeClientConfig, "eventStore"> &
|
|
28
|
+
Omit<CreateLogBrewReactNativeClientConfig, "eventStore"> & {
|
|
29
|
+
/**
|
|
30
|
+
* Sends one `app.start.duration` metric per process: milliseconds from process start
|
|
31
|
+
* to the first frame. Defaults to `true`. Set `false` to turn it off.
|
|
32
|
+
*/
|
|
33
|
+
captureAppStart?: boolean;
|
|
34
|
+
} & ({
|
|
29
35
|
/**
|
|
30
36
|
* `auto` uses the linked app-private native queue when available and otherwise uses memory.
|
|
31
37
|
* `required` fails client creation when the native queue is unavailable. `disabled` uses memory.
|
package/index.native.js
CHANGED
|
@@ -9,6 +9,7 @@ import baseDefault, {
|
|
|
9
9
|
createLogBrewReactNativeClient as createPlatformNeutralClient,
|
|
10
10
|
getReactNativeContext
|
|
11
11
|
} from "./index.js";
|
|
12
|
+
import { captureAppStart } from "./app-start.js";
|
|
12
13
|
import { bindAndroidNativeDelivery, bindAppleNativeCrashBreadcrumbs } from "./native-client-bindings.js";
|
|
13
14
|
import {
|
|
14
15
|
getLogBrewAndroidNativeDiagnosticsStatus,
|
|
@@ -87,6 +88,7 @@ function createLogBrewReactNativeClient(config = {}) {
|
|
|
87
88
|
const input = isObjectInput(config) ? config : {};
|
|
88
89
|
const {
|
|
89
90
|
apiKey,
|
|
91
|
+
captureAppStart: shouldCaptureAppStart = true,
|
|
90
92
|
clientKey,
|
|
91
93
|
eventStore,
|
|
92
94
|
maxQueueBytes,
|
|
@@ -107,7 +109,11 @@ function createLogBrewReactNativeClient(config = {}) {
|
|
|
107
109
|
maxQueueSize,
|
|
108
110
|
persistentQueue
|
|
109
111
|
});
|
|
110
|
-
|
|
112
|
+
const client = createResolvedClient({ ...forwarded, apiKey, clientKey, maxQueueBytes, maxQueueSize }, resolved);
|
|
113
|
+
if (shouldCaptureAppStart !== false) {
|
|
114
|
+
captureAppStart(client, nativeRuntime);
|
|
115
|
+
}
|
|
116
|
+
return client;
|
|
111
117
|
}
|
|
112
118
|
|
|
113
119
|
/**
|
|
@@ -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.46"
|
|
7
7
|
|
|
8
8
|
private let lock = NSLock()
|
|
9
9
|
private let replayQueue = DispatchQueue(label: "co.logbrew.react-native.apple-diagnostics-replay")
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
#import <Security/SecRandom.h>
|
|
8
8
|
#import <TargetConditionals.h>
|
|
9
9
|
#import <math.h>
|
|
10
|
+
#import <sys/sysctl.h>
|
|
11
|
+
#import <unistd.h>
|
|
10
12
|
|
|
11
13
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
12
14
|
#import <LogBrewReactNativeSpec/LogBrewReactNativeSpec.h>
|
|
@@ -111,6 +113,21 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(secureRandomHex:(double)length)
|
|
|
111
113
|
return output;
|
|
112
114
|
}
|
|
113
115
|
|
|
116
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(processStartTime)
|
|
117
|
+
{
|
|
118
|
+
if ([NSProcessInfo.processInfo.environment[@"ActivePrewarm"] isEqualToString:@"1"]) {
|
|
119
|
+
return @0;
|
|
120
|
+
}
|
|
121
|
+
struct kinfo_proc process;
|
|
122
|
+
size_t size = sizeof(process);
|
|
123
|
+
int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
|
|
124
|
+
if (sysctl(name, 4, &process, &size, NULL, 0) != 0 || size == 0) {
|
|
125
|
+
return @0;
|
|
126
|
+
}
|
|
127
|
+
struct timeval startedAt = process.kp_proc.p_starttime;
|
|
128
|
+
return @((double)startedAt.tv_sec * 1000.0 + (double)startedAt.tv_usec / 1000.0);
|
|
129
|
+
}
|
|
130
|
+
|
|
114
131
|
- (nullable LBRNEventRecordStore *)eventStoreForQueueKey:(NSString *)queueKey
|
|
115
132
|
{
|
|
116
133
|
NSString *queueHash = LBRNQueueHash(queueKey);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logbrew/react-native",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.46",
|
|
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",
|
|
@@ -235,6 +235,7 @@
|
|
|
235
235
|
"apple-native-diagnostics-module.js",
|
|
236
236
|
"apple-native-diagnostics.d.ts",
|
|
237
237
|
"android-native-diagnostics.js",
|
|
238
|
+
"app-start.js",
|
|
238
239
|
"native-client-bindings.js",
|
|
239
240
|
"native-diagnostics-values.js",
|
|
240
241
|
"native-module-lookup.js",
|
|
@@ -289,6 +290,7 @@
|
|
|
289
290
|
"node": ">=18"
|
|
290
291
|
},
|
|
291
292
|
"license": "MIT",
|
|
293
|
+
"homepage": "https://logbrew.co",
|
|
292
294
|
"repository": {
|
|
293
295
|
"type": "git",
|
|
294
296
|
"url": "git+https://github.com/LogBrewCo/sdk.git"
|
|
@@ -305,6 +307,6 @@
|
|
|
305
307
|
}
|
|
306
308
|
},
|
|
307
309
|
"scripts": {
|
|
308
|
-
"test": "node scripts/sync-apple-native-sources.mjs --check && node --check index.js && node --check index.cjs && node --check index.native.js && node --check apple-native-diagnostics.js && node --check android-native-diagnostics.js && node --check expo.js && node --check expo.cjs && node --check apollo.js && node --check apollo.cjs && node --check instrumentation.js && node --check instrumentation.cjs && node --check lifecycle.js && node --check lifecycle.cjs && node --check global-errors.js && node --check global-errors.native.js && node --check global-errors.cjs && node --check promise-rejections.cjs && node --check fatal-replay.cjs && node --check metadata.js && node --check metadata.cjs && node --check native-bridge.js && node --check native-bridge.cjs && node --check resource-fetch.js && node --check resource-fetch.cjs && node --check release-artifacts.js && node --check release-artifacts.cjs && node --check metro.js && node --check metro.cjs && node --check examples/index.mjs && node --check examples/apollo-link-spans.mjs && node --check examples/instrumentation-kit.mjs && node --check examples/lifecycle-spans.mjs && node --check examples/native-bridge-scope.mjs && node --check examples/navigation-resource-spans.mjs && node --check examples/readme-example.mjs && node --check examples/real-user-smoke.mjs && node --check examples/resource-fetch-spans.mjs && node --check examples/trace-correlation.mjs && node --test"
|
|
310
|
+
"test": "node scripts/sync-apple-native-sources.mjs --check && node --check index.js && node --check index.cjs && node --check index.native.js && node --check app-start.js && node --check apple-native-diagnostics.js && node --check android-native-diagnostics.js && node --check expo.js && node --check expo.cjs && node --check apollo.js && node --check apollo.cjs && node --check instrumentation.js && node --check instrumentation.cjs && node --check lifecycle.js && node --check lifecycle.cjs && node --check global-errors.js && node --check global-errors.native.js && node --check global-errors.cjs && node --check promise-rejections.cjs && node --check fatal-replay.cjs && node --check metadata.js && node --check metadata.cjs && node --check native-bridge.js && node --check native-bridge.cjs && node --check resource-fetch.js && node --check resource-fetch.cjs && node --check release-artifacts.js && node --check release-artifacts.cjs && node --check metro.js && node --check metro.cjs && node --check examples/index.mjs && node --check examples/apollo-link-spans.mjs && node --check examples/instrumentation-kit.mjs && node --check examples/lifecycle-spans.mjs && node --check examples/native-bridge-scope.mjs && node --check examples/navigation-resource-spans.mjs && node --check examples/readme-example.mjs && node --check examples/real-user-smoke.mjs && node --check examples/resource-fetch-spans.mjs && node --check examples/trace-correlation.mjs && node --test"
|
|
309
311
|
}
|
|
310
312
|
}
|
|
@@ -3,6 +3,7 @@ import { TurboModuleRegistry } from "react-native";
|
|
|
3
3
|
|
|
4
4
|
export interface Spec extends TurboModule {
|
|
5
5
|
secureRandomHex(length: number): string;
|
|
6
|
+
processStartTime(): number;
|
|
6
7
|
loadEventRecords(queueKey: string): CodegenTypes.UnsafeObject;
|
|
7
8
|
appendEventRecord(
|
|
8
9
|
queueKey: string,
|