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
14 changes: 14 additions & 0 deletions ExampleApp/ExampleApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ let config = { () -> LDConfig in
mobileKey: mobileKey,
autoEnvAttributes: .enabled
)
config.plugins = [
Observability(
options: .init(
otlpEndpoint: "http://localhost:4318",
sessionBackgroundTimeout: 3,
isDebug: true,
logs: .enabled,
traces: .enabled,
metrics: .enabled
)
)
]
/*
config.plugins = [
Observability(
options: .init(
Expand All @@ -20,6 +33,7 @@ let config = { () -> LDConfig in
)
)
]
*/
return config
}()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import SwiftUI
import LaunchDarklyObservability
import OpenTelemetryApi

struct InstrumentationView: View {
var body: some View {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import SwiftUI
import LaunchDarklyObservability
import OpenTelemetryApi


struct LogsView: View {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import SwiftUI
import LaunchDarklyObservability
import OpenTelemetryApi


struct TraceView: View {
Expand Down Expand Up @@ -30,6 +29,7 @@ struct TraceView: View {
.task(id: started) {
guard started else {
span?.end()
await LDObserve.shared.flush()
return name = ""
}
span = LDObserve.shared.startSpan(name: name)
Expand Down
105 changes: 65 additions & 40 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,63 @@ let package = Package(
.package(url: "https://github.com/kstenerud/KSCrash.git", from: "2.3.0"),
],
targets: [
.target(name: "Common"),
.target(
name: "API",
name: "DomainModels"
),
.target(
name: "DomainServices",
dependencies: [
.product(name: "OpenTelemetrySdk", package: "opentelemetry-swift"),
.product(name: "OpenTelemetryApi", package: "opentelemetry-swift"),
.product(name: "ResourceExtension", package: "opentelemetry-swift"),
"DomainModels"
]
),
.testTarget(
name: "CommonTests",
.target(
name: "ApplicationServices",
dependencies: [
"Common"
],
resources: [.process("GraphQL/Queries")]
"DomainModels",
"DomainServices"
]
),
.target(name: "CrashReporter"),
.target(
name: "CrashReporterLive",
name: "iOSSessionService",
dependencies: [
"DomainModels",
"DomainServices",
"ApplicationServices"
]
),
.target(
name: "KSCrashReportService",
dependencies: [
"DomainModels",
"DomainServices",
"ApplicationServices",
.product(name: "Installations", package: "KSCrash")
]
),
.target(
name: "OTelInstrumentation",
dependencies: [
"CrashReporter",
"Common",
"DomainModels",
"DomainServices",
"ApplicationServices",
"Sampling",
.product(name: "OpenTelemetrySdk", package: "opentelemetry-swift"),
.product(name: "OpenTelemetryApi", package: "opentelemetry-swift"),
.product(name: "URLSessionInstrumentation", package: "opentelemetry-swift"),
.product(name: "ResourceExtension", package: "opentelemetry-swift"),
.product(name: "OpenTelemetryProtocolExporterHTTP", package: "opentelemetry-swift"),
.product(name: "InMemoryExporter", package: "opentelemetry-swift"),
.product(name: "OTelSwiftLog", package: "opentelemetry-swift"),
]
),
.testTarget(
name: "OTelInstrumentationServiceTests",
dependencies: [
"OTelInstrumentation",
.product(name: "OpenTelemetrySdk", package: "opentelemetry-swift"),
.product(name: "Installations", package: "KSCrash")
.product(name: "OpenTelemetryApi", package: "opentelemetry-swift"),
.product(name: "OpenTelemetryProtocolExporterHTTP", package: "opentelemetry-swift"),
]
),
.target(
Expand All @@ -52,6 +84,7 @@ let package = Package(
.target(
name: "SamplingLive",
dependencies: [
"DomainModels",
"Sampling",
"Common",
.product(name: "OpenTelemetryApi", package: "opentelemetry-swift"),
Expand All @@ -61,6 +94,7 @@ let package = Package(
.testTarget(
name: "SamplingLiveTests",
dependencies: [
"DomainModels",
"Sampling",
"SamplingLive",
"Common",
Expand All @@ -73,43 +107,34 @@ let package = Package(
]
),
.target(
name: "Instrumentation",
name: "ObservabilityServiceLive",
dependencies: [
"API",
"CrashReporter",
"Sampling",
.product(name: "OpenTelemetrySdk", package: "opentelemetry-swift"),
.product(name: "OpenTelemetryApi", package: "opentelemetry-swift"),
]
),
.target(
name: "Observability",
dependencies: [
"Common",
"API",
"CrashReporter",
"CrashReporterLive",
"ApplicationServices",
"OTelInstrumentation",
"KSCrashReportService",
"iOSSessionService",
"Sampling",
"SamplingLive",
"Instrumentation",
.product(name: "OpenTelemetrySdk", package: "opentelemetry-swift"),
.product(name: "OpenTelemetryApi", package: "opentelemetry-swift"),
.product(name: "OpenTelemetryProtocolExporterHTTP", package: "opentelemetry-swift"),
.product(name: "URLSessionInstrumentation", package: "opentelemetry-swift"),
"Common"
],
resources: [
.process("Resources"),
]
),
.target(name: "Common"),
.testTarget(
name: "CommonTests",
dependencies: [
"Common"
],
resources: [.process("GraphQL/Queries")]
),
.target(
name: "LaunchDarklyObservability",
dependencies: [
"Observability",
"API",
"Common",
.product(name: "LaunchDarkly", package: "ios-client-sdk"),
.product(name: "OpenTelemetrySdk", package: "opentelemetry-swift"),
.product(name: "OpenTelemetryApi", package: "opentelemetry-swift"),
"ApplicationServices",
"ObservabilityServiceLive",
.product(name: "LaunchDarkly", package: "ios-client-sdk")
]
)
]
Expand Down
58 changes: 0 additions & 58 deletions Sources/API/Observe.swift

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
public struct CrashReporter {
public var install: () throws -> Void
public struct CrashReportService {
public var logPendingCrashReports: () -> Void

public init(
install: @escaping () throws -> Void,
logPendingCrashReports: @escaping () -> Void
) {
self.install = install
self.logPendingCrashReports = logPendingCrashReports
}
}
7 changes: 7 additions & 0 deletions Sources/ApplicationServices/InstrumentationError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public enum InstrumentationError: Error {
case invalidTraceExporterUrl
case invalidLogExporterUrl
case invalidMetricExporterUrl
case invalidGraphQLUrl
case unableToLoadReportStore
}
18 changes: 18 additions & 0 deletions Sources/ApplicationServices/LogsService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@_exported import DomainModels

public struct LogsService {
public var recordLog: (_ message: String, _ severity: Severity, _ attributes: [String: AttributeValue]) -> Void
public var flush: () async -> Bool

public init(
recordLog: @escaping (_: String, _: Severity, _: [String : AttributeValue]) -> Void,
flush: @escaping () async -> Bool
) {
self.recordLog = recordLog
self.flush = flush
}

public func recordLog(message: String, severity: Severity, attributes: [String: AttributeValue]) {
recordLog(message, severity, attributes)
}
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
import OpenTelemetryApi
@_exported import DomainModels

import API
import Sampling

public struct Instrumentation {
public struct MetricsService {
public var recordMetric: (_ metric: Metric) -> Void
public var recordCount: (_ metric: Metric) -> Void
public var recordIncr: (_ metric: Metric) -> Void
public var recordHistogram: (_ metric: Metric) -> Void
public var recordUpDownCounter: (_ metric: Metric) -> Void
public var recordError: (_ error: Error, _ attributes: [String: AttributeValue]) -> Void
public var recordLog: (_ message: String, _ severity: Severity, _ attributes: [String: AttributeValue]) -> Void
public var startSpan: (_ name: String, _ attributes: [String: AttributeValue]) -> Span
public var flush: () -> Bool
public var flush: () async -> Bool

public init(
recordMetric: @escaping (_: Metric) -> Void,
recordCount: @escaping (_: Metric) -> Void,
recordIncr: @escaping (_: Metric) -> Void,
recordHistogram: @escaping (_: Metric) -> Void,
recordUpDownCounter: @escaping (_: Metric) -> Void,
recordError: @escaping (_: Error, _: [String : AttributeValue]) -> Void,
recordLog: @escaping (_: String, _: Severity, _: [String : AttributeValue]) -> Void,
startSpan: @escaping (_: String, _: [String : AttributeValue]) -> Span,
flush: @escaping () -> Bool
flush: @escaping () async -> Bool
) {
self.recordMetric = recordMetric
self.recordCount = recordCount
self.recordIncr = recordIncr
self.recordHistogram = recordHistogram
self.recordUpDownCounter = recordUpDownCounter
self.recordError = recordError
self.recordLog = recordLog
self.startSpan = startSpan
self.flush = flush
}

Expand All @@ -55,16 +43,4 @@ public struct Instrumentation {
public func recordUpDownCounter(metric: Metric) {
recordUpDownCounter(metric)
}

public func recordError(error: Error, attributes: [String: AttributeValue]) {
recordError(error, attributes)
}

public func recordLog(message: String, severity: Severity, attributes: [String: AttributeValue]) {
recordLog(message, severity, attributes)
}

public func startSpan(name: String, attributes: [String: AttributeValue]) -> Span {
startSpan(name, attributes)
}
}
Loading