You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-*Swift Metrics Compatible*: Use the native Prometheus client API implemented in this library or integrate with [Swift Metrics](doc:swift-metrics).
13
+
-*Thread Safe and Type-Safe*.
14
+
-*Swift Metrics Compatible*: Use the native Prometheus client API implemented in this library or use [Swift Metrics](doc:swift-metrics) as a backend for this library.
16
15
17
16
For general Prometheus guidance, see the [Prometheus Documentation][prometheus-docs].
- Each metric name gets exactly one `# HELP` and `# TYPE` line (before the metric output), regardless of how many label variations exist.
@@ -137,13 +137,17 @@ Notice how:
137
137
138
138
*Prometheus Compliance:*
139
139
- Metric names, label names, and `# HELP` text are validated against Prometheus character allowlists.
140
-
- Different label names and structures are allowed for the same metric name.
141
-
- However, cannot mix labeled and unlabeled metrics with the same name.
140
+
- Different label names and structures are allowed for the same metric name; however, cannot mix labeled and unlabeled metrics with the same metric name.
142
141
- Must use consistent metric types, help text, and histogram buckets for the same metric name.
143
142
144
143
*Known Limitations:*
145
144
- Prometheus converts all metrics to floating-point types, which can cause precision loss. For example, Counters designed for `UInt64` values or Gauges capturing nanosecond timestamps will lose precision. In such cases, consider alternative frameworks or solutions.
146
145
146
+
*Thread-safe through multiple mechanisms:*
147
+
- Metric value updates are based on atomic operations.
148
+
- Export functions like `emitToBuffer()` and `emitToString()` use internal locking and conform to Swift [Sendable](https://developer.apple.com/documentation/Swift/Sendable).
149
+
- Lower-level export via `emit(into:)` is thread-safe due to Swift's `inout`[exclusivity](https://www.swift.org/blog/swift-5-exclusivity/) guarantees, with the compiler preventing concurrent access through warnings (Swift 5) or errors (Swift 6 [strict concurrency](https://developer.apple.com/documentation/swift/adoptingswift6) mode).
All operations are thread-safe, with the exception of the lower-level ``emit(into:)`` overload variant (compared to the thread-safe ``emitToBuffer()`` or ``emitToString()``). The client uses internal locking to ensure consistency across concurrent access and conforms to Swift's `Sendable` protocol, meaning it can be safely passed between actors and used in concurrent contexts without additional synchronization.
203
-
204
-
## Additional Notes
204
+
*Additional Notes*:
205
205
206
-
Above, we demonstrated the Prometheus’s proper approach. However, you can also integrate with the `swift-metrics` ecosystem using`PrometheusMetricsFactory`.
206
+
Above, we demonstrated the Prometheus’s proper approach. However, you can also use [Swift Metrics](doc:swift-metrics) as a backend for this library via`PrometheusMetricsFactory`.
207
207
208
-
-<doc:swift-metrics>
209
-
210
-
> Note: The naming between Prometheus and Swift-Metrics is a bit confusing. Swift Metrics calls a
208
+
> Note: The naming between Prometheus and Swift-Metrics may be confusing. Swift Metrics calls a
211
209
> metric's name its label and they call a metric's labels dimensions. In this article, when we
212
210
> refer to labels, we mean the additional properties that can be added to a metrics name.
213
211
>
@@ -216,17 +214,18 @@ Above, we demonstrated the Prometheus’s proper approach. However, you can also
216
214
> | swift-metrics |`label`|`dimensions`|
217
215
> | Prometheus |`name`|`labels`|
218
216
219
-
220
-
## References
217
+
### References
221
218
222
219
- Prometheus [Docs - Overview][prometheus-docs]
223
220
- Prometheus [Instrumentation Best Practices - Use Labels][prometheus-use-labels]
221
+
- Prometheus [Naming Best Practices][prometheus-naming]
0 commit comments