pub trait MetricsCallbackProvider:
Send
+ Sync
+ Clone
+ 'static {
// Required methods
fn on_request(&self, path: String);
fn on_response(
&self,
path: String,
latency: Duration,
status: u16,
grpc_status_code: Code,
);
// Provided methods
fn on_error(&self, _latency: Duration, _grpc_status_code: Code) { ... }
fn on_start(&self, _path: &str) { ... }
fn on_drop(&self, _path: &str) { ... }
}Expand description
The trait to be implemented when want to be notified about a new request and related metrics around it. When a request is performed (up to the point that a response is created) the on_response method is called with the corresponding metrics details. The on_request method will be called when the request is received, but not further processing has happened at this point.
Required Methods§
Sourcefn on_request(&self, path: String)
fn on_request(&self, path: String)
Method will be called when a request has been received.
path: the endpoint uri path
Sourcefn on_response(
&self,
path: String,
latency: Duration,
status: u16,
grpc_status_code: Code,
)
fn on_response( &self, path: String, latency: Duration, status: u16, grpc_status_code: Code, )
Method to be called from the server when a request is performed.
path: the endpoint uri path
latency: the time when the request was received and when the response
was created status: the http status code of the response
grpc_status_code: the grpc status code (see https://github.com/grpc/grpc/blob/master/doc/statuscodes.md#status-codes-and-their-use-in-grpc)
Provided Methods§
Sourcefn on_error(&self, _latency: Duration, _grpc_status_code: Code)
fn on_error(&self, _latency: Duration, _grpc_status_code: Code)
Called when a gRPC request fails at the transport/middleware level
(e.g. service panic, connection drop, timeout). gRPC application
errors (non-OK status codes) are NOT reported here — they are
already captured by on_response.
The method path is not available at this layer (tower-http’s
on_failure callback does not receive the response object).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".