From 38775c3ba3ff32bff35e57158f8eb3587eb91264 Mon Sep 17 00:00:00 2001 From: Fangdun Tsai Date: Tue, 6 Aug 2024 05:09:23 +0800 Subject: [PATCH] chore(deps): hyper v1.4 --- Cargo.toml | 116 +++++++++--------- examples/compression/src/main.rs | 2 - examples/cors/src/main.rs | 2 - examples/csrf/src/main.rs | 2 - examples/databases/sea-orm/Cargo.toml | 5 +- examples/databases/sea-orm/src/main.rs | 2 - examples/forms/form/src/main.rs | 2 - examples/forms/multipart/Cargo.toml | 10 +- examples/forms/multipart/src/main.rs | 2 - examples/graceful-shutdown/src/main.rs | 2 - examples/hello-world/src/main.rs | 2 - examples/htmlx/Cargo.toml | 2 +- examples/htmlx/src/main.rs | 2 - examples/limits/src/main.rs | 2 - examples/otel/metrics/src/main.rs | 2 - examples/otel/tracing/Cargo.toml | 10 +- examples/otel/tracing/src/main.rs | 9 +- examples/routing/openapi/Cargo.toml | 4 +- examples/routing/openapi/src/main.rs | 1 - examples/routing/todos/src/main.rs | 2 - examples/rustls/src/main.rs | 2 - examples/session/src/main.rs | 2 - examples/sse/src/main.rs | 2 - examples/static-files/embed/src/main.rs | 2 - examples/static-files/include-dir/src/main.rs | 1 - examples/static-files/serve/src/main.rs | 2 - examples/static-routes/src/main.rs | 2 - examples/templates/askama/src/main.rs | 2 - examples/templates/markup/src/main.rs | 1 - examples/templates/maud/src/main.rs | 1 - examples/templates/minijinja/Cargo.toml | 3 +- examples/templates/minijinja/src/main.rs | 1 - examples/templates/tera/Cargo.toml | 2 +- examples/templates/tera/src/main.rs | 2 - examples/tracing/src/main.rs | 2 - examples/unix-socket/src/main.rs | 1 - examples/websocket-chat/src/main.rs | 2 - viz-core/src/middleware/otel/metrics.rs | 10 +- viz-core/src/middleware/otel/tracing.rs | 51 +++++--- viz-core/tests/error.rs | 2 + viz-core/tests/from_request.rs | 2 + viz-core/tests/handler.rs | 2 + viz-core/tests/into_response.rs | 2 + viz-core/tests/request.rs | 2 + viz-core/tests/response.rs | 2 + viz-core/tests/type_json.rs | 2 + viz-core/tests/type_realip.rs | 2 + viz-macros/tests/handler.rs | 2 + viz-test/Cargo.toml | 6 +- 49 files changed, 146 insertions(+), 150 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3ba89881..f47ea68c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,41 +1,41 @@ [workspace] resolver = "2" members = [ - "viz", - "viz-core", - "viz-handlers", - "viz-macros", - "viz-router", - "viz-tower", - "viz-smol", - "viz-test", - - "examples/hello-world", - "examples/unix-socket", - "examples/static-files/embed", - "examples/static-files/serve", - "examples/static-files/include-dir", - "examples/limits", - "examples/forms/form", - "examples/forms/multipart", - "examples/websocket-chat", - "examples/sse", - "examples/session", - "examples/csrf", - "examples/cors", - "examples/rustls", - "examples/static-routes", - "examples/routing/todos", - "examples/routing/openapi", - "examples/otel/*", - "examples/compression", - "examples/templates/*", - "examples/tracing", - "examples/graceful-shutdown", - "examples/databases/*", - "examples/htmlx", - "examples/tower", - "examples/smol", + "viz", + "viz-core", + "viz-handlers", + "viz-macros", + "viz-router", + "viz-tower", + "viz-smol", + "viz-test", + + "examples/hello-world", + "examples/unix-socket", + "examples/static-files/embed", + "examples/static-files/serve", + "examples/static-files/include-dir", + "examples/limits", + "examples/forms/form", + "examples/forms/multipart", + "examples/websocket-chat", + "examples/sse", + "examples/session", + "examples/csrf", + "examples/cors", + "examples/rustls", + "examples/static-routes", + "examples/routing/todos", + "examples/routing/openapi", + "examples/otel/*", + "examples/compression", + "examples/templates/*", + "examples/tracing", + "examples/graceful-shutdown", + "examples/databases/*", + "examples/htmlx", + "examples/tower", + "examples/smol", ] [workspace.package] @@ -61,7 +61,7 @@ viz-smol = { version = "0.1.9", path = "viz-smol" } anyhow = "1.0" async-trait = "0.1" -bytes = "1.6" +bytes = "1.7" serde = "1.0" serde_derive = "1.0" serde_json = "1.0" @@ -80,33 +80,39 @@ sessions-memory = "0.6" # http headers = "0.4" http = "1.1" -http-body = "1" +http-body = "1.0" http-body-util = "0.1" -hyper = { version = "1.3" } -hyper-util = { version = "0.1.5", features = ["server", "tokio" ] } +hyper = { version = "1.4" } +hyper-util = { version = "0.1.9", features = ["server", "tokio"] } mime = "0.3" mime_guess = "2.0" percent-encoding = "2.3" hex = "0.4" -rust-embed = "8" +rust-embed = "8.5" futures-util = "0.3" -rustls-pemfile = "2.0" tokio = { version = "1.38", features = ["net"] } -tokio-native-tls = "0.3" -tokio-rustls = "0.26" tokio-stream = "0.1" -tokio-tungstenite = "0.21" +tokio-tungstenite = "0.24" tokio-util = "0.7" +# TLS +rustls-pemfile = "2.1" +tokio-native-tls = "0.3" +tokio-rustls = "0.26" + # OpenTelemetry -opentelemetry = { version = "0.23", default-features = false } -opentelemetry_sdk = { version = "0.23", default-features = false } -opentelemetry-prometheus = { version = "0.16", features = [ - "prometheus-encoding", +opentelemetry = { version = "0.24", default-features = false } +opentelemetry_sdk = { version = "0.24", default-features = false } +opentelemetry-otlp = { version = "0.17", default-features = false, features = [ + "trace", + "http-proto", +] } +opentelemetry-prometheus = { version = "0.17", features = [ + "prometheus-encoding", ] } -opentelemetry-semantic-conventions = { version = "0.15" } +opentelemetry-semantic-conventions = { version = "0.16" } prometheus = "0.13" # Tracing @@ -114,15 +120,15 @@ tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } # Tower -tower = "0.4" -tower-http = "0.5" +tower = "0.5" +tower-http = "0.6" # Soml async-channel = "2.3" -async-executor = "1.11" +async-executor = "1.13" async-io = "2.3" async-net = "2.0" -smol-hyper = "0.1.1" +smol-hyper = "0.1" smol-macros = "0.1" macro_rules_attribute = "0.2" futures-lite = { version = "2.3", default-features = false, features = ["std"] } @@ -150,13 +156,13 @@ missing_debug_implementations = "warn" missing_docs = "warn" [workspace.lints.clippy] -all = "warn" # Downgrade deny-by-default lints +all = "warn" # Downgrade deny-by-default lints pedantic = "warn" missing_errors_doc = { level = "allow", priority = 1 } module_name_repetitions = { level = "allow", priority = 1 } too_many_lines = { level = "allow", priority = 1 } type_complexity = { level = "allow", priority = 1 } -lint_groups_priority = { level = "allow", priority = 1 } # https://github.com/rust-lang/rust-clippy/issues/12270 +lint_groups_priority = { level = "allow", priority = 1 } # https://github.com/rust-lang/rust-clippy/issues/12270 [workspace.lints.rustdoc] private_intra_doc_links = 'allow' diff --git a/examples/compression/src/main.rs b/examples/compression/src/main.rs index 839b3a3a..0761916e 100644 --- a/examples/compression/src/main.rs +++ b/examples/compression/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::net::SocketAddr; use tokio::net::TcpListener; diff --git a/examples/cors/src/main.rs b/examples/cors/src/main.rs index f62b84df..77e23496 100644 --- a/examples/cors/src/main.rs +++ b/examples/cors/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::net::SocketAddr; use tokio::net::TcpListener; use viz::{get, middleware::cors, serve, Method, Request, Result, Router}; diff --git a/examples/csrf/src/main.rs b/examples/csrf/src/main.rs index e6878b35..fb76f1fe 100644 --- a/examples/csrf/src/main.rs +++ b/examples/csrf/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::{net::SocketAddr, time::Duration}; use tokio::net::TcpListener; diff --git a/examples/databases/sea-orm/Cargo.toml b/examples/databases/sea-orm/Cargo.toml index 36e291a1..42f38e86 100644 --- a/examples/databases/sea-orm/Cargo.toml +++ b/examples/databases/sea-orm/Cargo.toml @@ -9,7 +9,10 @@ viz = { workspace = true, features = ["serve"] } serde.workspace = true tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } -sea-orm = { version = "1", features = ["runtime-tokio-rustls", "sqlx-sqlite"] } +sea-orm = { version = "1.0", features = [ + "runtime-tokio-rustls", + "sqlx-sqlite", +] } [lints] workspace = true diff --git a/examples/databases/sea-orm/src/main.rs b/examples/databases/sea-orm/src/main.rs index ced916ca..5880f3a2 100644 --- a/examples/databases/sea-orm/src/main.rs +++ b/examples/databases/sea-orm/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - //! `SeaOrm` example for Viz framework. use sea_orm_example::{api, db::init_db}; use std::{env, net::SocketAddr, path::PathBuf}; diff --git a/examples/forms/form/src/main.rs b/examples/forms/form/src/main.rs index 9624979f..aec7e7ae 100644 --- a/examples/forms/form/src/main.rs +++ b/examples/forms/form/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use serde::{Deserialize, Serialize}; use std::net::SocketAddr; use tokio::net::TcpListener; diff --git a/examples/forms/multipart/Cargo.toml b/examples/forms/multipart/Cargo.toml index 373fd604..f171bad1 100644 --- a/examples/forms/multipart/Cargo.toml +++ b/examples/forms/multipart/Cargo.toml @@ -9,10 +9,10 @@ viz.workspace = true futures-util.workspace = true tokio = { workspace = true, features = [ - "fs", - "io-util", - "macros", - "rt-multi-thread", + "fs", + "io-util", + "macros", + "rt-multi-thread", ] } -tempfile = "3.10" +tempfile = "3.0" diff --git a/examples/forms/multipart/src/main.rs b/examples/forms/multipart/src/main.rs index 83e661d0..763bc5a8 100644 --- a/examples/forms/multipart/src/main.rs +++ b/examples/forms/multipart/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use futures_util::TryStreamExt; use std::{fs::File, net::SocketAddr}; use tempfile::tempdir; diff --git a/examples/graceful-shutdown/src/main.rs b/examples/graceful-shutdown/src/main.rs index 3a2b112a..e03e72de 100644 --- a/examples/graceful-shutdown/src/main.rs +++ b/examples/graceful-shutdown/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::net::SocketAddr; use tokio::net::TcpListener; use tokio::signal; diff --git a/examples/hello-world/src/main.rs b/examples/hello-world/src/main.rs index 9d6e7fa3..40e90d9e 100644 --- a/examples/hello-world/src/main.rs +++ b/examples/hello-world/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::{net::SocketAddr, str::FromStr}; use tokio::net::TcpListener; use viz::{serve, Request, Result, Router}; diff --git a/examples/htmlx/Cargo.toml b/examples/htmlx/Cargo.toml index faebf10f..9b5b01d6 100644 --- a/examples/htmlx/Cargo.toml +++ b/examples/htmlx/Cargo.toml @@ -11,4 +11,4 @@ serde = { workspace = true, features = ["derive"] } serde_json.workspace = true tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } -handlebars = { version = "6", features = ["dir_source"] } +handlebars = { version = "6.0", features = ["dir_source"] } diff --git a/examples/htmlx/src/main.rs b/examples/htmlx/src/main.rs index 91d2fd32..a0a69cb2 100644 --- a/examples/htmlx/src/main.rs +++ b/examples/htmlx/src/main.rs @@ -1,5 +1,3 @@ -// #![deny(warnings)] - use handlebars::{DirectorySourceOptions, Handlebars}; use serde::{Deserialize, Serialize}; use serde_json::json; diff --git a/examples/limits/src/main.rs b/examples/limits/src/main.rs index 0f2da782..2b12cd9e 100644 --- a/examples/limits/src/main.rs +++ b/examples/limits/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::net::SocketAddr; use tokio::net::TcpListener; use viz::{ diff --git a/examples/otel/metrics/src/main.rs b/examples/otel/metrics/src/main.rs index 45195ea2..e2196e3f 100644 --- a/examples/otel/metrics/src/main.rs +++ b/examples/otel/metrics/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::net::SocketAddr; use tokio::net::TcpListener; diff --git a/examples/otel/tracing/Cargo.toml b/examples/otel/tracing/Cargo.toml index f39e1b18..71b3dfcc 100644 --- a/examples/otel/tracing/Cargo.toml +++ b/examples/otel/tracing/Cargo.toml @@ -9,5 +9,11 @@ viz = { workspace = true, features = ["otel-tracing"] } tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } opentelemetry.workspace = true -opentelemetry_sdk = { workspace = true, features = ["trace", "rt-tokio-current-thread"] } -opentelemetry-otlp = { version = "0.17", default-features = false, features = ["trace", "http-proto"] } +opentelemetry_sdk = { workspace = true, features = [ + "trace", + "rt-tokio-current-thread", +] } +opentelemetry-otlp = { workspace = true, default-features = false, features = [ + "trace", + "http-proto", +] } diff --git a/examples/otel/tracing/src/main.rs b/examples/otel/tracing/src/main.rs index c1e28518..d5a63a69 100644 --- a/examples/otel/tracing/src/main.rs +++ b/examples/otel/tracing/src/main.rs @@ -1,16 +1,15 @@ -#![deny(warnings)] #![allow(clippy::unused_async)] use opentelemetry::global; use opentelemetry_sdk::{ runtime::TokioCurrentThread, - {propagation::TraceContextPropagator, trace::Tracer}, + {propagation::TraceContextPropagator, trace::TracerProvider}, }; use std::net::SocketAddr; use tokio::net::TcpListener; use viz::{middleware::otel, serve, Request, Result, Router}; -fn init_tracer() -> Tracer { +fn init_tracer_provider() -> TracerProvider { global::set_text_map_propagator(TraceContextPropagator::new()); opentelemetry_otlp::new_pipeline() .tracing() @@ -29,12 +28,12 @@ async fn main() -> Result<()> { let listener = TcpListener::bind(addr).await?; println!("listening on http://{addr}"); - let tracer = init_tracer(); + let tracer_provider = init_tracer_provider(); let app = Router::new() .get("/", index) .get("/:username", index) - .with(otel::tracing::Config::new(tracer)); + .with(otel::tracing::Config::new(tracer_provider, None)); if let Err(e) = serve(listener, app).await { println!("{e}"); diff --git a/examples/routing/openapi/Cargo.toml b/examples/routing/openapi/Cargo.toml index 43c07a2c..c411ffe0 100644 --- a/examples/routing/openapi/Cargo.toml +++ b/examples/routing/openapi/Cargo.toml @@ -12,5 +12,5 @@ serde = { workspace = true, features = ["derive"] } serde_json.workspace = true tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } -utoipa = "4" -utoipa-swagger-ui = "7" +utoipa = "4.0" +utoipa-swagger-ui = "7.0" diff --git a/examples/routing/openapi/src/main.rs b/examples/routing/openapi/src/main.rs index 2a22f9b0..f51eb03a 100644 --- a/examples/routing/openapi/src/main.rs +++ b/examples/routing/openapi/src/main.rs @@ -1,4 +1,3 @@ -#![deny(warnings)] #![allow(clippy::unused_async)] #![allow(clippy::needless_pass_by_value)] diff --git a/examples/routing/todos/src/main.rs b/examples/routing/todos/src/main.rs index c0d2f1fc..1bf2f769 100644 --- a/examples/routing/todos/src/main.rs +++ b/examples/routing/todos/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::{ net::SocketAddr, sync::{Arc, Mutex, PoisonError}, diff --git a/examples/rustls/src/main.rs b/examples/rustls/src/main.rs index d0b26db3..31f0f6d0 100644 --- a/examples/rustls/src/main.rs +++ b/examples/rustls/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::{net::SocketAddr, sync::Arc}; use tokio::net::TcpListener; use viz::{get, serve, tls, Request, Result, Router}; diff --git a/examples/session/src/main.rs b/examples/session/src/main.rs index 44f87c06..8be0fd3b 100644 --- a/examples/session/src/main.rs +++ b/examples/session/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::net::SocketAddr; use tokio::net::TcpListener; diff --git a/examples/sse/src/main.rs b/examples/sse/src/main.rs index 1fc2ffcc..57794b1e 100644 --- a/examples/sse/src/main.rs +++ b/examples/sse/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use futures_util::StreamExt; use std::{net::SocketAddr, sync::Arc}; use systemstat::{Platform, System}; diff --git a/examples/static-files/embed/src/main.rs b/examples/static-files/embed/src/main.rs index e6d7283f..5f6ff4c0 100644 --- a/examples/static-files/embed/src/main.rs +++ b/examples/static-files/embed/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::net::SocketAddr; use tokio::net::TcpListener; use viz::{handlers::embed, serve, Result, Router, StatusCode}; diff --git a/examples/static-files/include-dir/src/main.rs b/examples/static-files/include-dir/src/main.rs index 0f330ee5..5441a976 100644 --- a/examples/static-files/include-dir/src/main.rs +++ b/examples/static-files/include-dir/src/main.rs @@ -1,4 +1,3 @@ -#![deny(warnings)] #![allow(clippy::unused_async)] use http_body_util::Full; diff --git a/examples/static-files/serve/src/main.rs b/examples/static-files/serve/src/main.rs index ff197a57..57300fde 100644 --- a/examples/static-files/serve/src/main.rs +++ b/examples/static-files/serve/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::{env, net::SocketAddr, path::PathBuf}; use tokio::net::TcpListener; use viz::{handlers::serve, serve, Request, Response, ResponseExt, Result, Router}; diff --git a/examples/static-routes/src/main.rs b/examples/static-routes/src/main.rs index 7bb1887d..f1036828 100644 --- a/examples/static-routes/src/main.rs +++ b/examples/static-routes/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use hyper::server::conn::http1; use hyper::service::service_fn; use std::{ diff --git a/examples/templates/askama/src/main.rs b/examples/templates/askama/src/main.rs index 0c5939c6..d4171f82 100644 --- a/examples/templates/askama/src/main.rs +++ b/examples/templates/askama/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::net::SocketAddr; use askama::Template; diff --git a/examples/templates/markup/src/main.rs b/examples/templates/markup/src/main.rs index 6cc2e383..af4f62f2 100644 --- a/examples/templates/markup/src/main.rs +++ b/examples/templates/markup/src/main.rs @@ -1,4 +1,3 @@ -#![deny(warnings)] #![allow(clippy::must_use_candidate)] #![allow(clippy::inherent_to_string_shadow_display)] diff --git a/examples/templates/maud/src/main.rs b/examples/templates/maud/src/main.rs index 36c4c69e..08025b5f 100644 --- a/examples/templates/maud/src/main.rs +++ b/examples/templates/maud/src/main.rs @@ -1,4 +1,3 @@ -#![deny(warnings)] #![allow(clippy::must_use_candidate)] #![allow(clippy::inherent_to_string_shadow_display)] diff --git a/examples/templates/minijinja/Cargo.toml b/examples/templates/minijinja/Cargo.toml index f0dd8128..a5918b09 100644 --- a/examples/templates/minijinja/Cargo.toml +++ b/examples/templates/minijinja/Cargo.toml @@ -9,4 +9,5 @@ viz.workspace = true serde.workspace = true tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } -minijinja = { version = "2", features = ["loader"] } + +minijinja = { version = "2.0", features = ["loader"] } diff --git a/examples/templates/minijinja/src/main.rs b/examples/templates/minijinja/src/main.rs index bfeed9a3..a6244caf 100644 --- a/examples/templates/minijinja/src/main.rs +++ b/examples/templates/minijinja/src/main.rs @@ -1,4 +1,3 @@ -#![deny(warnings)] #![allow(clippy::unused_async)] use std::{env, net::SocketAddr, path::PathBuf, sync::LazyLock}; diff --git a/examples/templates/tera/Cargo.toml b/examples/templates/tera/Cargo.toml index abf31146..9f11c58a 100644 --- a/examples/templates/tera/Cargo.toml +++ b/examples/templates/tera/Cargo.toml @@ -10,4 +10,4 @@ viz.workspace = true serde.workspace = true tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } -tera = "1.19" +tera = "1.0" diff --git a/examples/templates/tera/src/main.rs b/examples/templates/tera/src/main.rs index 50680ab0..5c71a7da 100644 --- a/examples/templates/tera/src/main.rs +++ b/examples/templates/tera/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::{net::SocketAddr, sync::LazyLock}; use serde::Serialize; diff --git a/examples/tracing/src/main.rs b/examples/tracing/src/main.rs index 2565e3c9..fc6c9183 100644 --- a/examples/tracing/src/main.rs +++ b/examples/tracing/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::net::SocketAddr; use tokio::net::TcpListener; use tracing::{debug, error, info, instrument}; diff --git a/examples/unix-socket/src/main.rs b/examples/unix-socket/src/main.rs index ec1f6cf8..d5cce33f 100644 --- a/examples/unix-socket/src/main.rs +++ b/examples/unix-socket/src/main.rs @@ -3,7 +3,6 @@ //! ```sh //! curl --unix-socket /tmp/viz.sock http://localhost/ //! ``` -#![deny(warnings)] #[cfg(unix)] #[tokio::main] diff --git a/examples/websocket-chat/src/main.rs b/examples/websocket-chat/src/main.rs index 888fba6b..782143d2 100644 --- a/examples/websocket-chat/src/main.rs +++ b/examples/websocket-chat/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use futures_util::{SinkExt, StreamExt}; use std::net::SocketAddr; use tokio::net::TcpListener; diff --git a/viz-core/src/middleware/otel/metrics.rs b/viz-core/src/middleware/otel/metrics.rs index 4837d05e..b744881c 100644 --- a/viz-core/src/middleware/otel/metrics.rs +++ b/viz-core/src/middleware/otel/metrics.rs @@ -6,7 +6,7 @@ use std::time::SystemTime; use http::uri::Scheme; use opentelemetry::{ - metrics::{Histogram, Meter, Unit, UpDownCounter}, + metrics::{Histogram, Meter, UpDownCounter}, KeyValue, }; use opentelemetry_semantic_conventions::trace::{ @@ -39,25 +39,25 @@ impl Config { .with_description( "Measures the number of concurrent HTTP requests that are currently in-flight.", ) - .with_unit(Unit::new("{request}")) + .with_unit("{request}") .init(); let duration = meter .f64_histogram(HTTP_SERVER_DURATION) .with_description("Measures the duration of inbound HTTP requests.") - .with_unit(Unit::new("s")) + .with_unit("s") .init(); let request_size = meter .u64_histogram(HTTP_SERVER_REQUEST_SIZE) .with_description("Measures the size of HTTP request messages (compressed).") - .with_unit(Unit::new("By")) + .with_unit("By") .init(); let response_size = meter .u64_histogram(HTTP_SERVER_RESPONSE_SIZE) .with_description("Measures the size of HTTP request messages (compressed).") - .with_unit(Unit::new("By")) + .with_unit("By") .init(); Self { diff --git a/viz-core/src/middleware/otel/tracing.rs b/viz-core/src/middleware/otel/tracing.rs index 2d9b36a7..09de836b 100644 --- a/viz-core/src/middleware/otel/tracing.rs +++ b/viz-core/src/middleware/otel/tracing.rs @@ -2,19 +2,19 @@ //! //! [`OpenTelemetry`]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md -use std::sync::Arc; - use http::{uri::Scheme, HeaderValue}; use opentelemetry::{ global, propagation::Extractor, - trace::{FutureExt as OtelFutureExt, Span, SpanKind, Status, TraceContextExt, Tracer}, + trace::{ + FutureExt as OtelFutureExt, Span, SpanKind, Status, TraceContextExt, Tracer, TracerProvider, + }, Context, KeyValue, }; use opentelemetry_semantic_conventions::trace::{ - CLIENT_ADDRESS, EXCEPTION_MESSAGE, HTTP_REQUEST_BODY_SIZE, HTTP_REQUEST_METHOD, - HTTP_RESPONSE_BODY_SIZE, HTTP_RESPONSE_STATUS_CODE, HTTP_ROUTE, NETWORK_PROTOCOL_VERSION, - SERVER_ADDRESS, SERVER_PORT, URL_PATH, URL_QUERY, URL_SCHEME, USER_AGENT_ORIGINAL, + CLIENT_ADDRESS, EXCEPTION_MESSAGE, HTTP_REQUEST_METHOD, HTTP_RESPONSE_STATUS_CODE, HTTP_ROUTE, + NETWORK_PROTOCOL_VERSION, SERVER_ADDRESS, SERVER_PORT, URL_PATH, URL_QUERY, URL_SCHEME, + USER_AGENT_ORIGINAL, }; use crate::{ @@ -23,28 +23,34 @@ use crate::{ Handler, IntoResponse, Request, RequestExt, Response, ResponseExt, Result, Transform, }; +const HTTP_REQUEST_BODY_SIZE: &str = "http.request.body.size"; +const HTTP_RESPONSE_BODY_SIZE: &str = "http.response.body.size"; + /// `OpenTelemetry` tracing config. #[derive(Debug)] pub struct Config { - tracer: Arc, + tracer: T, + name: Option, } impl Config { /// Creats new `OpenTelemetry` tracing config. - pub fn new(t: T) -> Self { - Self { - tracer: Arc::new(t), - } + pub fn new(t: T, name: Option) -> Self { + Self { tracer: t, name } } } -impl Transform for Config { +impl Transform for Config +where + T: Clone, +{ type Output = TracingMiddleware; fn transform(&self, h: H) -> Self::Output { TracingMiddleware { h, tracer: self.tracer.clone(), + name: self.name.clone().unwrap_or("tracing".to_string()), } } } @@ -53,7 +59,8 @@ impl Transform for Config { #[derive(Debug, Clone)] pub struct TracingMiddleware { h: H, - tracer: Arc, + tracer: T, + name: String, } #[crate::async_trait] @@ -61,8 +68,9 @@ impl Handler for TracingMiddleware where H: Handler>, O: IntoResponse, - T: Tracer + Send + Sync + Clone + 'static, - T::Span: Send + Sync + 'static, + T: TracerProvider + Send + Sync + Clone + 'static, + T::Tracer: Tracer + Send + Sync + 'static, + ::Span: Span + Send + Sync + 'static, { type Output = Result; @@ -74,12 +82,17 @@ where let http_route = &req.route_info().pattern; let attributes = build_attributes(&req, http_route.as_str()); - let mut span = self + let tracer = self .tracer - .span_builder(format!("{} {}", req.method(), http_route)) - .with_kind(SpanKind::Server) + .tracer_builder(self.name.clone()) .with_attributes(attributes) - .start_with_context(&*self.tracer, &parent_context); + .build(); + let mut span = tracer.build_with_context( + tracer + .span_builder(format!("{} {}", req.method(), http_route)) + .with_kind(SpanKind::Server), + &parent_context, + ); span.add_event("request.started".to_string(), vec![]); diff --git a/viz-core/tests/error.rs b/viz-core/tests/error.rs index 3acfaee5..68c413c7 100644 --- a/viz-core/tests/error.rs +++ b/viz-core/tests/error.rs @@ -1,3 +1,5 @@ +//! Error test cases + use std::error::Error as StdError; use viz_core::{Body, Error, Response, StatusCode}; diff --git a/viz-core/tests/from_request.rs b/viz-core/tests/from_request.rs index ac2a00a5..d2c9a9f1 100644 --- a/viz-core/tests/from_request.rs +++ b/viz-core/tests/from_request.rs @@ -1,3 +1,5 @@ +//! HTTP Request test cases + use headers::HeaderValue; use viz_core::{ header::{CONTENT_LENGTH, CONTENT_TYPE}, diff --git a/viz-core/tests/handler.rs b/viz-core/tests/handler.rs index 3d15f627..6371ec99 100644 --- a/viz-core/tests/handler.rs +++ b/viz-core/tests/handler.rs @@ -1,3 +1,5 @@ +//! HTTP Handler test cases + #![allow(dead_code)] #![allow(non_local_definitions)] #![allow(clippy::unused_async)] diff --git a/viz-core/tests/into_response.rs b/viz-core/tests/into_response.rs index a02e638f..6b7ac457 100644 --- a/viz-core/tests/into_response.rs +++ b/viz-core/tests/into_response.rs @@ -1,3 +1,5 @@ +//! HTTP Response test cases + use headers::{ContentLength, ContentType, HeaderMapExt}; use viz_core::{Error, IntoResponse, Response, StatusCode}; diff --git a/viz-core/tests/request.rs b/viz-core/tests/request.rs index ae52a93d..fd5d7bef 100644 --- a/viz-core/tests/request.rs +++ b/viz-core/tests/request.rs @@ -1,3 +1,5 @@ +//! HTTP Request test cases + use headers::{ContentType, HeaderValue}; use http::uri::Scheme; use serde::{Deserialize, Serialize}; diff --git a/viz-core/tests/response.rs b/viz-core/tests/response.rs index ea701a48..ea6e3b1e 100644 --- a/viz-core/tests/response.rs +++ b/viz-core/tests/response.rs @@ -1,3 +1,5 @@ +//! HTTP Response test cases + #![feature(test)] extern crate test; diff --git a/viz-core/tests/type_json.rs b/viz-core/tests/type_json.rs index f31c2301..8bf611b0 100644 --- a/viz-core/tests/type_json.rs +++ b/viz-core/tests/type_json.rs @@ -1,3 +1,5 @@ +//! JSON type test cases + use viz_core::{types::Json, IntoResponse, ResponseExt}; #[test] diff --git a/viz-core/tests/type_realip.rs b/viz-core/tests/type_realip.rs index 06b69f22..669af434 100644 --- a/viz-core/tests/type_realip.rs +++ b/viz-core/tests/type_realip.rs @@ -1,3 +1,5 @@ +//! RealIp type test cases + use viz_core::{ header::{HeaderValue, FORWARDED}, types::RealIp, diff --git a/viz-macros/tests/handler.rs b/viz-macros/tests/handler.rs index eeb37cb2..2f00b638 100644 --- a/viz-macros/tests/handler.rs +++ b/viz-macros/tests/handler.rs @@ -1,3 +1,5 @@ +//! Handler test cases + #![allow(clippy::unused_async)] #![allow(clippy::unnecessary_wraps)] diff --git a/viz-test/Cargo.toml b/viz-test/Cargo.toml index a07944cb..0dc94d4c 100644 --- a/viz-test/Cargo.toml +++ b/viz-test/Cargo.toml @@ -26,7 +26,7 @@ hyper.workspace = true mime.workspace = true serde.workspace = true sessions = { workspace = true, features = ["memory"] } -nano-id = "0.4" - -reqwest = { version = "0.12", features = ["cookies", "json", "multipart"]} tokio = { workspace = true, features = ["full"] } + +nano-id = "0.4" +reqwest = { version = "0.12", features = ["cookies", "json", "multipart"] }