@@ -139,13 +139,21 @@ public struct PrometheusLabelSanitizer: LabelSanitizer {
139
139
}
140
140
}
141
141
142
+ /// Defines the base for a bridge between PrometheusClient and swift-metrics.
143
+ /// Used by `SwiftMetrics.prometheus()` to get an instance of `PromtheusClient` from `MetricsSystem`
144
+ ///
145
+ /// Any custom implementation of `MetricsFactory` using `PrometheusClient` should conform to this implementation.
146
+ public protocol PrometheusWrappedMetricsFactory : MetricsFactory {
147
+ var client : PrometheusClient { get }
148
+ }
149
+
142
150
/// A bridge between PrometheusClient and swift-metrics. Prometheus types don't map perfectly on swift-metrics API,
143
151
/// which makes bridge implementation non trivial. This class defines how exactly swift-metrics types should be backed
144
152
/// with Prometheus types, e.g. how to sanitize labels, what buckets/quantiles to use for recorder/timer, etc.
145
- public struct PrometheusMetricsFactory : MetricsFactory {
153
+ public struct PrometheusMetricsFactory : PrometheusWrappedMetricsFactory {
146
154
147
155
/// Prometheus client to bridge swift-metrics API to.
148
- private let client : PrometheusClient
156
+ public let client : PrometheusClient
149
157
150
158
/// Bridge configuration.
151
159
private let configuration : Configuration
@@ -262,10 +270,10 @@ public extension MetricsSystem {
262
270
/// - Throws: `PrometheusError.PrometheusFactoryNotBootstrapped`
263
271
/// if no `PrometheusClient` was used to bootstrap `MetricsSystem`
264
272
static func prometheus( ) throws -> PrometheusClient {
265
- guard let prom = self . factory as? PrometheusClient else {
273
+ guard let prom = self . factory as? PrometheusWrappedMetricsFactory else {
266
274
throw PrometheusError . prometheusFactoryNotBootstrapped ( bootstrappedWith: " \( self . factory) " )
267
275
}
268
- return prom
276
+ return prom. client
269
277
}
270
278
}
271
279
0 commit comments