Skip to content

Metrics collection for Services #2

@yazaddaruvala

Description

@yazaddaruvala

I know this will not be looked at for a while, and this might get moved to a different repo, but I wanted to get my thoughts written down.

I'd love to get more thoughts on two things:

  • We need a trait for Metrics, that a service(via middleware) can then use.
pub trait Metric {
    /// Name of service
    fn service_name(&self) -> &str;

    /// Name of api
    fn api_name(&self) -> &str;

    /// Request Id
    fn request_id(&self) -> &str; // Or `usize` or `T`

    /// Start time for the call; To calculate latency
    fn start(&self) -> Instant;

    /// End time for the call; To calculate latency
    fn end(&self) -> Instant;

    // There are some more here we can discuss later: [children_calls, error_type, or some generic "other_info"]
}
  • How would we end up returning such an object from the Future?
Future<(Response, Metrics), (Error, Metrics)>

This feels really awkward, and it breaks the fluency of Futures with .map and such. What other options do we have? Given the nature of Futures (i.e. long tasks), and the importance of metrics, it could make sense to bake in Metrics into the Future trait, but that may not be possible in a zero-cost way. Does it make sense for Tokio-Service to implement its own Future which has Metrics built-in?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions