Skip to content

Add http request related metrics in observe::MetricsLayer #5794

@Xuanwo

Description

@Xuanwo

By adding the context concept, we can now include HTTP metrics in observe::MetricsLayer. In general, we have full access to HttpFetch, allowing us to wrap our own logic around it. Based on this, we can add metrics for HTTP request duration in seconds and track the number of bytes sent.

My current plan is to add the following metrics:

  • http_request_duration_seconds: Histogram of time spent during http requests
  • http_request_bytes: Histogram of the bytes transferred during http requests

Available labels includes scheme, namespace, root, operation


We will need to implement the following new methods for different metrics layers:

/// Observe the http request duration in seconds.
fn observe_http_request_duration_seconds(
    &self,
    info: Arc<AccessorInfo>,
    op: Operation,
    duration: Duration,
) {
    let _ = (info, op, duration);
}

/// Observe the operation bytes happened in http request like read and write.
fn observe_http_request_bytes(&self, info: Arc<AccessorInfo>, op: Operation, bytes: usize) {
    let _ = (info, op, bytes);
}

Refer to the OtelMetricsLayer as an example: #5800

Metrics

Update Layers for http request metrics

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions