Skip to content

Commit 755e7e6

Browse files
refactor: observability service dependencies
1 parent 7fbf282 commit 755e7e6

File tree

47 files changed

+1635
-437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1635
-437
lines changed

ExampleApp/ExampleApp/AppDelegate.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ let config = { () -> LDConfig in
88
mobileKey: mobileKey,
99
autoEnvAttributes: .enabled
1010
)
11+
config.plugins = [
12+
Observability(
13+
options: .init(
14+
otlpEndpoint: "http://localhost:4318",
15+
sessionBackgroundTimeout: 3,
16+
isDebug: true,
17+
logs: .enabled,
18+
traces: .enabled,
19+
metrics: .enabled
20+
)
21+
)
22+
]
23+
/*
1124
config.plugins = [
1225
Observability(
1326
options: .init(
@@ -20,6 +33,7 @@ let config = { () -> LDConfig in
2033
)
2134
)
2235
]
36+
*/
2337
return config
2438
}()
2539

ExampleApp/ExampleApp/Instrumentation/Manual/InstrumentationView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import SwiftUI
22
import LaunchDarklyObservability
3-
import OpenTelemetryApi
43

54
struct InstrumentationView: View {
65
var body: some View {

ExampleApp/ExampleApp/Instrumentation/Manual/LogsView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import SwiftUI
22
import LaunchDarklyObservability
3-
import OpenTelemetryApi
43

54

65
struct LogsView: View {

ExampleApp/ExampleApp/Instrumentation/Manual/TraceView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import SwiftUI
22
import LaunchDarklyObservability
3-
import OpenTelemetryApi
43

54

65
struct TraceView: View {

Package.swift

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,36 +32,64 @@ let package = Package(
3232
]
3333
),
3434
.target(
35-
name: "SessionServiceLive",
35+
name: "iOSSessionService",
3636
dependencies: [
3737
"DomainModels",
3838
"DomainServices",
3939
"ApplicationServices"
4040
]
4141
),
4242
.target(
43-
name: "OTelInstrumentationService",
43+
name: "KSCrashReportService",
44+
dependencies: [
45+
"DomainModels",
46+
"DomainServices",
47+
"ApplicationServices",
48+
.product(name: "Installations", package: "KSCrash")
49+
]
50+
),
51+
.target(
52+
name: "OTelInstrumentation",
4453
dependencies: [
4554
"Common",
4655
"DomainModels",
4756
"DomainServices",
4857
"ApplicationServices",
4958
"Sampling",
50-
"SamplingLive",
5159
.product(name: "OpenTelemetrySdk", package: "opentelemetry-swift"),
5260
.product(name: "OpenTelemetryApi", package: "opentelemetry-swift"),
61+
.product(name: "URLSessionInstrumentation", package: "opentelemetry-swift"),
62+
.product(name: "ResourceExtension", package: "opentelemetry-swift"),
5363
.product(name: "OpenTelemetryProtocolExporterHTTP", package: "opentelemetry-swift"),
64+
.product(name: "InMemoryExporter", package: "opentelemetry-swift"),
65+
.product(name: "OTelSwiftLog", package: "opentelemetry-swift"),
5466
]
5567
),
5668
.testTarget(
5769
name: "OTelInstrumentationServiceTests",
5870
dependencies: [
59-
"OTelInstrumentationService",
71+
"OTelInstrumentation",
6072
.product(name: "OpenTelemetrySdk", package: "opentelemetry-swift"),
6173
.product(name: "OpenTelemetryApi", package: "opentelemetry-swift"),
6274
.product(name: "OpenTelemetryProtocolExporterHTTP", package: "opentelemetry-swift"),
6375
]
6476
),
77+
.target(
78+
name: "ObservabilityServiceLive",
79+
dependencies: [
80+
"ApplicationServices",
81+
"OTelInstrumentation",
82+
"KSCrashReportService",
83+
"iOSSessionService",
84+
"Sampling",
85+
"SamplingLive",
86+
"Sampling",
87+
"Common"
88+
],
89+
resources: [
90+
.process("Resources"),
91+
]
92+
),
6593
.target(name: "Common"),
6694
.target(
6795
name: "API",
@@ -151,12 +179,15 @@ let package = Package(
151179
.target(
152180
name: "LaunchDarklyObservability",
153181
dependencies: [
154-
"Observability",
155-
"API",
156-
"Common",
182+
"ApplicationServices",
183+
"ObservabilityServiceLive",
157184
.product(name: "LaunchDarkly", package: "ios-client-sdk"),
158-
.product(name: "OpenTelemetrySdk", package: "opentelemetry-swift"),
159-
.product(name: "OpenTelemetryApi", package: "opentelemetry-swift"),
185+
// "Observability",
186+
// "API",
187+
// "Common",
188+
// .product(name: "LaunchDarkly", package: "ios-client-sdk"),
189+
// .product(name: "OpenTelemetrySdk", package: "opentelemetry-swift"),
190+
// .product(name: "OpenTelemetryApi", package: "opentelemetry-swift"),
160191
]
161192
)
162193
]
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
public struct CrashReportService {
2-
public var install: () throws -> Void
32
public var logPendingCrashReports: () -> Void
43

54
public init(
6-
install: @escaping () throws -> Void,
75
logPendingCrashReports: @escaping () -> Void
86
) {
9-
self.install = install
107
self.logPendingCrashReports = logPendingCrashReports
118
}
129
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
public enum InstrumentationError: Error {
22
case traceExporterUrlIsInvalid
33
case logExporterUrlIsInvalid
4+
case metricExporterUrlIsInvalid
5+
case graphQLUrlIsInvalid
46
}

Sources/ApplicationServices/ObservabilityService.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,8 @@ public struct ObservabilityService {
4444
public func startSpan(name: String, attributes: [String: AttributeValue]) -> Span {
4545
tracesService.startSpan(name: name, attributes: attributes)
4646
}
47+
48+
public func flush() -> Bool {
49+
tracesService.flush() && logsService.flush() && metricsService.flush()
50+
}
4751
}

Sources/ApplicationServices/Options.swift

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,26 @@ public struct Options {
2929
case enabled
3030
case disabled
3131
}
32-
public let serviceName: String
33-
public let serviceVersion: String
34-
public let otlpEndpoint: String
35-
public let backendUrl: String
36-
public let resourceAttributes: [String: AttributeValue]
37-
public let customHeaders: [(String, String)]
38-
public let sessionBackgroundTimeout: TimeInterval
39-
public let isDebug: Bool
40-
public let disableErrorTracking: Bool
41-
public let logs: FeatureFlag
42-
public let traces: FeatureFlag
43-
public let metrics: FeatureFlag
44-
public let log: OSLog
32+
public enum TracingOriginsOption {
33+
case enabled([String])
34+
case enabledRegex([String])
35+
case disabled
36+
}
37+
public var serviceName: String
38+
public var serviceVersion: String
39+
public var otlpEndpoint: String
40+
public var backendUrl: String
41+
public var resourceAttributes: [String: AttributeValue]
42+
public var customHeaders: [(String, String)]
43+
public var tracingOrigins: TracingOriginsOption
44+
public var urlBlocklist: [String]
45+
public var sessionBackgroundTimeout: TimeInterval
46+
public var isDebug: Bool
47+
public var disableErrorTracking: Bool
48+
public var logs: FeatureFlag
49+
public var traces: FeatureFlag
50+
public var metrics: FeatureFlag
51+
public var log: OSLog
4552

4653
public init(
4754
serviceName: String = "observability-swift",
@@ -50,6 +57,8 @@ public struct Options {
5057
backendUrl: String = "https://pub.observability.app.launchdarkly.com",
5158
resourceAttributes: [String: AttributeValue] = [:],
5259
customHeaders: [(String, String)] = [],
60+
tracingOrigins: TracingOriginsOption = .disabled,
61+
urlBlocklist: [String] = [],
5362
sessionBackgroundTimeout: TimeInterval = 15 * 60,
5463
isDebug: Bool = false,
5564
disableErrorTracking: Bool = false,
@@ -64,6 +73,8 @@ public struct Options {
6473
self.backendUrl = backendUrl
6574
self.resourceAttributes = resourceAttributes
6675
self.customHeaders = customHeaders
76+
self.tracingOrigins = tracingOrigins
77+
self.urlBlocklist = urlBlocklist
6778
self.sessionBackgroundTimeout = sessionBackgroundTimeout
6879
self.isDebug = isDebug
6980
self.disableErrorTracking = disableErrorTracking
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public struct UserInteractionService {
2+
public var start: () -> Void
3+
4+
public init(start: @escaping () -> Void) {
5+
self.start = start
6+
}
7+
}

0 commit comments

Comments
 (0)