Metrics¶
See the Instrumentation & metrics guide for usage.
asyncly.client.metrics.sinks.base.MetricsSink
¶
Bases: Protocol
Protocol for metrics backends used by InstrumentableHttpClient.
Implement observe_request to record requests in any backend.
observe_request
¶
observe_request(
*,
client: str,
method: str,
route: str,
status: int | str,
duration_seconds: float,
error_type: str | None = None,
) -> None
Record a single completed request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
str
|
The client name ( |
required |
method
|
str
|
HTTP method. |
required |
route
|
str
|
Normalized, low-cardinality route label. |
required |
status
|
int | str
|
Response status code, or a string marker on error. |
required |
duration_seconds
|
float
|
Total time including response handling. |
required |
error_type
|
str | None
|
Exception class name if the request failed, else None. |
None
|
Source code in asyncly/client/metrics/sinks/base.py
asyncly.client.metrics.sinks.noop.NoopSink
¶
The default sink: records nothing and adds no overhead.
asyncly.client.metrics.sinks.prometheus.PrometheusSink
¶
PrometheusSink(
namespace: str = "asyncly",
subsystem: str = "client",
buckets: Iterable[float] = (
0.005,
0.01,
0.025,
0.05,
0.1,
0.25,
0.5,
1.0,
2.5,
5.0,
10.0,
),
registry: CollectorRegistry = REGISTRY,
)
Metrics sink that records to Prometheus (needs the prometheus extra).
Exposes a request-duration histogram and a request counter, labeled by client, method, route, and status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace
|
str
|
Prometheus metric namespace prefix. |
'asyncly'
|
subsystem
|
str
|
Prometheus metric subsystem prefix. |
'client'
|
buckets
|
Iterable[float]
|
Histogram bucket boundaries in seconds. |
(0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0)
|
registry
|
CollectorRegistry
|
Collector registry to register the metrics on. |
REGISTRY
|
Source code in asyncly/client/metrics/sinks/prometheus.py
asyncly.client.metrics.sinks.opentelemetry.OpenTelemetrySink
¶
Metrics sink backed by OpenTelemetry (needs the opentelemetry extra).
Records request counts, durations, and errors through the given Meter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meter
|
Meter
|
An OpenTelemetry |
required |
Source code in asyncly/client/metrics/sinks/opentelemetry.py
asyncly.client.metrics.route_resolver.default_route_resolver
¶
Normalize a URL path into a low-cardinality route label.
Numeric and UUID-like path segments are replaced with :id so that, for
example, /cats/42 and /cats/7 both map to /cats/:id. Used as the
default route label for client metrics.