@logbrew/react-native 0.1.43 → 0.1.44
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/index.cjs +1 -1
- package/ios/AppleDiagnostics/LBRNAppleNativeDiagnostics.swift +2 -1
- package/ios/GeneratedAppleDiagnostics/LogBrew/AppStartMetric.swift +117 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/LogBrewClient.swift +16 -1
- package/ios/GeneratedAppleDiagnostics/LogBrew/PublicTypes.swift +3 -0
- package/ios/GeneratedAppleDiagnostics/SOURCE-MANIFEST.json +3 -2
- package/package.json +1 -1
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.44";
|
|
40
40
|
const DEFAULT_REACT_NATIVE_DELIVERY_INTERVAL_MS = 1000;
|
|
41
41
|
const DEFAULT_MAX_RETRIES = 2;
|
|
42
42
|
|
|
@@ -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.44"
|
|
7
7
|
|
|
8
8
|
private let lock = NSLock()
|
|
9
9
|
private let replayQueue = DispatchQueue(label: "co.logbrew.react-native.apple-diagnostics-replay")
|
|
@@ -87,6 +87,7 @@ public final class LBRNAppleNativeDiagnostics: NSObject, @unchecked Sendable {
|
|
|
87
87
|
apiKey: configuration.apiKey,
|
|
88
88
|
sdkName: "logbrew-react-native-apple",
|
|
89
89
|
sdkVersion: Self.sdkVersion,
|
|
90
|
+
includeAppStartMetric: false,
|
|
90
91
|
)
|
|
91
92
|
let transport = try HTTPTransport(endpoint: configuration.endpoint)
|
|
92
93
|
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Generated by scripts/sync-apple-native-sources.mjs.
|
|
2
|
+
// Edit the canonical Swift source, then regenerate this package boundary.
|
|
3
|
+
import Foundation
|
|
4
|
+
|
|
5
|
+
struct AppStartSource: Sendable {
|
|
6
|
+
let processStartMs: Double?
|
|
7
|
+
let isPrewarmed: Bool
|
|
8
|
+
let firstFrameNotification: Notification.Name?
|
|
9
|
+
let notificationCenter: NotificationCenter
|
|
10
|
+
let nowMs: @Sendable () -> Double
|
|
11
|
+
|
|
12
|
+
static let current = AppStartSource(
|
|
13
|
+
processStartMs: kernelProcessStartMs(),
|
|
14
|
+
isPrewarmed: ProcessInfo.processInfo.environment["ActivePrewarm"] == "1",
|
|
15
|
+
firstFrameNotification: platformFirstFrameNotification(),
|
|
16
|
+
notificationCenter: .default,
|
|
17
|
+
nowMs: { Date().timeIntervalSince1970 * 1000 },
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
final class AppStartRecorder: @unchecked Sendable {
|
|
22
|
+
static let process = AppStartRecorder(source: .current)
|
|
23
|
+
|
|
24
|
+
let source: AppStartSource
|
|
25
|
+
private let lock = NSLock()
|
|
26
|
+
private var finished: Bool
|
|
27
|
+
private var observer: (any NSObjectProtocol)?
|
|
28
|
+
private weak var client: LogBrewClient?
|
|
29
|
+
|
|
30
|
+
init(source: AppStartSource) {
|
|
31
|
+
self.source = source
|
|
32
|
+
finished = source.isPrewarmed || source.processStartMs == nil
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
func install(for client: LogBrewClient) {
|
|
36
|
+
guard let name = source.firstFrameNotification else {
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
lock.lock()
|
|
40
|
+
defer {
|
|
41
|
+
lock.unlock()
|
|
42
|
+
}
|
|
43
|
+
guard !finished, observer == nil else {
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
self.client = client
|
|
47
|
+
observer = source.notificationCenter.addObserver(forName: name, object: nil, queue: .main) { [weak self] _ in
|
|
48
|
+
DispatchQueue.main.async {
|
|
49
|
+
self?.finish(client: nil)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@discardableResult
|
|
55
|
+
func finish(client explicitClient: LogBrewClient?) -> Bool {
|
|
56
|
+
let endMs = source.nowMs()
|
|
57
|
+
lock.lock()
|
|
58
|
+
guard !finished, let startMs = source.processStartMs else {
|
|
59
|
+
lock.unlock()
|
|
60
|
+
return false
|
|
61
|
+
}
|
|
62
|
+
finished = true
|
|
63
|
+
let target = explicitClient ?? client
|
|
64
|
+
let registeredObserver = observer
|
|
65
|
+
observer = nil
|
|
66
|
+
client = nil
|
|
67
|
+
lock.unlock()
|
|
68
|
+
if let registeredObserver {
|
|
69
|
+
source.notificationCenter.removeObserver(registeredObserver)
|
|
70
|
+
}
|
|
71
|
+
let durationMs = endMs - startMs
|
|
72
|
+
guard let target, durationMs >= 0, durationMs <= 60000 else {
|
|
73
|
+
return false
|
|
74
|
+
}
|
|
75
|
+
let eventID = "evt_app_start_\(UUID().uuidString.replacingOccurrences(of: "-", with: "").lowercased())"
|
|
76
|
+
return (try? target.metric(
|
|
77
|
+
eventID,
|
|
78
|
+
timestamp: currentTelemetryTimestamp(),
|
|
79
|
+
attributes: MetricAttributes(
|
|
80
|
+
name: "app.start.duration",
|
|
81
|
+
kind: .histogram,
|
|
82
|
+
value: durationMs,
|
|
83
|
+
unit: "ms",
|
|
84
|
+
temporality: .delta,
|
|
85
|
+
metadata: ["startType": "cold"],
|
|
86
|
+
description: "Time from process start to the first frame.",
|
|
87
|
+
),
|
|
88
|
+
)) != nil
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private func platformFirstFrameNotification() -> Notification.Name? {
|
|
93
|
+
#if os(iOS) || os(tvOS) || os(visionOS)
|
|
94
|
+
Notification.Name("UIApplicationDidBecomeActiveNotification")
|
|
95
|
+
#elseif os(watchOS)
|
|
96
|
+
Notification.Name("WKApplicationDidBecomeActiveNotification")
|
|
97
|
+
#elseif os(macOS)
|
|
98
|
+
Notification.Name("NSApplicationDidFinishLaunchingNotification")
|
|
99
|
+
#else
|
|
100
|
+
nil
|
|
101
|
+
#endif
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private func kernelProcessStartMs() -> Double? {
|
|
105
|
+
#if canImport(Darwin)
|
|
106
|
+
var information = kinfo_proc()
|
|
107
|
+
var size = MemoryLayout<kinfo_proc>.stride
|
|
108
|
+
var mib: [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
|
|
109
|
+
guard sysctl(&mib, u_int(mib.count), &information, &size, nil, 0) == 0 else {
|
|
110
|
+
return nil
|
|
111
|
+
}
|
|
112
|
+
let start = information.kp_proc.p_un.__p_starttime
|
|
113
|
+
return Double(start.tv_sec) * 1000 + Double(start.tv_usec) / 1000
|
|
114
|
+
#else
|
|
115
|
+
nil
|
|
116
|
+
#endif
|
|
117
|
+
}
|
|
@@ -6,6 +6,7 @@ public final class LogBrewClient: @unchecked Sendable {
|
|
|
6
6
|
private let engine: DeliveryEngine
|
|
7
7
|
private let baseContext: TelemetryContext?
|
|
8
8
|
private let breadcrumbStore = IssueBreadcrumbStore()
|
|
9
|
+
private let appStart: AppStartRecorder?
|
|
9
10
|
|
|
10
11
|
public static func create(
|
|
11
12
|
apiKey: String,
|
|
@@ -14,6 +15,7 @@ public final class LogBrewClient: @unchecked Sendable {
|
|
|
14
15
|
maxRetries: Int = 2,
|
|
15
16
|
context: TelemetryContext? = nil,
|
|
16
17
|
includeAutomaticContext: Bool = true,
|
|
18
|
+
includeAppStartMetric: Bool = true,
|
|
17
19
|
) throws -> LogBrewClient {
|
|
18
20
|
try LogBrewClient(
|
|
19
21
|
config: ClientConfig(
|
|
@@ -23,11 +25,16 @@ public final class LogBrewClient: @unchecked Sendable {
|
|
|
23
25
|
maxRetries: maxRetries,
|
|
24
26
|
context: context,
|
|
25
27
|
includeAutomaticContext: includeAutomaticContext,
|
|
28
|
+
includeAppStartMetric: includeAppStartMetric,
|
|
26
29
|
),
|
|
27
30
|
)
|
|
28
31
|
}
|
|
29
32
|
|
|
30
|
-
public init(config: ClientConfig) throws {
|
|
33
|
+
public convenience init(config: ClientConfig) throws {
|
|
34
|
+
try self.init(config: config, appStart: .process)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
init(config: ClientConfig, appStart: AppStartRecorder) throws {
|
|
31
38
|
try requireNonEmpty("api_key", config.apiKey)
|
|
32
39
|
try requireNonEmpty("sdk_name", config.sdkName)
|
|
33
40
|
try requireNonEmpty("sdk_version", config.sdkVersion)
|
|
@@ -40,6 +47,14 @@ public final class LogBrewClient: @unchecked Sendable {
|
|
|
40
47
|
sdk: SDKInfo(name: config.sdkName, language: "swift", version: config.sdkVersion),
|
|
41
48
|
maxRetries: config.maxRetries,
|
|
42
49
|
)
|
|
50
|
+
self.appStart = config.includeAppStartMetric ? appStart : nil
|
|
51
|
+
self.appStart?.install(for: self)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/// End the cold start measurement now if the first frame has not ended it yet.
|
|
55
|
+
@discardableResult
|
|
56
|
+
public func markAppReady() -> Bool {
|
|
57
|
+
appStart?.finish(client: self) ?? false
|
|
43
58
|
}
|
|
44
59
|
|
|
45
60
|
public func pendingEvents() -> Int {
|
|
@@ -107,6 +107,7 @@ public struct ClientConfig: Equatable, Sendable {
|
|
|
107
107
|
public let maxRetries: Int
|
|
108
108
|
public let context: TelemetryContext?
|
|
109
109
|
public let includeAutomaticContext: Bool
|
|
110
|
+
public let includeAppStartMetric: Bool
|
|
110
111
|
|
|
111
112
|
public init(
|
|
112
113
|
apiKey: String,
|
|
@@ -115,6 +116,7 @@ public struct ClientConfig: Equatable, Sendable {
|
|
|
115
116
|
maxRetries: Int = 2,
|
|
116
117
|
context: TelemetryContext? = nil,
|
|
117
118
|
includeAutomaticContext: Bool = true,
|
|
119
|
+
includeAppStartMetric: Bool = true,
|
|
118
120
|
) {
|
|
119
121
|
self.apiKey = apiKey
|
|
120
122
|
self.sdkName = sdkName
|
|
@@ -122,6 +124,7 @@ public struct ClientConfig: Equatable, Sendable {
|
|
|
122
124
|
self.maxRetries = maxRetries
|
|
123
125
|
self.context = context
|
|
124
126
|
self.includeAutomaticContext = includeAutomaticContext
|
|
127
|
+
self.includeAppStartMetric = includeAppStartMetric
|
|
125
128
|
}
|
|
126
129
|
}
|
|
127
130
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"sources": {
|
|
4
|
+
"swift/logbrew-swift/Sources/LogBrew/AppStartMetric.swift": "00ad61c062366b68674a5cccc9940dfbe83827e80b00b74648c215c082987d9f",
|
|
4
5
|
"swift/logbrew-swift/Sources/LogBrew/AutomaticTelemetryContext.swift": "76ab7f8a7c79db1d54ba13da8d61d96af62c509116b7df0f9d220d5c88364c00",
|
|
5
6
|
"swift/logbrew-swift/Sources/LogBrew/DeliveryEngine.swift": "274ca2ed671add1f7c51494e2a4e254b0fecd6fd7d80321ee0836e3521c2b02b",
|
|
6
7
|
"swift/logbrew-swift/Sources/LogBrew/DeliveryEngineAutomatic.swift": "d261e2364edffe82ccb7e962f12e6864a0077d41204e0b021c8160635cc843b2",
|
|
@@ -14,14 +15,14 @@
|
|
|
14
15
|
"swift/logbrew-swift/Sources/LogBrew/IssueDiagnostics.swift": "bbdfe6169961ff27b8f2cee63c7dcdeacf2e5cee6a3ca17f6a26b933f0adfc39",
|
|
15
16
|
"swift/logbrew-swift/Sources/LogBrew/IssueExceptionChain.swift": "10f81cbce95b47da0a44ef9e515b150e60d71dfcc8b04be24b037b1222a373a5",
|
|
16
17
|
"swift/logbrew-swift/Sources/LogBrew/LifecycleTrace.swift": "738cd3f129fac821a892404d1d42ee92bd806b6583d3dbb5379e88b14ab23c16",
|
|
17
|
-
"swift/logbrew-swift/Sources/LogBrew/LogBrewClient.swift": "
|
|
18
|
+
"swift/logbrew-swift/Sources/LogBrew/LogBrewClient.swift": "1dd933fcb4e889694ef29a120edbc942b27dfb72adc37fa35473c110c473180b",
|
|
18
19
|
"swift/logbrew-swift/Sources/LogBrew/LogBrewLogger.swift": "96e440f411c6276056e10c5feca82eb24fce9824632c7dbcedfd99b49d8332fc",
|
|
19
20
|
"swift/logbrew-swift/Sources/LogBrew/LogBrewTrace.swift": "f67edf4ca464e6a6eb1c7a22cd4997928cd27b6c2d07535855a18a053d8de924",
|
|
20
21
|
"swift/logbrew-swift/Sources/LogBrew/Metadata.swift": "65840ebb3f3b79fbfc1f5faa3026c2583319e89ff26061676dc552c03ee15dbe",
|
|
21
22
|
"swift/logbrew-swift/Sources/LogBrew/NativeStackFrame.swift": "ecbd418969ec4a31503d9916a8bf27f22e6863356c6fabe457c1e61027a8d805",
|
|
22
23
|
"swift/logbrew-swift/Sources/LogBrew/OperationTrace.swift": "d7383d1926c7276cc97f03537e4587e20e4495f80226b5113e8ef10397f9c702",
|
|
23
24
|
"swift/logbrew-swift/Sources/LogBrew/ProductTimeline.swift": "209906aa0e8f096a347e35832840522710eadfb530053253cd73c748518e362d",
|
|
24
|
-
"swift/logbrew-swift/Sources/LogBrew/PublicTypes.swift": "
|
|
25
|
+
"swift/logbrew-swift/Sources/LogBrew/PublicTypes.swift": "ab1831ae31dea4504bc756fce0b83e41aeec2cbe4da62cfc2ce45c0deea85b3f",
|
|
25
26
|
"swift/logbrew-swift/Sources/LogBrew/TelemetryContext.swift": "ce3ac93a62a345f8c9a8f4c69ce84efc991bf02a688f49bad5e68edcff2f6e08",
|
|
26
27
|
"swift/logbrew-swift/Sources/LogBrew/TelemetryContextValidation.swift": "ab5811b48df308bf8f6435efee30a24f91a62bfe8b6dea612a2077c8ae0eb302",
|
|
27
28
|
"swift/logbrew-swift/Sources/LogBrew/TraceEvidence.swift": "40aaa42976164c53d9f4d9e9e30d236534238da43bbe90832a673c8809ad54b6",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logbrew/react-native",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.44",
|
|
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",
|