diff --git a/Cargo.toml b/Cargo.toml index 025fb5f5..507d8de3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,12 +61,13 @@ thiserror = "1.0" path-tree = "0.7" # http -headers = "0.3" -http = "0.2" -http-body = "=1.0.0-rc.2" -http-body-util = "=0.1.0-rc.3" -hyper = { version = "=1.0.0-rc.4", features = ["server"] } -hyper-util = { git = "https://github.com/hyperium/hyper-util", rev = "63e84bf", features = ["auto"] } +# TODO: wait headers-v1.0 +headers = { git = "https://github.com/hyperium/headers.git", rev = "4400aa9" } +http = "1" +http-body = "1" +http-body-util = "0.1" +hyper = { version = "1", features = ["server"] } +hyper-util = { version = "0.1", features = ["server-auto", "tokio"] } futures-util = "0.3" tokio = { version = "1.33", features = ["net"] } @@ -86,11 +87,12 @@ hex = "0.4" rust-embed = "8" # OpenTelemetry -opentelemetry = { version = "0.20", default-features = false } -opentelemetry-prometheus = { version = "0.13", features = [ +opentelemetry = { version = "0.21", default-features = false } +opentelemetry_sdk = { version = "0.21", default-features = false } +opentelemetry-prometheus = { version = "0.14", features = [ "prometheus-encoding", ] } -opentelemetry-semantic-conventions = { version = "0.12" } +opentelemetry-semantic-conventions = { version = "0.13" } prometheus = "0.13" # Tracing @@ -102,6 +104,7 @@ all-features = true rustdoc-args = ["--cfg", "docsrs"] [profile.dev] +opt-level = 1 split-debuginfo = "unpacked" [profile.dev.package."*"] diff --git a/examples/otel/metrics/Cargo.toml b/examples/otel/metrics/Cargo.toml index c577fbb1..853e4632 100644 --- a/examples/otel/metrics/Cargo.toml +++ b/examples/otel/metrics/Cargo.toml @@ -8,4 +8,5 @@ publish = false viz = { workspace = true, features = ["otel-metrics", "otel-prometheus"] } tokio = { workspace = true, features = [ "rt-multi-thread", "macros" ] } -opentelemetry = { workspace = true, default-features = false, features = ["metrics"]} +opentelemetry = { workspace = true, features = ["metrics"]} +opentelemetry_sdk = { workspace = true, features = ["metrics"] } diff --git a/examples/otel/metrics/src/main.rs b/examples/otel/metrics/src/main.rs index af23ed30..237ae5d6 100644 --- a/examples/otel/metrics/src/main.rs +++ b/examples/otel/metrics/src/main.rs @@ -4,13 +4,10 @@ use std::{net::SocketAddr, sync::Arc}; use tokio::net::TcpListener; -use opentelemetry::{ - global, - sdk::{ - metrics::{self, Aggregation, Instrument, MeterProvider, Stream}, - Resource, - }, - KeyValue, +use opentelemetry::{global, KeyValue}; +use opentelemetry_sdk::{ + metrics::{self, Aggregation, Instrument, MeterProvider, Stream}, + Resource, }; use viz::{ diff --git a/examples/otel/tracing/Cargo.toml b/examples/otel/tracing/Cargo.toml index 82154c54..e70e7dde 100644 --- a/examples/otel/tracing/Cargo.toml +++ b/examples/otel/tracing/Cargo.toml @@ -9,4 +9,5 @@ viz = { workspace = true, features = ["otel-tracing"] } tokio = { workspace = true, features = [ "rt-multi-thread", "macros" ] } opentelemetry.workspace = true -opentelemetry-jaeger = { version = "0.19.0", features = ["rt-tokio-current-thread"]} +opentelemetry_sdk = { workspace = true, features = ["trace", "rt-tokio-current-thread"] } +opentelemetry-jaeger = { version = "0.20", features = ["rt-tokio-current-thread"]} diff --git a/examples/otel/tracing/src/main.rs b/examples/otel/tracing/src/main.rs index 1c34ea3b..b53fd236 100644 --- a/examples/otel/tracing/src/main.rs +++ b/examples/otel/tracing/src/main.rs @@ -1,10 +1,10 @@ #![deny(warnings)] #![allow(clippy::unused_async)] -use opentelemetry::{ - global, +use opentelemetry::global; +use opentelemetry_sdk::{ runtime::TokioCurrentThread, - sdk::{propagation::TraceContextPropagator, trace::Tracer}, + {propagation::TraceContextPropagator, trace::Tracer}, }; use std::{net::SocketAddr, sync::Arc}; use tokio::net::TcpListener; diff --git a/examples/routing/openapi/Cargo.toml b/examples/routing/openapi/Cargo.toml index 9b7fa56b..c2daeaf6 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.0" -utoipa-swagger-ui = "4.0" +utoipa = "4" +utoipa-swagger-ui = "4" diff --git a/examples/templates/markup/Cargo.toml b/examples/templates/markup/Cargo.toml index d653cab0..ee497407 100644 --- a/examples/templates/markup/Cargo.toml +++ b/examples/templates/markup/Cargo.toml @@ -9,5 +9,5 @@ viz.workspace = true tokio = { workspace = true, features = [ "rt-multi-thread", "macros" ] } -markup = "0.13" +markup = "0.14" v_htmlescape = "0.15" diff --git a/examples/templates/markup/src/main.rs b/examples/templates/markup/src/main.rs index 7eaf7e87..6383c845 100644 --- a/examples/templates/markup/src/main.rs +++ b/examples/templates/markup/src/main.rs @@ -1,5 +1,7 @@ #![deny(warnings)] #![allow(clippy::unused_async)] +#![allow(clippy::must_use_candidate)] +#![allow(clippy::inherent_to_string_shadow_display)] use std::{net::SocketAddr, sync::Arc}; use tokio::net::TcpListener; diff --git a/viz-core/Cargo.toml b/viz-core/Cargo.toml index 13605439..45694cd0 100644 --- a/viz-core/Cargo.toml +++ b/viz-core/Cargo.toml @@ -70,7 +70,7 @@ thiserror.workspace = true rfc7239 = "0.1" # realip cookie = { version = "0.18", features = ["percent-encode"], optional = true } -form-data = { version = "0.5.0-rc.2", optional = true } +form-data = { version = "0.5.0", optional = true } serde = { workspace = true, features = ["derive"], optional = true } serde_json = { workspace = true, optional = true } serde_urlencoded = { workspace = true, optional = true } diff --git a/viz-core/src/middleware/otel/tracing.rs b/viz-core/src/middleware/otel/tracing.rs index 127e6a4a..82043035 100644 --- a/viz-core/src/middleware/otel/tracing.rs +++ b/viz-core/src/middleware/otel/tracing.rs @@ -8,10 +8,8 @@ use http::uri::Scheme; use opentelemetry::{ global, propagation::Extractor, - trace::{ - FutureExt as OtelFutureExt, OrderMap, Span, SpanKind, Status, TraceContextExt, Tracer, - }, - Context, Key, Value, + trace::{FutureExt as OtelFutureExt, Span, SpanKind, Status, TraceContextExt, Tracer}, + Context, KeyValue, }; use opentelemetry_semantic_conventions::trace::{ CLIENT_ADDRESS, CLIENT_SOCKET_ADDRESS, EXCEPTION_MESSAGE, HTTP_REQUEST_BODY_SIZE, @@ -82,7 +80,7 @@ where .tracer .span_builder(format!("{} {}", req.method(), http_route)) .with_kind(SpanKind::Server) - .with_attributes_map(attributes) + .with_attributes(attributes) .start_with_context(&*self.tracer, &parent_context); span.add_event("request.started".to_string(), vec![]); @@ -153,62 +151,65 @@ impl<'a> Extractor for RequestHeaderCarrier<'a> { } } -fn build_attributes(req: &Request, http_route: &str) -> OrderMap { - let mut attributes = OrderMap::::with_capacity(10); +fn build_attributes(req: &Request, http_route: &str) -> Vec { + let mut attributes = Vec::with_capacity(10); // - attributes.insert(HTTP_ROUTE, http_route.to_string().into()); + attributes.push(KeyValue::new(HTTP_ROUTE, http_route.to_string())); // - attributes.insert(HTTP_REQUEST_METHOD, req.method().to_string().into()); - attributes.insert( + attributes.push(KeyValue::new(HTTP_REQUEST_METHOD, req.method().to_string())); + attributes.push(KeyValue::new( NETWORK_PROTOCOL_VERSION, - format!("{:?}", req.version()).into(), - ); + format!("{:?}", req.version()), + )); let remote_addr = req.remote_addr(); if let Some(remote_addr) = remote_addr { - attributes.insert(CLIENT_ADDRESS, remote_addr.to_string().into()); + attributes.push(KeyValue::new(CLIENT_ADDRESS, remote_addr.to_string())); } if let Some(realip) = req.realip().map(|value| value.0).filter(|realip| { remote_addr .map(SocketAddr::ip) .map_or(true, |remoteip| &remoteip != realip) }) { - attributes.insert(CLIENT_SOCKET_ADDRESS, realip.to_string().into()); + attributes.push(KeyValue::new(CLIENT_SOCKET_ADDRESS, realip.to_string())); } let uri = req.uri(); if let Some(host) = uri.host() { - attributes.insert(SERVER_ADDRESS, host.to_string().into()); + attributes.push(KeyValue::new(SERVER_ADDRESS, host.to_string())); } if let Some(port) = uri .port_u16() .map(i64::from) .filter(|port| *port != 80 && *port != 443) { - attributes.insert(SERVER_PORT, port.into()); + attributes.push(KeyValue::new(SERVER_PORT, port.to_string())); } if let Some(path_query) = uri.path_and_query() { if path_query.path() != "/" { - attributes.insert(URL_PATH, path_query.path().to_string().into()); + attributes.push(KeyValue::new(URL_PATH, path_query.path().to_string())); } if let Some(query) = path_query.query() { - attributes.insert(URL_QUERY, query.to_string().into()); + attributes.push(KeyValue::new(URL_QUERY, query.to_string())); } } - attributes.insert( + attributes.push(KeyValue::new( URL_SCHEME, - uri.scheme().unwrap_or(&Scheme::HTTP).to_string().into(), - ); + uri.scheme().unwrap_or(&Scheme::HTTP).to_string(), + )); if let Some(content_length) = req .content_length() .and_then(|len| i64::try_from(len).ok()) .filter(|len| *len > 0) { - attributes.insert(HTTP_REQUEST_BODY_SIZE, content_length.into()); + attributes.push(KeyValue::new( + HTTP_REQUEST_BODY_SIZE, + content_length.to_string(), + )); } if let Some(user_agent) = req @@ -216,7 +217,7 @@ fn build_attributes(req: &Request, http_route: &str) -> OrderMap { .as_ref() .map(UserAgent::as_str) { - attributes.insert(USER_AGENT_ORIGINAL, user_agent.to_string().into()); + attributes.push(KeyValue::new(USER_AGENT_ORIGINAL, user_agent.to_string())); } attributes diff --git a/viz-core/tests/request.rs b/viz-core/tests/request.rs index 30f52e28..eb46bc95 100644 --- a/viz-core/tests/request.rs +++ b/viz-core/tests/request.rs @@ -4,10 +4,19 @@ use headers::{authorization::Bearer, Authorization, ContentType, HeaderValue}; use http::uri::Scheme; use serde::{Deserialize, Serialize}; use viz_core::{ - header::{AUTHORIZATION, CONTENT_TYPE, COOKIE, SET_COOKIE}, + // TODO: reqwest and hyper haven't used the same version of `http`. + // header::{AUTHORIZATION, CONTENT_TYPE, COOKIE, SET_COOKIE}, + // StatusCode, + header::CONTENT_TYPE, types::{self, PayloadError}, - Error, IncomingBody, IntoResponse, Request, RequestExt, Response, ResponseExt, Result, - StatusCode, + Error, + IncomingBody, + IntoResponse, + Request, + RequestExt, + Response, + ResponseExt, + Result, }; #[derive(Debug, Deserialize, Serialize, PartialEq)] @@ -70,6 +79,10 @@ async fn request_body() -> Result<()> { middleware::{cookie, limits}, Router, }; + use viz_test::http::{ + header::{AUTHORIZATION, COOKIE}, + StatusCode, + }; use viz_test::TestServer; let router = Router::new() @@ -300,6 +313,7 @@ async fn request_session() -> Result<()> { middleware::{cookie, helper::CookieOptions, session}, Router, }; + use viz_test::http::header::{COOKIE, SET_COOKIE}; use viz_test::{nano_id, sessions, TestServer}; let router = Router::new() diff --git a/viz-core/tests/type_payload.rs b/viz-core/tests/type_payload.rs index 233bca61..b8db5383 100644 --- a/viz-core/tests/type_payload.rs +++ b/viz-core/tests/type_payload.rs @@ -1,9 +1,10 @@ use std::collections::HashMap; -use viz_core::{types, Error, Request, RequestExt, Response, ResponseExt, Result, StatusCode}; +use viz_core::{types, Error, Request, RequestExt, Response, ResponseExt, Result}; #[tokio::test] async fn payload() -> Result<()> { use viz::{middleware::limits, Router}; + use viz_test::http::StatusCode; use viz_test::TestServer; let router = Router::new() diff --git a/viz-test/Cargo.toml b/viz-test/Cargo.toml index 7a7aa053..a46ea389 100644 --- a/viz-test/Cargo.toml +++ b/viz-test/Cargo.toml @@ -19,5 +19,6 @@ viz.workspace = true sessions = { version = "0.5", features = ["memory"] } nano-id = "0.3" +http = "0.2" reqwest = { version = "0.11", features = ["cookies", "json", "multipart"]} tokio = { workspace = true, features = ["full"] } diff --git a/viz-test/src/lib.rs b/viz-test/src/lib.rs index 169d06f8..7267bd22 100644 --- a/viz-test/src/lib.rs +++ b/viz-test/src/lib.rs @@ -3,6 +3,7 @@ use std::{net::SocketAddr, sync::Arc}; use tokio::net::TcpListener; use viz::{serve, Error, Result, Router, Tree}; +pub use http; pub use nano_id; pub use sessions; diff --git a/viz/src/serve.rs b/viz/src/serve.rs index cd4b62c9..99f655e7 100644 --- a/viz/src/serve.rs +++ b/viz/src/serve.rs @@ -18,7 +18,7 @@ where I: AsyncRead + AsyncWrite + Unpin + Send + 'static, { Builder::new(TokioExecutor::new()) - .serve_connection_with_upgrades(Io::new(stream).into_inner(), Responder::new(tree, addr)) + .serve_connection_with_upgrades(Io::new(stream), Responder::new(tree, addr)) .await .map_err(Into::into) }