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
12 changes: 12 additions & 0 deletions Sources/Observability/InstrumentationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Foundation
import OpenTelemetrySdk
import OpenTelemetryApi
import OpenTelemetryProtocolExporterHttp
import URLSessionInstrumentation

import Common
import API
Expand All @@ -19,6 +20,7 @@ final class InstrumentationManager {
let otelMeter: (any Meter)?
public let otelBatchLogRecordProcessor: BatchLogRecordProcessor?
private let sessionManager: SessionManager
private let urlSessionInstrumentation: URLSessionInstrumentation
private var cachedGauges = AtomicDictionary<String, DoubleGauge>()
private var cachedCounters = AtomicDictionary<String, DoubleCounter>()
private var cachedLongCounters = AtomicDictionary<String, LongCounter>()
Expand Down Expand Up @@ -141,6 +143,16 @@ final class InstrumentationManager {
self.otelMeter = OpenTelemetry.instance.meterProvider.get(
name: options.serviceName
)

self.urlSessionInstrumentation = URLSessionInstrumentation(
configuration: URLSessionInstrumentationConfiguration(
shouldInstrument: { urlRequest in
urlRequest.url?.absoluteString.contains(options.otlpEndpoint) == false &&
urlRequest.url?.absoluteString.contains("https://mobile.launchdarkly.com/mobile") == false
},
tracer: self.otelTracer
)
)
}

func recordMetric(metric: Metric) {
Expand Down
12 changes: 0 additions & 12 deletions Sources/Observability/ObservabilityClient.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@preconcurrency import OpenTelemetryApi
import OpenTelemetrySdk
import URLSessionInstrumentation

import API
import Common
Expand All @@ -15,7 +14,6 @@ public final class ObservabilityClient: Observe {

private var cachedSpans = AtomicDictionary<String, Span>()
private let crashReporter: CrashReporter
private let urlSessionInstrumentation: URLSessionInstrumentation

public init(sdkKey: String, resource: Resource, options: Options) {
let sessionManager = SessionManager(options: .init(timeout: options.sessionBackgroundTimeout))
Expand All @@ -36,16 +34,6 @@ public final class ObservabilityClient: Observe {
crashReporter.logPendingCrashReports()
}

self.urlSessionInstrumentation = URLSessionInstrumentation(
configuration: URLSessionInstrumentationConfiguration(
shouldInstrument: { urlRequest in
urlRequest.url?.absoluteString.contains(options.otlpEndpoint) == false &&
urlRequest.url?.absoluteString.contains("https://mobile.launchdarkly.com/mobile") == false
},
tracer: instrumentationManager.otelTracer
)
)

sessionManager.onSessionDidChange = { _ in
// TODO: create a span
}
Expand Down