swift-server / swift-prometheus

Prometheus client library for Swift
https://swiftpackageindex.com/swift-server/swift-prometheus
Apache License 2.0
142 stars 30 forks source link

Add Sendable conformance #113

Closed mman closed 5 months ago

mman commented 5 months ago

Compiling with [SwiftSetting] = [.enableExperimentalFeature("StrictConcurrency=complete")] produces couple now all too familiar warnings related to concurrency.

Looking at the source code of PrometheusClient as well as other Metrics it seems that most code (if not all) is guarded with a Lock so all public classes could essentially be @unchecked Sendable.

I have in my code opted for this...

import Prometheus

extension PrometheusClient: @unchecked Sendable {}
extension PromGauge: @unchecked Sendable {}
extension PromHistogram: @unchecked Sendable {}
extension PromSummary: @unchecked Sendable {}
let prometheus = PrometheusClient()

let gauge = prometheus.createGauge(forType: Int.self, named: "peers_total")

...to silence compiler and am now testing to see if anything breaks.

Looks like official Sendable conformance can be added to the library, correct?

mman commented 5 months ago

My fault, been pinned to version 1.0.0 and completely missed the 2.0.0-alpha where Sendable conformance is obviously addressed. Thanks and closing!