pub struct RequestMetrics { /* private fields */ }
Available on crate feature
metrics
only.Expand description
Request metrics tracking
For more information on how to configure Prometheus with OTLP
§Examples
use actix_web::{http, web, App, HttpRequest, HttpResponse, HttpServer, Responder};
use opentelemetry::{global, KeyValue};
use opentelemetry_instrumentation_actix_web::{RequestMetrics, RequestTracing};
use opentelemetry_sdk::{metrics::SdkMeterProvider, Resource};
async fn manual_hello() -> impl Responder {
HttpResponse::Ok().body("Hey there!")
}
#[actix_web::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize STDOUT exporter
let exporter = opentelemetry_stdout::MetricExporter::default();
// set up your meter provider with your exporter(s)
let provider = SdkMeterProvider::builder()
.with_periodic_exporter(exporter)
.with_resource(
// recommended attributes
Resource::builder_empty()
.with_attribute(KeyValue::new("service.name", "my_app"))
.build(),
)
.build();
global::set_meter_provider(provider.clone());
// Run actix server, metrics will be exported periodically
HttpServer::new(move || {
App::new()
.wrap(RequestTracing::new())
.wrap(RequestMetrics::default())
.route("/hey", web::get().to(manual_hello))
})
.bind("localhost:8080")?
.run()
.await?;
//Shutdown the meter provider. This will trigger an export of all metrics.
provider.shutdown()?;
Ok(())
}
Implementations§
Source§impl RequestMetrics
impl RequestMetrics
Sourcepub fn builder() -> RequestMetricsBuilder
pub fn builder() -> RequestMetricsBuilder
Create a builder to configure this middleware
Trait Implementations§
Source§impl Clone for RequestMetrics
impl Clone for RequestMetrics
Source§fn clone(&self) -> RequestMetrics
fn clone(&self) -> RequestMetrics
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for RequestMetrics
impl Debug for RequestMetrics
Source§impl Default for RequestMetrics
impl Default for RequestMetrics
Source§impl<S, B> Transform<S, ServiceRequest> for RequestMetricswhere
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
B: MessageBody + 'static,
impl<S, B> Transform<S, ServiceRequest> for RequestMetricswhere
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
B: MessageBody + 'static,
Source§type Response = ServiceResponse<B>
type Response = ServiceResponse<B>
Responses produced by the service.
Source§type Transform = RequestMetricsMiddleware<S>
type Transform = RequestMetricsMiddleware<S>
The
TransformService
value created by this factorySource§type Future = Ready<Result<<RequestMetrics as Transform<S, ServiceRequest>>::Transform, <RequestMetrics as Transform<S, ServiceRequest>>::InitError>>
type Future = Ready<Result<<RequestMetrics as Transform<S, ServiceRequest>>::Transform, <RequestMetrics as Transform<S, ServiceRequest>>::InitError>>
The future response value.
Source§fn new_transform(&self, service: S) -> Self::Future
fn new_transform(&self, service: S) -> Self::Future
Creates and returns a new Transform component, asynchronously
Auto Trait Implementations§
impl Freeze for RequestMetrics
impl !RefUnwindSafe for RequestMetrics
impl Send for RequestMetrics
impl Sync for RequestMetrics
impl Unpin for RequestMetrics
impl !UnwindSafe for RequestMetrics
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more