-
Notifications
You must be signed in to change notification settings - Fork 30
/
lib.rs
73 lines (71 loc) · 2.07 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! # Actix Web OpenTelemetry
//!
//! [OpenTelemetry](https://opentelemetry.io/) integration for [Actix Web](https://actix.rs/).
//!
//! This crate allows you to easily instrument client and server requests.
//!
//! * Client requests can be traced by using the [`with_tracing`] function.
//! * Server requests can be traced by using the [`RequestTracing`] struct.
//!
//! [`with_tracing`]: fn.with_tracing.html
//! [`RequestTracing`]: struct.RequestTracing.html
//!
//! ### Client Request Example:
//! ```rust,no_run
//! use actix_web::client;
//! use futures::Future;
//!
//! async fn execute_request(client: &client::Client) -> Result<(), client::SendRequestError> {
//! let mut res = actix_web_opentelemetry::with_tracing(
//! client.get("http://localhost:8080"),
//! |request| request.send()
//! )
//! .await;
//!
//! res.and_then(|res| {
//! println!("Response: {:?}", res);
//! Ok(())
//! })
//! }
//! ```
//!
//! ### Server middlware example:
//! ```rust,no_run
//! use actix_web::{web, App, HttpServer};
//! use actix_web_opentelemetry::RequestTracing;
//! use opentelemetry::api;
//!
//! fn init_tracer() {
//! // Replace this no-op provider with something like:
//! // https://docs.rs/opentelemetry-jaeger
//! opentelemetry::global::set_provider(api::NoopProvider {});
//! }
//!
//! async fn index() -> &'static str {
//! "Hello world!"
//! }
//!
//! #[actix_rt::main]
//! async fn main() -> std::io::Result<()> {
//! init_tracer();
//! HttpServer::new(|| {
//! App::new()
//! .wrap(RequestTracing::default())
//! .service(web::resource("/").to(index))
//! })
//! .bind("127.0.0.1:8080")?
//! .run()
//! .await
//! }
//! ```
//!
#![deny(missing_docs, unreachable_pub, missing_debug_implementations)]
#![cfg_attr(test, deny(warnings))]
mod client;
mod middleware;
pub use {
client::with_tracing,
middleware::metrics::{RequestMetrics, RequestMetricsMiddleware},
middleware::route_formatter::{RouteFormatter, UuidWildcardFormatter},
middleware::trace::RequestTracing,
};