Protocols
The following protocols are available globally.
-
The
MetricsFactoryis the bridge between theMetricsSystemand the metrics backend implementation.MetricsFactory‘s role is to initialize concrete implementations of the various metric types:Counter->CounterHandlerFloatingPointCounter->FloatingPointCounterHandlerRecorder->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
CounterHandlerrepresents 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
CounterHandleryou should respect a few requirements that are necessary so applications work as expected regardless of the selectedCounterHandlerimplementation.- The
CounterHandlermust be aclass.
Declaration
Swift
public protocol CounterHandler : AnyObject - The
-
A
FloatingPointCounterHandlerrepresents 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
FloatingPointCounterHandleryou should respect a few requirements that are necessary so applications work as expected regardless of the selectedFloatingPointCounterHandlerimplementation.- The
FloatingPointCounterHandlermust be aclass.
Declaration
Swift
public protocol FloatingPointCounterHandler : AnyObject - The
-
A
RecorderHandlerrepresents 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
RecorderHandleryou should respect a few requirements that are necessary so applications work as expected regardless of the selectedRecorderHandlerimplementation.- The
RecorderHandlermust be aclass.
Declaration
Swift
public protocol RecorderHandler : AnyObject - The
-
A
TimerHandlerrepresents 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
TimerHandleryou should respect a few requirements that are necessary so applications work as expected regardless of the selectedTimerHandlerimplementation.- The
TimerHandlermust be aclass.
Declaration
Swift
public protocol TimerHandler : AnyObject - The
View on GitHub
Install in Dash
Protocols Reference