Protocols
The following protocols are available globally.
-
The
MetricsFactory
is the bridge between theMetricsSystem
and the metrics backend implementation.MetricsFactory
‘s role is to initialize concrete implementations of the various metric types:Counter
->CounterHandler
FloatingPointCounter
->FloatingPointCounterHandler
Recorder
->RecorderHandler
Warning
This type is an implementation detail and should not be used directly, unless implementing your own metrics backend. To use the SwiftMetrics API, please refer to the documentation of
MetricsSystem
.Destroying metrics
Since some metrics implementations may need to allocate (potentially “heavy”) resources for metrics, destroying metrics offers a signal to libraries when a metric is “known to never be updated again.”
While many metrics are bound to the entire lifetime of an application and thus never need to be destroyed eagerly, some metrics have well defined unique life-cycles, and it may be beneficial to release any resources held by them more eagerly than awaiting the application’s termination. In such cases, a library or application should invoke a metric’s appropriate
destroy()
method, which in turn results in the corresponding handler that it is backed by to be passed todestroyCounter(handler:)
,destroyRecorder(handler:)
ordestroyTimer(handler:)
where the factory can decide to free any corresponding resources.While some libraries may not need to implement this destroying as they may be stateless or similar, libraries using the metrics API should always assume a library WILL make use of this signal, and shall not neglect calling these methods when appropriate.
See moreDeclaration
Swift
public protocol MetricsFactory
-
A
CounterHandler
represents a backend implementation of aCounter
.This type is an implementation detail and should not be used directly, unless implementing your own metrics backend. To use the SwiftMetrics API, please refer to the documentation of
Counter
.Implementation requirements
To implement your own
CounterHandler
you should respect a few requirements that are necessary so applications work as expected regardless of the selectedCounterHandler
implementation.- The
CounterHandler
must be aclass
.
Declaration
Swift
public protocol CounterHandler : AnyObject
- The
-
A
FloatingPointCounterHandler
represents a backend implementation of aFloatingPointCounter
.This type is an implementation detail and should not be used directly, unless implementing your own metrics backend. To use the SwiftMetrics API, please refer to the documentation of
FloatingPointCounter
.Implementation requirements
To implement your own
FloatingPointCounterHandler
you should respect a few requirements that are necessary so applications work as expected regardless of the selectedFloatingPointCounterHandler
implementation.- The
FloatingPointCounterHandler
must be aclass
.
Declaration
Swift
public protocol FloatingPointCounterHandler : AnyObject
- The
-
A
RecorderHandler
represents a backend implementation of aRecorder
.This type is an implementation detail and should not be used directly, unless implementing your own metrics backend. To use the SwiftMetrics API, please refer to the documentation of
Recorder
.Implementation requirements
To implement your own
RecorderHandler
you should respect a few requirements that are necessary so applications work as expected regardless of the selectedRecorderHandler
implementation.- The
RecorderHandler
must be aclass
.
Declaration
Swift
public protocol RecorderHandler : AnyObject
- The
-
A
TimerHandler
represents a backend implementation of aTimer
.This type is an implementation detail and should not be used directly, unless implementing your own metrics backend. To use the SwiftMetrics API, please refer to the documentation of
Timer
.Implementation requirements
To implement your own
TimerHandler
you should respect a few requirements that are necessary so applications work as expected regardless of the selectedTimerHandler
implementation.- The
TimerHandler
must be aclass
.
Declaration
Swift
public protocol TimerHandler : AnyObject
- The