Skip to content
Draft
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
6 changes: 3 additions & 3 deletions Examples/Logging Tracer/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ Logger.printHeader()

OpenTelemetry.registerTracerProvider(tracerProvider: LoggingTracerProvider())

var tracer = OpenTelemetry.instance.tracerProvider.get(instrumentationName: "ConsoleApp", instrumentationVersion: "semver:1.0.0")

let tracer = OpenTelemetry.instance.tracerProvider.get(instrumentationName: "ConsoleApp", instrumentationVersion: "semver:1.0.0")
let span1 = tracer.spanBuilder(spanName: "Main (span1)").startSpan()
OpenTelemetry.instance.contextProvider.setActiveSpan(span1)
let semaphore = DispatchSemaphore(value: 0)
DispatchQueue.global().async {
let tracer = OpenTelemetry.instance.tracerProvider.get(instrumentationName: "ConsoleApp", instrumentationVersion: "semver:1.0.0")
let span2 = tracer.spanBuilder(spanName: "Main (span2)").startSpan()
OpenTelemetry.instance.contextProvider.setActiveSpan(span2)
OpenTelemetry.instance.contextProvider.activeSpan?.setAttribute(key: "myAttribute", value: "myValue")
Expand All @@ -26,4 +26,4 @@ DispatchQueue.global().async {

span1.end()

semaphore.wait()
semaphore.wait()
9 changes: 7 additions & 2 deletions Examples/Network Sample/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ func simpleNetworkCall() {
semaphore.wait()
}

class SessionDelegate: NSObject, URLSessionDataDelegate, URLSessionTaskDelegate {
final class SessionDelegate: NSObject, URLSessionDataDelegate, URLSessionTaskDelegate, @unchecked Sendable {
let semaphore = DispatchSemaphore(value: 0)
var callCount = 0
private let queue = DispatchQueue(label: "callCount")
private var _callCount = 0
var callCount: Int {
get { queue.sync { _callCount } }
set { queue.sync { _callCount = newValue } }
}

func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
semaphore.signal()
Expand Down
4 changes: 2 additions & 2 deletions Examples/OTLP Exporter/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
tracerProviderSDK?.addSpanProcessor(SignPostIntegration())
}

func createSpans() {
@MainActor func createSpans() {
let parentSpan1 = tracer.spanBuilder(spanName: "Main").setSpanKind(spanKind: .client).startSpan()
parentSpan1.setAttribute(key: sampleKey, value: sampleValue)
OpenTelemetry.instance.contextProvider.setActiveSpan(parentSpan1)
Expand All @@ -71,7 +71,7 @@
parentSpan1.end()
}

func doWork() {
@MainActor func doWork() {
let childSpan = tracer.spanBuilder(spanName: "doWork").setSpanKind(spanKind: .client).startSpan()
childSpan.setAttribute(key: sampleKey, value: sampleValue)
Thread.sleep(forTimeInterval: Double.random(in: 0 ..< 10) / 100)
Expand Down
4 changes: 2 additions & 2 deletions Examples/OTLP HTTP Exporter/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
tracerProviderSDK?.addSpanProcessor(SignPostIntegration())
}

func createSpans() {
@MainActor func createSpans() {
let parentSpan1 = tracer.spanBuilder(spanName: "Main").setSpanKind(spanKind: .client).startSpan()
parentSpan1.setAttribute(key: sampleKey, value: sampleValue)
OpenTelemetry.instance.contextProvider.setActiveSpan(parentSpan1)
Expand All @@ -64,7 +64,7 @@
parentSpan1.end()
}

func doWork() {
@MainActor func doWork() {
let childSpan = tracer.spanBuilder(spanName: "doWork").setSpanKind(spanKind: .client).startSpan()
childSpan.setAttribute(key: sampleKey, value: sampleValue)
Thread.sleep(forTimeInterval: Double.random(in: 0 ..< 10) / 100)
Expand Down
6 changes: 3 additions & 3 deletions Examples/Prometheus Sample/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ let localAddress = "192.168.1.28"

let promOptions = PrometheusExporterOptions(url: "http://\(localAddress):9184/metrics")
let promExporter = PrometheusExporter(options: promOptions)
let metricsHttpServer = PrometheusExporterHttpServer(exporter: promExporter)

DispatchQueue.global(qos: .default).async {
Task { @MainActor in
let metricsHttpServer = PrometheusExporterHttpServer(exporter: promExporter)
do {
try metricsHttpServer.start()
} catch {
Expand Down Expand Up @@ -84,7 +84,7 @@ while counter < 3000 {
sleep(1)
}

metricsHttpServer.stop()
// Server will be stopped when the task completes

print("Metrics server shutdown.")
print("Press Enter key to exit.")
14 changes: 8 additions & 6 deletions Examples/Simple Exporter/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@
tracerProviderSDK?.addSpanProcessor(SignPostIntegration())
}

func simpleSpan() {
@MainActor func simpleSpan() {
let span = tracer.spanBuilder(spanName: "SimpleSpan").setSpanKind(spanKind: .client).startSpan()
span.setAttribute(key: sampleKey, value: sampleValue)
Thread.sleep(forTimeInterval: 0.5)
span.end()
}

func childSpan() {
@MainActor func childSpan() {
let span = tracer.spanBuilder(spanName: "parentSpan").setSpanKind(spanKind: .client).setActive(true).startSpan()
span.setAttribute(key: sampleKey, value: sampleValue)
Thread.sleep(forTimeInterval: 0.2)
Expand All @@ -67,9 +67,11 @@
span.end()
}

simpleSpan()
sleep(1)
childSpan()
sleep(1)
Task { @MainActor in
simpleSpan()
sleep(1)
childSpan()
sleep(1)
}

#endif
60 changes: 39 additions & 21 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.9
// swift-tools-version:6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import Foundation
Expand Down Expand Up @@ -40,7 +40,8 @@ let package = Package(
.target(
name: "SharedTestUtils",
dependencies: [],
path: "Tests/Shared/TestUtils"
path: "Tests/Shared/TestUtils",
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-availability-checking", "-strict-concurrency=minimal"])]
),
.target(
name: "OTelSwiftLog",
Expand Down Expand Up @@ -132,20 +133,23 @@ let package = Package(
.testTarget(
name: "OTelSwiftLogTests",
dependencies: ["OTelSwiftLog"],
path: "Tests/BridgesTests/OTelSwiftLog"
path: "Tests/BridgesTests/OTelSwiftLog",
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-availability-checking", "-strict-concurrency=minimal"])]
),
.testTarget(
name: "SwiftMetricsShimTests",
dependencies: [
"SwiftMetricsShim",
.product(name: "OpenTelemetrySdk", package: "opentelemetry-swift-core")
],
path: "Tests/ImportersTests/SwiftMetricsShim"
path: "Tests/ImportersTests/SwiftMetricsShim",
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-availability-checking", "-strict-concurrency=minimal"])]
),
.testTarget(
name: "PrometheusExporterTests",
dependencies: ["PrometheusExporter"],
path: "Tests/ExportersTests/Prometheus"
path: "Tests/ExportersTests/Prometheus",
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-availability-checking", "-strict-concurrency=minimal"])]
),
.testTarget(
name: "OpenTelemetryProtocolExporterTests",
Expand All @@ -154,32 +158,38 @@ let package = Package(
"OpenTelemetryProtocolExporterHttp",
"SharedTestUtils",
],
path: "Tests/ExportersTests/OpenTelemetryProtocol"
path: "Tests/ExportersTests/OpenTelemetryProtocol",
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-availability-checking", "-strict-concurrency=minimal"])]
),
.testTarget(
name: "InMemoryExporterTests",
dependencies: ["InMemoryExporter"],
path: "Tests/ExportersTests/InMemory"
path: "Tests/ExportersTests/InMemory",
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-availability-checking", "-strict-concurrency=minimal"])]
),
.testTarget(
name: "PersistenceExporterTests",
dependencies: ["PersistenceExporter"],
path: "Tests/ExportersTests/PersistenceExporter"
path: "Tests/ExportersTests/PersistenceExporter",
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-availability-checking", "-strict-concurrency=minimal"])]
),
.testTarget(
name: "ContribTests",
dependencies: [
"BaggagePropagationProcessor",
"InMemoryExporter"
]
],
path: "Tests/ContribTests",
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-availability-checking", "-strict-concurrency=minimal"])]
),
.testTarget(
.testTarget(
name: "SessionTests",
dependencies: [
"Sessions",
.product(name: "OpenTelemetrySdk", package: "opentelemetry-swift-core")
],
path: "Tests/InstrumentationTests/SessionTests"
path: "Tests/InstrumentationTests/SessionTests",
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-availability-checking", "-strict-concurrency=minimal"])]
),
.executableTarget(
name: "LoggingTracer",
Expand Down Expand Up @@ -235,7 +245,8 @@ extension Package {
"OpenTracingShim",
.product(name: "OpenTelemetrySdk", package: "opentelemetry-swift-core")
],
path: "Tests/ImportersTests/OpenTracingShim"
path: "Tests/ImportersTests/OpenTracingShim",
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-availability-checking", "-strict-concurrency=minimal"])]
)
])
#endif
Expand Down Expand Up @@ -266,12 +277,14 @@ extension Package {
condition: .when(platforms: [.iOS, .macOS, .tvOS, .macCatalyst, .linux])
)
],
path: "Sources/Exporters/Jaeger"
path: "Sources/Exporters/Jaeger",
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-availability-checking", "-strict-concurrency=minimal"])]
),
.testTarget(
name: "JaegerExporterTests",
dependencies: ["JaegerExporter"],
path: "Tests/ExportersTests/Jaeger"
path: "Tests/ExportersTests/Jaeger",
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-availability-checking", "-strict-concurrency=minimal"])]
),
.executableTarget(
name: "SimpleExporter",
Expand All @@ -298,7 +311,8 @@ extension Package {
dependencies: [
"NetworkStatus"
],
path: "Tests/InstrumentationTests/NetworkStatusTests"
path: "Tests/InstrumentationTests/NetworkStatusTests",
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-availability-checking", "-strict-concurrency=minimal"])]
),
.target(
name: "URLSessionInstrumentation",
Expand All @@ -314,7 +328,8 @@ extension Package {
"URLSessionInstrumentation",
"SharedTestUtils",
],
path: "Tests/InstrumentationTests/URLSessionTests"
path: "Tests/InstrumentationTests/URLSessionTests",
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-availability-checking", "-strict-concurrency=minimal"])]
),
.executableTarget(
name: "NetworkSample",
Expand All @@ -335,7 +350,8 @@ extension Package {
.testTarget(
name: "ZipkinExporterTests",
dependencies: ["ZipkinExporter"],
path: "Tests/ExportersTests/Zipkin"
path: "Tests/ExportersTests/Zipkin",
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-availability-checking", "-strict-concurrency=minimal"])]
),
.executableTarget(
name: "OTLPExporter",
Expand Down Expand Up @@ -380,15 +396,16 @@ extension Package {
"ResourceExtension",
.product(name: "OpenTelemetrySdk", package: "opentelemetry-swift-core")
],
path: "Tests/InstrumentationTests/SDKResourceExtensionTests"
path: "Tests/InstrumentationTests/SDKResourceExtensionTests",
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-availability-checking", "-strict-concurrency=minimal"])]
),
.target(
name: "MetricKitInstrumentation",
dependencies: [
.product(name: "OpenTelemetrySdk", package: "opentelemetry-swift-core")
],
path: "Sources/Instrumentation/MetricKit",
exclude: ["README.md"]
exclude: ["README.md", "StackTraceFormat.md"]
),
.testTarget(
name: "MetricKitInstrumentationTests",
Expand All @@ -397,7 +414,8 @@ extension Package {
"InMemoryExporter",
.product(name: "OpenTelemetrySdk", package: "opentelemetry-swift-core")
],
path: "Tests/InstrumentationTests/MetricKitTests"
path: "Tests/InstrumentationTests/MetricKitTests",
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-availability-checking", "-strict-concurrency=minimal"])]
),
.executableTarget(
name: "PrometheusSample",
Expand All @@ -424,4 +442,4 @@ if ProcessInfo.processInfo.environment["OTEL_ENABLE_SWIFTLINT"] != nil {
.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins")
]
}
}
}
5 changes: 2 additions & 3 deletions Sources/Bridges/OTelSwiftLog/LogHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let bridgeName: String = "OTelSwiftLog"
let version: String = "1.0.0"

/// A custom log handler to translate swift logs into otel logs
public struct OTelLogHandler: LogHandler {
public struct OTelLogHandler: LogHandler, @unchecked Sendable {
/// Get or set the configured log level.
///
/// - note: `LogHandler`s must treat the log level as a value type. This means that the change in metadata must
Expand Down Expand Up @@ -41,7 +41,6 @@ public struct OTelLogHandler: LogHandler {
self.loggerProvider = loggerProvider
logger = self.loggerProvider.loggerBuilder(instrumentationScopeName: bridgeName)
.setInstrumentationVersion(version)
.setEventDomain("device")
.setIncludeTraceContext(true)
.setAttributes(attributes)
.setIncludeTraceContext(includeTraceContext)
Expand Down Expand Up @@ -138,4 +137,4 @@ func convertSeverity(level: Logging.Logger.Level) -> OpenTelemetryApi.Severity {
case .critical:
return OpenTelemetryApi.Severity.error2 // should this be fatal instead?
}
}
}
4 changes: 2 additions & 2 deletions Sources/Exporters/InMemory/InMemoryExporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import Foundation
import OpenTelemetrySdk

public class InMemoryExporter: SpanExporter {
public final class InMemoryExporter: SpanExporter, @unchecked Sendable {
private var finishedSpanItems: [SpanData] = []
private var isRunning: Bool = true

Expand Down Expand Up @@ -41,4 +41,4 @@ public class InMemoryExporter: SpanExporter {
finishedSpanItems.removeAll()
isRunning = false
}
}
}
2 changes: 1 addition & 1 deletion Sources/Exporters/Jaeger/Jaeger Thrift/agent+Exts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
}

extension AgentProcessor: TProcessor {
static let processorHandlers: ProcessorHandlerDictionary = {
nonisolated(unsafe) static let processorHandlers: ProcessorHandlerDictionary = {
var processorHandlers = ProcessorHandlerDictionary()

processorHandlers["emitZipkinBatch"] = { _, inProtocol, _, _ in
Expand Down
2 changes: 1 addition & 1 deletion Sources/Exporters/Jaeger/Jaeger Thrift/jaeger+Exts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@
}

extension CollectorProcessor: TProcessor {
static let processorHandlers: ProcessorHandlerDictionary = {
nonisolated(unsafe) static let processorHandlers: ProcessorHandlerDictionary = {
var processorHandlers = ProcessorHandlerDictionary()

processorHandlers["submitBatches"] = { sequenceID, inProtocol, outProtocol, handler in
Expand Down
4 changes: 2 additions & 2 deletions Sources/Exporters/Jaeger/JaegerSpanExporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import OpenTelemetrySdk
import Thrift

public class JaegerSpanExporter: SpanExporter {
public final class JaegerSpanExporter: SpanExporter, @unchecked Sendable {
let collectorAddress: String
let process: Process

Expand All @@ -34,4 +34,4 @@
public func shutdown(explicitTimeout: TimeInterval? = nil) {}
}

#endif
#endif
4 changes: 2 additions & 2 deletions Sources/Exporters/Jaeger/Sender.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Network
import Thrift

public class Sender {
public final class Sender: @unchecked Sendable {
private let host: String
private let port = 6832

Expand Down Expand Up @@ -58,4 +58,4 @@
}
}

#endif
#endif
Loading
Loading