@logbrew/react-native 0.1.11 → 0.1.12
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/LogBrewReactNative.podspec +25 -3
- package/README.md +106 -3
- package/apple-native-diagnostics.d.ts +52 -0
- package/apple-native-diagnostics.js +286 -0
- package/expo.cjs +46 -0
- package/expo.d.ts +16 -0
- package/expo.js +5 -0
- package/fatal-replay.cjs +12 -1
- package/global-errors.cjs +3 -1
- package/index.cjs +84 -2
- package/index.d.cts +4 -0
- package/index.d.ts +4 -0
- package/index.js +84 -2
- package/index.native.d.ts +4 -0
- package/index.native.js +14 -1
- package/ios/AppleDiagnostics/LBRNAppleDiagnosticsModule.h +4 -0
- package/ios/AppleDiagnostics/LBRNAppleDiagnosticsModule.mm +56 -0
- package/ios/AppleDiagnostics/LBRNAppleNativeDiagnostics.swift +293 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/AutomaticTelemetryContext.swift +72 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngine.swift +270 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngineAutomatic.swift +331 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngineDurable.swift +148 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngineQueue.swift +343 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryLifecycle.swift +70 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/DurableDeliveryStore.swift +258 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/DurableDeliveryStoreRecovery.swift +330 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/EventEncoding.swift +114 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/IssueDiagnostics.swift +385 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/LifecycleTrace.swift +138 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/LogBrewClient.swift +358 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/LogBrewLogger.swift +262 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/LogBrewTrace.swift +357 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/Metadata.swift +86 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/NativeStackFrame.swift +27 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/ProductTimeline.swift +228 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/PublicTypes.swift +334 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/TelemetryContext.swift +197 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/TelemetryContextValidation.swift +337 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/TraceEvidence.swift +79 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/Transport.swift +204 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/URLSessionTrace.swift +277 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/URLSessionTracer.swift +151 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/Validation.swift +165 -0
- package/ios/GeneratedAppleDiagnostics/LogBrewCrash/CrashEngine.swift +125 -0
- package/ios/GeneratedAppleDiagnostics/LogBrewCrash/CrashReportSanitizer.swift +139 -0
- package/ios/GeneratedAppleDiagnostics/LogBrewCrash/CrashStorageDirectory.swift +124 -0
- package/ios/GeneratedAppleDiagnostics/LogBrewCrash/NativeArtifactIdentity.swift +137 -0
- package/ios/GeneratedAppleDiagnostics/LogBrewCrash/NativeCrashCapture.swift +229 -0
- package/ios/GeneratedAppleDiagnostics/LogBrewCrash/NativeCrashPublic.swift +386 -0
- package/ios/GeneratedAppleDiagnostics/LogBrewCrash/NativeCrashReplay.swift +317 -0
- package/ios/GeneratedAppleDiagnostics/LogBrewCrash/NativeHangIncidentStore.swift +321 -0
- package/ios/GeneratedAppleDiagnostics/LogBrewCrash/NativeHangWatchdog.swift +386 -0
- package/ios/GeneratedAppleDiagnostics/LogBrewCrash/NativeHangWatchdogContracts.swift +84 -0
- package/ios/GeneratedAppleDiagnostics/LogBrewCrash/NativeHangWatchdogSystem.swift +139 -0
- package/ios/GeneratedAppleDiagnostics/LogBrewCrash/NativeMainThreadStackCapture.swift +84 -0
- package/ios/GeneratedAppleDiagnostics/LogBrewCrash/NativeStackFrameSanitizer.swift +170 -0
- package/ios/GeneratedAppleDiagnostics/SOURCE-MANIFEST.json +43 -0
- package/package.json +42 -4
- package/promise-rejections.cjs +3 -1
- package/scripts/sync-apple-native-sources.mjs +93 -0
- package/src/NativeLogBrewAppleDiagnostics.ts +12 -0
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
// Generated by scripts/sync-apple-native-sources.mjs.
|
|
2
|
+
// Edit the canonical Swift source, then regenerate this package boundary.
|
|
3
|
+
public enum IssueLevel: String, Codable, Sendable {
|
|
4
|
+
case trace
|
|
5
|
+
case debug
|
|
6
|
+
case info
|
|
7
|
+
case warn
|
|
8
|
+
case warning
|
|
9
|
+
case error
|
|
10
|
+
case fatal
|
|
11
|
+
case critical
|
|
12
|
+
|
|
13
|
+
public var canonicalValue: String {
|
|
14
|
+
switch self {
|
|
15
|
+
case .trace, .debug, .info:
|
|
16
|
+
"info"
|
|
17
|
+
case .warn, .warning:
|
|
18
|
+
"warning"
|
|
19
|
+
case .error:
|
|
20
|
+
"error"
|
|
21
|
+
case .fatal, .critical:
|
|
22
|
+
"critical"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public func encode(to encoder: any Encoder) throws {
|
|
27
|
+
var container = encoder.singleValueContainer()
|
|
28
|
+
try container.encode(canonicalValue)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public init(from decoder: any Decoder) throws {
|
|
32
|
+
let container = try decoder.singleValueContainer()
|
|
33
|
+
let value = try container.decode(String.self)
|
|
34
|
+
guard let level = IssueLevel(rawValue: value) else {
|
|
35
|
+
throw DecodingError.dataCorruptedError(in: container, debugDescription: "unsupported issue level")
|
|
36
|
+
}
|
|
37
|
+
self = level
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public enum LogLevel: String, Codable, Sendable {
|
|
42
|
+
case trace
|
|
43
|
+
case debug
|
|
44
|
+
case info
|
|
45
|
+
case warn
|
|
46
|
+
case warning
|
|
47
|
+
case error
|
|
48
|
+
case fatal
|
|
49
|
+
case critical
|
|
50
|
+
|
|
51
|
+
public var canonicalValue: String {
|
|
52
|
+
switch self {
|
|
53
|
+
case .trace, .debug, .info:
|
|
54
|
+
"info"
|
|
55
|
+
case .warn, .warning:
|
|
56
|
+
"warning"
|
|
57
|
+
case .error:
|
|
58
|
+
"error"
|
|
59
|
+
case .fatal, .critical:
|
|
60
|
+
"critical"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public func encode(to encoder: any Encoder) throws {
|
|
65
|
+
var container = encoder.singleValueContainer()
|
|
66
|
+
try container.encode(canonicalValue)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public init(from decoder: any Decoder) throws {
|
|
70
|
+
let container = try decoder.singleValueContainer()
|
|
71
|
+
let value = try container.decode(String.self)
|
|
72
|
+
guard let level = LogLevel(rawValue: value) else {
|
|
73
|
+
throw DecodingError.dataCorruptedError(in: container, debugDescription: "unsupported log level")
|
|
74
|
+
}
|
|
75
|
+
self = level
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public enum SpanStatus: String, Codable, Sendable {
|
|
80
|
+
case ok
|
|
81
|
+
case error
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public enum ActionStatus: String, Codable, Sendable {
|
|
85
|
+
case queued
|
|
86
|
+
case running
|
|
87
|
+
case success
|
|
88
|
+
case failure
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public enum MetricKind: String, Codable, Sendable {
|
|
92
|
+
case counter
|
|
93
|
+
case gauge
|
|
94
|
+
case histogram
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public enum MetricTemporality: String, Codable, Sendable {
|
|
98
|
+
case delta
|
|
99
|
+
case cumulative
|
|
100
|
+
case instant
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public struct ClientConfig: Equatable, Sendable {
|
|
104
|
+
public let apiKey: String
|
|
105
|
+
public let sdkName: String
|
|
106
|
+
public let sdkVersion: String
|
|
107
|
+
public let maxRetries: Int
|
|
108
|
+
public let context: TelemetryContext?
|
|
109
|
+
public let includeAutomaticContext: Bool
|
|
110
|
+
|
|
111
|
+
public init(
|
|
112
|
+
apiKey: String,
|
|
113
|
+
sdkName: String,
|
|
114
|
+
sdkVersion: String,
|
|
115
|
+
maxRetries: Int = 2,
|
|
116
|
+
context: TelemetryContext? = nil,
|
|
117
|
+
includeAutomaticContext: Bool = true,
|
|
118
|
+
) {
|
|
119
|
+
self.apiKey = apiKey
|
|
120
|
+
self.sdkName = sdkName
|
|
121
|
+
self.sdkVersion = sdkVersion
|
|
122
|
+
self.maxRetries = maxRetries
|
|
123
|
+
self.context = context
|
|
124
|
+
self.includeAutomaticContext = includeAutomaticContext
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
public struct ReleaseAttributes: Codable, Equatable, Sendable {
|
|
129
|
+
public let version: String
|
|
130
|
+
public let commit: String?
|
|
131
|
+
public let notes: String?
|
|
132
|
+
public let metadata: Metadata?
|
|
133
|
+
public let context: TelemetryContext?
|
|
134
|
+
|
|
135
|
+
public init(
|
|
136
|
+
version: String,
|
|
137
|
+
commit: String? = nil,
|
|
138
|
+
notes: String? = nil,
|
|
139
|
+
metadata: Metadata? = nil,
|
|
140
|
+
context: TelemetryContext? = nil,
|
|
141
|
+
) {
|
|
142
|
+
self.version = version
|
|
143
|
+
self.commit = commit
|
|
144
|
+
self.notes = notes
|
|
145
|
+
self.metadata = metadata
|
|
146
|
+
self.context = context
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
public struct EnvironmentAttributes: Codable, Equatable, Sendable {
|
|
151
|
+
public let name: String
|
|
152
|
+
public let region: String?
|
|
153
|
+
public let metadata: Metadata?
|
|
154
|
+
public let context: TelemetryContext?
|
|
155
|
+
|
|
156
|
+
public init(
|
|
157
|
+
name: String,
|
|
158
|
+
region: String? = nil,
|
|
159
|
+
metadata: Metadata? = nil,
|
|
160
|
+
context: TelemetryContext? = nil,
|
|
161
|
+
) {
|
|
162
|
+
self.name = name
|
|
163
|
+
self.region = region
|
|
164
|
+
self.metadata = metadata
|
|
165
|
+
self.context = context
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public struct IssueAttributes: Codable, Equatable, Sendable {
|
|
170
|
+
public let title: String
|
|
171
|
+
public let level: IssueLevel
|
|
172
|
+
public let message: String?
|
|
173
|
+
public let exception: IssueException?
|
|
174
|
+
public let stackFrames: [IssueStackFrame]?
|
|
175
|
+
public let breadcrumbs: [IssueBreadcrumb]?
|
|
176
|
+
public let breadcrumbsTruncated: Bool?
|
|
177
|
+
public let metadata: Metadata?
|
|
178
|
+
public let context: TelemetryContext?
|
|
179
|
+
@_spi(CrashReplay) public let nativeStackFrames: [NativeStackFrame]?
|
|
180
|
+
|
|
181
|
+
public init(
|
|
182
|
+
title: String,
|
|
183
|
+
level: IssueLevel,
|
|
184
|
+
message: String? = nil,
|
|
185
|
+
exception: IssueException? = nil,
|
|
186
|
+
stackFrames: [IssueStackFrame]? = nil,
|
|
187
|
+
breadcrumbs: [IssueBreadcrumb]? = nil,
|
|
188
|
+
breadcrumbsTruncated: Bool? = nil,
|
|
189
|
+
metadata: Metadata? = nil,
|
|
190
|
+
context: TelemetryContext? = nil,
|
|
191
|
+
) {
|
|
192
|
+
self.title = title
|
|
193
|
+
self.level = level
|
|
194
|
+
self.message = message
|
|
195
|
+
self.exception = exception
|
|
196
|
+
self.stackFrames = stackFrames
|
|
197
|
+
self.breadcrumbs = breadcrumbs
|
|
198
|
+
self.breadcrumbsTruncated = breadcrumbsTruncated
|
|
199
|
+
self.metadata = metadata
|
|
200
|
+
self.context = context
|
|
201
|
+
nativeStackFrames = nil
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
@_spi(CrashReplay)
|
|
205
|
+
public init(
|
|
206
|
+
title: String,
|
|
207
|
+
level: IssueLevel,
|
|
208
|
+
message: String? = nil,
|
|
209
|
+
exception: IssueException? = nil,
|
|
210
|
+
stackFrames: [IssueStackFrame]? = nil,
|
|
211
|
+
breadcrumbs: [IssueBreadcrumb]? = nil,
|
|
212
|
+
breadcrumbsTruncated: Bool? = nil,
|
|
213
|
+
metadata: Metadata? = nil,
|
|
214
|
+
context: TelemetryContext? = nil,
|
|
215
|
+
nativeStackFrames: [NativeStackFrame]?,
|
|
216
|
+
) {
|
|
217
|
+
self.title = title
|
|
218
|
+
self.level = level
|
|
219
|
+
self.message = message
|
|
220
|
+
self.exception = exception
|
|
221
|
+
self.stackFrames = stackFrames
|
|
222
|
+
self.breadcrumbs = breadcrumbs
|
|
223
|
+
self.breadcrumbsTruncated = breadcrumbsTruncated
|
|
224
|
+
self.metadata = metadata
|
|
225
|
+
self.context = context
|
|
226
|
+
self.nativeStackFrames = nativeStackFrames
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
public struct LogAttributes: Codable, Equatable, Sendable {
|
|
231
|
+
public let message: String
|
|
232
|
+
public let level: LogLevel
|
|
233
|
+
public let logger: String?
|
|
234
|
+
public let metadata: Metadata?
|
|
235
|
+
public let context: TelemetryContext?
|
|
236
|
+
|
|
237
|
+
public init(
|
|
238
|
+
message: String,
|
|
239
|
+
level: LogLevel,
|
|
240
|
+
logger: String? = nil,
|
|
241
|
+
metadata: Metadata? = nil,
|
|
242
|
+
context: TelemetryContext? = nil,
|
|
243
|
+
) {
|
|
244
|
+
self.message = message
|
|
245
|
+
self.level = level
|
|
246
|
+
self.logger = logger
|
|
247
|
+
self.metadata = metadata
|
|
248
|
+
self.context = context
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
public struct SpanAttributes: Codable, Equatable, Sendable {
|
|
253
|
+
public let name: String
|
|
254
|
+
public let traceId: String
|
|
255
|
+
public let spanId: String
|
|
256
|
+
public let parentSpanId: String?
|
|
257
|
+
public let status: SpanStatus
|
|
258
|
+
public let durationMs: Double?
|
|
259
|
+
public let events: [SpanEventSummary]?
|
|
260
|
+
public let links: [SpanLinkSummary]?
|
|
261
|
+
public let metadata: Metadata?
|
|
262
|
+
public let context: TelemetryContext?
|
|
263
|
+
|
|
264
|
+
public init(
|
|
265
|
+
name: String,
|
|
266
|
+
traceId: String,
|
|
267
|
+
spanId: String,
|
|
268
|
+
parentSpanId: String? = nil,
|
|
269
|
+
status: SpanStatus,
|
|
270
|
+
durationMs: Double? = nil,
|
|
271
|
+
events: [SpanEventSummary]? = nil,
|
|
272
|
+
links: [SpanLinkSummary]? = nil,
|
|
273
|
+
metadata: Metadata? = nil,
|
|
274
|
+
context: TelemetryContext? = nil,
|
|
275
|
+
) {
|
|
276
|
+
self.name = name
|
|
277
|
+
self.traceId = traceId
|
|
278
|
+
self.spanId = spanId
|
|
279
|
+
self.parentSpanId = parentSpanId
|
|
280
|
+
self.status = status
|
|
281
|
+
self.durationMs = durationMs
|
|
282
|
+
self.events = events
|
|
283
|
+
self.links = links
|
|
284
|
+
self.metadata = metadata
|
|
285
|
+
self.context = context
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
public struct ActionAttributes: Codable, Equatable, Sendable {
|
|
290
|
+
public let name: String
|
|
291
|
+
public let status: ActionStatus
|
|
292
|
+
public let metadata: Metadata?
|
|
293
|
+
public let context: TelemetryContext?
|
|
294
|
+
|
|
295
|
+
public init(
|
|
296
|
+
name: String,
|
|
297
|
+
status: ActionStatus,
|
|
298
|
+
metadata: Metadata? = nil,
|
|
299
|
+
context: TelemetryContext? = nil,
|
|
300
|
+
) {
|
|
301
|
+
self.name = name
|
|
302
|
+
self.status = status
|
|
303
|
+
self.metadata = metadata
|
|
304
|
+
self.context = context
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
public struct MetricAttributes: Codable, Equatable, Sendable {
|
|
309
|
+
public let name: String
|
|
310
|
+
public let kind: MetricKind
|
|
311
|
+
public let value: Double
|
|
312
|
+
public let unit: String
|
|
313
|
+
public let temporality: MetricTemporality
|
|
314
|
+
public let metadata: Metadata?
|
|
315
|
+
public let context: TelemetryContext?
|
|
316
|
+
|
|
317
|
+
public init(
|
|
318
|
+
name: String,
|
|
319
|
+
kind: MetricKind,
|
|
320
|
+
value: Double,
|
|
321
|
+
unit: String,
|
|
322
|
+
temporality: MetricTemporality,
|
|
323
|
+
metadata: Metadata? = nil,
|
|
324
|
+
context: TelemetryContext? = nil,
|
|
325
|
+
) {
|
|
326
|
+
self.name = name
|
|
327
|
+
self.kind = kind
|
|
328
|
+
self.value = value
|
|
329
|
+
self.unit = unit
|
|
330
|
+
self.temporality = temporality
|
|
331
|
+
self.metadata = metadata
|
|
332
|
+
self.context = context
|
|
333
|
+
}
|
|
334
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// Generated by scripts/sync-apple-native-sources.mjs.
|
|
2
|
+
// Edit the canonical Swift source, then regenerate this package boundary.
|
|
3
|
+
/// A bounded name and optional version shared by service, runtime, and framework context.
|
|
4
|
+
public struct TelemetryNamedVersion: Codable, Equatable, Sendable {
|
|
5
|
+
public let name: String
|
|
6
|
+
public let version: String?
|
|
7
|
+
|
|
8
|
+
public init(name: String, version: String? = nil) {
|
|
9
|
+
self.name = name
|
|
10
|
+
self.version = version
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/// Deployment identity shared across related telemetry signals.
|
|
15
|
+
public struct TelemetryDeployment: Codable, Equatable, Sendable {
|
|
16
|
+
public let environment: String?
|
|
17
|
+
public let release: String?
|
|
18
|
+
|
|
19
|
+
public init(environment: String? = nil, release: String? = nil) {
|
|
20
|
+
self.environment = environment
|
|
21
|
+
self.release = release
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/// Operating-system identity without host, account, or network identifiers.
|
|
26
|
+
public struct TelemetryOperatingSystem: Codable, Equatable, Sendable {
|
|
27
|
+
public let name: String
|
|
28
|
+
public let version: String?
|
|
29
|
+
public let build: String?
|
|
30
|
+
|
|
31
|
+
public init(name: String, version: String? = nil, build: String? = nil) {
|
|
32
|
+
self.name = name
|
|
33
|
+
self.version = version
|
|
34
|
+
self.build = build
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/// Privacy-bounded device class. Do not use unique hardware identifiers as these values.
|
|
39
|
+
public struct TelemetryDevice: Codable, Equatable, Sendable {
|
|
40
|
+
public let family: String?
|
|
41
|
+
public let model: String?
|
|
42
|
+
public let architecture: String?
|
|
43
|
+
|
|
44
|
+
public init(family: String? = nil, model: String? = nil, architecture: String? = nil) {
|
|
45
|
+
self.family = family
|
|
46
|
+
self.model = model
|
|
47
|
+
self.architecture = architecture
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/// Application bundle identity shared by issues, logs, traces, metrics, and product events.
|
|
52
|
+
public struct TelemetryApplication: Codable, Equatable, Sendable {
|
|
53
|
+
public let name: String?
|
|
54
|
+
public let version: String?
|
|
55
|
+
public let build: String?
|
|
56
|
+
|
|
57
|
+
public init(name: String? = nil, version: String? = nil, build: String? = nil) {
|
|
58
|
+
self.name = name
|
|
59
|
+
self.version = version
|
|
60
|
+
self.build = build
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/// Stable resource identity shared by every LogBrew signal.
|
|
65
|
+
public struct TelemetryResource: Codable, Equatable, Sendable {
|
|
66
|
+
public let service: TelemetryNamedVersion?
|
|
67
|
+
public let deployment: TelemetryDeployment?
|
|
68
|
+
public let runtime: TelemetryNamedVersion?
|
|
69
|
+
public let framework: TelemetryNamedVersion?
|
|
70
|
+
public let operatingSystem: TelemetryOperatingSystem?
|
|
71
|
+
public let device: TelemetryDevice?
|
|
72
|
+
public let application: TelemetryApplication?
|
|
73
|
+
|
|
74
|
+
public init(
|
|
75
|
+
service: TelemetryNamedVersion? = nil,
|
|
76
|
+
deployment: TelemetryDeployment? = nil,
|
|
77
|
+
runtime: TelemetryNamedVersion? = nil,
|
|
78
|
+
framework: TelemetryNamedVersion? = nil,
|
|
79
|
+
operatingSystem: TelemetryOperatingSystem? = nil,
|
|
80
|
+
device: TelemetryDevice? = nil,
|
|
81
|
+
application: TelemetryApplication? = nil,
|
|
82
|
+
) {
|
|
83
|
+
self.service = service
|
|
84
|
+
self.deployment = deployment
|
|
85
|
+
self.runtime = runtime
|
|
86
|
+
self.framework = framework
|
|
87
|
+
self.operatingSystem = operatingSystem
|
|
88
|
+
self.device = device
|
|
89
|
+
self.application = application
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/// W3C-compatible trace identity shared by non-span telemetry and trace evidence.
|
|
94
|
+
public struct TelemetryTraceContext: Codable, Equatable, Sendable {
|
|
95
|
+
public let traceId: String
|
|
96
|
+
public let spanId: String?
|
|
97
|
+
public let parentSpanId: String?
|
|
98
|
+
public let sampled: Bool?
|
|
99
|
+
|
|
100
|
+
public init(
|
|
101
|
+
traceId: String,
|
|
102
|
+
spanId: String? = nil,
|
|
103
|
+
parentSpanId: String? = nil,
|
|
104
|
+
sampled: Bool? = nil,
|
|
105
|
+
) {
|
|
106
|
+
self.traceId = traceId
|
|
107
|
+
self.spanId = spanId
|
|
108
|
+
self.parentSpanId = parentSpanId
|
|
109
|
+
self.sampled = sampled
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/// Opaque application-owned session identity.
|
|
114
|
+
public struct TelemetrySessionContext: Codable, Equatable, Sendable {
|
|
115
|
+
public let id: String
|
|
116
|
+
public let previousId: String?
|
|
117
|
+
|
|
118
|
+
public init(id: String, previousId: String? = nil) {
|
|
119
|
+
self.id = id
|
|
120
|
+
self.previousId = previousId
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public enum TelemetrySubjectKind: String, Codable, Equatable, Sendable {
|
|
125
|
+
case anonymous
|
|
126
|
+
case user
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/// Explicit app-owned subject identity. Do not send names, email addresses, or IP addresses.
|
|
130
|
+
public struct TelemetrySubjectContext: Codable, Equatable, Sendable {
|
|
131
|
+
public let id: String
|
|
132
|
+
public let kind: TelemetrySubjectKind
|
|
133
|
+
|
|
134
|
+
public init(id: String, kind: TelemetrySubjectKind) {
|
|
135
|
+
self.id = id
|
|
136
|
+
self.kind = kind
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/// Versioned, privacy-bounded context available on every LogBrew event type.
|
|
141
|
+
public struct TelemetryContext: Codable, Equatable, Sendable {
|
|
142
|
+
public let schemaVersion: Int
|
|
143
|
+
public let resource: TelemetryResource?
|
|
144
|
+
public let trace: TelemetryTraceContext?
|
|
145
|
+
public let session: TelemetrySessionContext?
|
|
146
|
+
public let subject: TelemetrySubjectContext?
|
|
147
|
+
public let tags: [String: String]?
|
|
148
|
+
|
|
149
|
+
public init(
|
|
150
|
+
resource: TelemetryResource? = nil,
|
|
151
|
+
trace: TelemetryTraceContext? = nil,
|
|
152
|
+
session: TelemetrySessionContext? = nil,
|
|
153
|
+
subject: TelemetrySubjectContext? = nil,
|
|
154
|
+
tags: [String: String]? = nil,
|
|
155
|
+
) {
|
|
156
|
+
schemaVersion = 1
|
|
157
|
+
self.resource = resource
|
|
158
|
+
self.trace = trace
|
|
159
|
+
self.session = session
|
|
160
|
+
self.subject = subject
|
|
161
|
+
self.tags = tags
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/// Merge this context with an event-level override using deterministic field-level rules.
|
|
165
|
+
public func merging(_ override: TelemetryContext) throws -> TelemetryContext {
|
|
166
|
+
try requireTelemetryContext(mergeTelemetryContexts(self, override))
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/// Task-local context for correlating related telemetry without global mutable user state.
|
|
171
|
+
public enum LogBrewTelemetry {
|
|
172
|
+
@TaskLocal private static var activeContext: TelemetryContext?
|
|
173
|
+
|
|
174
|
+
public static var current: TelemetryContext? {
|
|
175
|
+
activeContext
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
public static func withContext<T>(
|
|
179
|
+
_ context: TelemetryContext,
|
|
180
|
+
operation: () throws -> T,
|
|
181
|
+
) throws -> T {
|
|
182
|
+
let nested = try mergeTelemetryContexts(activeContext, context)
|
|
183
|
+
return try $activeContext.withValue(nested) {
|
|
184
|
+
try operation()
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
public static func withContext<T>(
|
|
189
|
+
_ context: TelemetryContext,
|
|
190
|
+
operation: () async throws -> T,
|
|
191
|
+
) async throws -> T {
|
|
192
|
+
let nested = try mergeTelemetryContexts(activeContext, context)
|
|
193
|
+
return try await $activeContext.withValue(nested) {
|
|
194
|
+
try await operation()
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|