Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ExampleApp/ExampleApp/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ struct Client {
tracesApi: .enabled,
metricsApi: .enabled,
crashReporting: .disabled,
autoInstrumentation: [.urlSession, .userTaps, .memory, .cpu, .memoryWarnings]
autoInstrumentation: [.urlSession, .userTaps, .memory, .cpu, .memoryWarnings],
instrumentation: .init(
urlSession: .enabled,
userTaps: .enabled,
memory: .enabled,
memoryWarnings: .enabled,
cpu: .disabled,
launchTimes: .enabled
)
)
)
]
Expand Down
36 changes: 35 additions & 1 deletion Sources/Observability/Api/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ public struct Options {
public enum FeatureFlag {
case enabled
case disabled

var isEnabled: Bool {
switch self {
case .enabled: return true
case .disabled: return false
}
}
}
public enum TracingOriginsOption {
case enabled([String])
Expand All @@ -144,6 +151,30 @@ public struct Options {
case cpu
case launchTimes
}
public struct Instrumentation {
let urlSession: FeatureFlag
let userTaps: FeatureFlag
let memory: FeatureFlag
let memoryWarnings: FeatureFlag
let cpu: FeatureFlag
let launchTimes: FeatureFlag

public init(
urlSession: FeatureFlag = .disabled,
userTaps: FeatureFlag = .disabled,
memory: FeatureFlag = .disabled,
memoryWarnings: FeatureFlag = .disabled,
cpu: FeatureFlag = .disabled,
launchTimes: FeatureFlag = .disabled
) {
self.urlSession = urlSession
self.userTaps = userTaps
self.memory = memory
self.memoryWarnings = memoryWarnings
self.cpu = cpu
self.launchTimes = launchTimes
}
}
public var serviceName: String
public var serviceVersion: String
public var otlpEndpoint: String
Expand All @@ -161,6 +192,7 @@ public struct Options {
public var log: OSLog
public var crashReporting: FeatureFlag
public var autoInstrumentation: Set<AutoInstrumented>
public var instrumentation: Instrumentation
let launchMeter = LaunchMeter()

public init(
Expand All @@ -180,7 +212,8 @@ public struct Options {
metricsApi: AppMetrics = .enabled,
log: OSLog = OSLog(subsystem: "com.launchdarkly", category: "LaunchDarklyObservabilityPlugin"),
crashReporting: FeatureFlag = .enabled,
autoInstrumentation: Set<AutoInstrumented> = [.urlSession]
autoInstrumentation: Set<AutoInstrumented> = [.urlSession],
instrumentation: Instrumentation = .init()
) {
self.serviceName = serviceName
self.serviceVersion = serviceVersion
Expand All @@ -199,5 +232,6 @@ public struct Options {
self.log = log
self.crashReporting = crashReporting
self.autoInstrumentation = autoInstrumentation
self.instrumentation = instrumentation
}
}
10 changes: 5 additions & 5 deletions Sources/Observability/Client/ObservabilityClientFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public struct ObservabilityClientFactory {
Task {
await batchWorker.addExporter(logExporter)
}
if options.autoInstrumentation.contains(.memoryWarnings) {
if options.instrumentation.memoryWarnings.isEnabled {
let memoryWarningMonitor = MemoryPressureMonitor(options: options, appLogBuilder: appLogBuilder) { log in
await eventQueue.send(LogItem(log: log))
}
Expand Down Expand Up @@ -88,7 +88,7 @@ public struct ObservabilityClientFactory {
options: options.tracesApi,
tracingApiClient: traceClient
)
if options.autoInstrumentation.contains(.urlSession) {
if options.instrumentation.urlSession.isEnabled {
autoInstrumentation.append(
NetworkInstrumentationManager(
options: options,
Expand All @@ -97,7 +97,7 @@ public struct ObservabilityClientFactory {
)
)
}
if options.autoInstrumentation.contains(.launchTimes) {
if options.instrumentation.launchTimes.isEnabled {
options.launchMeter.subscribe { statistics in
for element in statistics {
let span = traceClient.startSpan(
Expand Down Expand Up @@ -141,7 +141,7 @@ public struct ObservabilityClientFactory {
metricsApiClient: metricsClient
)

if options.autoInstrumentation.contains(.memory) {
if options.instrumentation.memory.isEnabled {
autoInstrumentation.append(
MeasurementTask(metricsApi: metricsClient, samplingInterval: autoInstrumentationSamplingInterval) { api in
guard let report = MemoryUseManager.memoryReport(log: options.log) else { return }
Expand All @@ -155,7 +155,7 @@ public struct ObservabilityClientFactory {
)
}

if options.autoInstrumentation.contains(.cpu) {
if options.instrumentation.cpu.isEnabled {
autoInstrumentation.append(
MeasurementTask(metricsApi: metricsClient, samplingInterval: autoInstrumentationSamplingInterval) { api in
guard let value = CpuUtilizationManager.currentCPUUsage() else { return }
Expand Down