diff --git a/Cargo.toml b/Cargo.toml index 348c10a8f..44408a4a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,7 @@ encoding_rs = "0.8" email_address = "0.2" enumflags2 = "0.7" etag = "4" -eyre = "0.6.12" +eyre = "0.6" fastrand = "2" form_urlencoded = "1" futures-channel = "0.3" @@ -70,7 +70,7 @@ hex = "0.4" hostname-validator = "1" hyper = { version = "1", features = ["full"] } hyper-rustls = { version = "0.27", default-features = false } -hyper-util = { version = "0.1.2", default-features = true } +hyper-util = { version = "0.1", default-features = true } indexmap = "2" inventory = "0.3" jsonwebtoken = "9.1" @@ -82,10 +82,10 @@ multimap = "0.10" native-tls = "0.2" nix = { version = "0.29", default-features = false } openssl = "0.10" -opentelemetry = { version = "0.26", default-features = false } -opentelemetry-http = { version = "0.26", default-features = false } +opentelemetry = { version = "0.27", default-features = false } +opentelemetry-http = { version = "0.27", default-features = false } opentelemetry-prometheus = { version = "0.17", default-features = false } -opentelemetry-semantic-conventions = { version = "0.26", default-features = false } +opentelemetry-semantic-conventions = { version = "0.27", default-features = false } parking_lot = "0.12" path-slash = "0.2" percent-encoding = "2" @@ -99,7 +99,7 @@ quote = "1" rand = "0.8" rcgen = "0.13" regex = "1" -reqwest = "0.12.1" +reqwest = "0.12" ring = "0.17" rust_decimal = "1" rustls = "0.23" @@ -110,12 +110,12 @@ serde_json = "1" serde-xml-rs = "0.6" serde_urlencoded = "0.7" serde_yaml = "0.9" -serde_with = "3.0" +serde_with = "3" sha2 = "0.10" smallvec = "1" socket2 = "0.5" syn = "2" -sync_wrapper = "1.0" +sync_wrapper = "1" tempfile = "3" thiserror = "2" time = "0.3" @@ -136,8 +136,8 @@ uuid = "1" x509-parser = "0.16" # Compress -brotli = { version = "7.0", default-features = false } -flate2 = { version = "1.0", default-features = false } +brotli = { version = "7", default-features = false } +flate2 = { version = "1", default-features = false } zstd = { version = "0.13", default-features = false } [workspace.lints.rust] diff --git a/crates/core/src/conn/quinn/builder.rs b/crates/core/src/conn/quinn/builder.rs index 61699ffdb..76394f9b2 100644 --- a/crates/core/src/conn/quinn/builder.rs +++ b/crates/core/src/conn/quinn/builder.rs @@ -151,14 +151,14 @@ async fn process_web_transport( .extensions_mut() .remove::>>>() .map(|c| { - Arc::into_inner(c).unwrap().into_inner() + Arc::into_inner(c).expect("http3 connection must exist").into_inner() .map_err(|e| IoError::new(ErrorKind::Other, format!("failed to get conn : {}", e))) }) .transpose()?; stream = response .extensions_mut() .remove::, Bytes>>>() - .and_then(|stream|Arc::into_inner(stream)); + .and_then(Arc::into_inner); } let Some(conn) = conn else { diff --git a/crates/oapi-macros/src/schema/enum_variant.rs b/crates/oapi-macros/src/schema/enum_variant.rs index caa3f11ab..7bdccf111 100644 --- a/crates/oapi-macros/src/schema/enum_variant.rs +++ b/crates/oapi-macros/src/schema/enum_variant.rs @@ -49,7 +49,7 @@ cfg_feature! { pub(crate) type_path: &'r syn::TypePath, } - impl<'r, T> Variant for ReprVariant<'r, T> + impl Variant for ReprVariant<'_, T> where T: ToTokens, { diff --git a/crates/oapi/src/swagger_ui/mod.rs b/crates/oapi/src/swagger_ui/mod.rs index 91a71c5d2..835a4d9c9 100644 --- a/crates/oapi/src/swagger_ui/mod.rs +++ b/crates/oapi/src/swagger_ui/mod.rs @@ -348,7 +348,7 @@ impl From for Url<'_> { } } -impl<'a> From> for Url<'a> { +impl From> for Url<'_> { fn from(url: Cow<'static, str>) -> Self { Self { url, diff --git a/crates/otel/src/metrics.rs b/crates/otel/src/metrics.rs index e2bd5ad97..43e159515 100644 --- a/crates/otel/src/metrics.rs +++ b/crates/otel/src/metrics.rs @@ -27,18 +27,18 @@ impl Metrics { request_count: meter .u64_counter("salvo_request_count") .with_description("total request count (since start of service)") - .init(), + .build(), error_count: meter .u64_counter("salvo_error_count") .with_description("failed request count (since start of service)") - .init(), + .build(), duration: meter .f64_histogram("salvo_request_duration_ms") .with_unit("milliseconds") .with_description( "request duration histogram (in milliseconds, since start of service)", ) - .init(), + .build(), } } } diff --git a/crates/serve-static/src/embed.rs b/crates/serve-static/src/embed.rs index daffecc4f..f7f89b595 100644 --- a/crates/serve-static/src/embed.rs +++ b/crates/serve-static/src/embed.rs @@ -120,7 +120,7 @@ where } else { &*decode_url_path_safely(req.uri().path()) }; - let req_path = format_url_path_safely(&req_path); + let req_path = format_url_path_safely(req_path); let mut key_path = Cow::Borrowed(&*req_path); let mut embedded_file = T::get(req_path.as_str()); if embedded_file.is_none() { diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 61b141ccd..804ff9603 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -22,22 +22,26 @@ categories = ["web-programming::http-server", "web-programming::websocket", "net [workspace.dependencies] anyhow = "1" -rbatis = "4.5.22" -rbdc = "4.5.32" -rbdc-mysql = "4.5.7" -rbs = "4.3" +rbatis = "4.5" +rbdc = "4.5" +rbdc-mysql = "4.5" +rbs = "4.5" async-std = "1.12" async-trait = "0.1" -sea-orm = "0.12" -sea-orm-migration = "0.12" +sea-orm = "1" +sea-orm-migration = "1" eyre = "0.6" tera = "1.3" futures = "0.3" -opentelemetry = "0.26.0" -opentelemetry-http = "0.26.0" -opentelemetry-otlp = "0.26.0" + +opentelemetry = "0.27.0" +opentelemetry-http = "0.27.0" +opentelemetry-otlp = "0.27.0" opentelemetry-prometheus = "0.17.0" -opentelemetry_sdk = "0.26.0" +opentelemetry_sdk = "0.27.0" +opentelemetry-semantic-conventions = "0.27.0" +tracing-opentelemetry = "0.27.0" + tokio-stream = "0.1.14" async-stream = "0.3.5" futures-util = { version = "0.3", default-features = true } @@ -47,13 +51,14 @@ reqwest = "0.12" salvo = { path = "../crates/salvo", default-features = true } serde = "1" serde_json = "1" -thiserror = "1" +thiserror = "2" tokio = "1" tracing = "0.1" +tracing-appender = "0.2.3" tracing-subscriber = "0.3" tracing-test = "0.2.1" url = "2" chrono = "0.4" -sqlx = "0.7" +sqlx = "0.8" rust-embed = "8" -time = "0.3" \ No newline at end of file +time = "0.3" diff --git a/examples/craft/src/main.rs b/examples/craft/src/main.rs index 10777891a..f7f54aa4a 100644 --- a/examples/craft/src/main.rs +++ b/examples/craft/src/main.rs @@ -24,7 +24,7 @@ impl Opts { pub(crate) fn add2( self: ::std::sync::Arc, left: QueryParam, - right: QueryParam + right: QueryParam, ) -> String { (self.state + *left + *right).to_string() } @@ -49,4 +49,4 @@ async fn main() { .push(SwaggerUi::new("/api-doc/openapi.json").into_router("swagger-ui")); let acceptor = TcpListener::new("127.0.0.1:5800").bind().await; Server::new(acceptor).serve(router).await; -} \ No newline at end of file +} diff --git a/examples/logging-otlp/Cargo.toml b/examples/logging-otlp/Cargo.toml index cb13771f5..921079c96 100644 --- a/examples/logging-otlp/Cargo.toml +++ b/examples/logging-otlp/Cargo.toml @@ -11,8 +11,10 @@ salvo = { workspace = true, features = ["logging"] } tokio = { workspace = true, features = ["macros"] } tracing.workspace = true tracing-subscriber ={ workspace = true, features = ["env-filter"] } -tracing-opentelemetry = "0.23.0" -opentelemetry = "0.22.0" -opentelemetry-otlp = { version = "0.15.0", features = ["tonic"] } -opentelemetry_sdk = { version = "0.22.1", features = ["rt-tokio"] } -tracing-appender = "0.2.3" +tracing-opentelemetry = { workspace = true } +opentelemetry = { workspace = true } +opentelemetry-appender-tracing = { version = "0.27.0", default-features = false } +opentelemetry-otlp = { workspace = true, features = ["tonic"] } +opentelemetry_sdk = { workspace = true, features = ["rt-tokio"] } +opentelemetry-semantic-conventions = { workspace = true } +tracing-appender = { workspace = true } diff --git a/examples/logging-otlp/src/main.rs b/examples/logging-otlp/src/main.rs index 000adfedd..22a8d5983 100644 --- a/examples/logging-otlp/src/main.rs +++ b/examples/logging-otlp/src/main.rs @@ -1,20 +1,16 @@ use anyhow::Result; use opentelemetry::KeyValue; -use opentelemetry_otlp::WithExportConfig; -use opentelemetry_sdk::{ - runtime, - trace::{self, RandomIdGenerator, Tracer}, - Resource, -}; +use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge; +use opentelemetry_otlp::{LogExporter, WithExportConfig}; +use opentelemetry_sdk::logs::LoggerProvider; +use opentelemetry_sdk::{runtime, Resource}; use salvo::logging::Logger; use salvo::prelude::*; use tracing::{instrument, level_filters::LevelFilter}; -use tracing_subscriber::{ - fmt::{self, format::FmtSpan}, - layer::SubscriberExt, - util::SubscriberInitExt, - Layer, -}; +use tracing_subscriber::fmt::{self, format::FmtSpan}; +use tracing_subscriber::layer::SubscriberExt; +use tracing_subscriber::util::SubscriberInitExt; +use tracing_subscriber::Layer; #[instrument(fields(http.uri = req.uri().path(), http.method = req.method().as_str()))] #[handler] @@ -39,13 +35,12 @@ async fn main() -> Result<()> { .with_filter(LevelFilter::INFO); // opentelemetry tracing layer for tracing-subscriber - let tracer = init_tracer()?; - let opentelemetry = tracing_opentelemetry::layer().with_tracer(tracer); + let provider = init_tracer_provider()?; tracing_subscriber::registry() .with(console) .with(file) - .with(opentelemetry) + .with(OpenTelemetryTracingBridge::new(&provider)) .init(); let router = Router::new().get(hello); @@ -56,24 +51,17 @@ async fn main() -> Result<()> { Ok(()) } -fn init_tracer() -> anyhow::Result { - let tracer = opentelemetry_otlp::new_pipeline() - .tracing() - .with_exporter( - opentelemetry_otlp::new_exporter() - .tonic() - .with_endpoint("http://localhost:4317"), - ) - .with_trace_config( - trace::config() - .with_id_generator(RandomIdGenerator::default()) - .with_max_events_per_span(32) - .with_max_attributes_per_span(64) - .with_resource(Resource::new(vec![KeyValue::new( - "service.name", - "salvo-tracing", - )])), - ) - .install_batch(runtime::Tokio)?; - Ok(tracer) +fn init_tracer_provider() -> anyhow::Result { + let exporter = LogExporter::builder() + .with_tonic() + .with_endpoint("http://localhost:4317") + .build()?; + let provider = LoggerProvider::builder() + .with_batch_exporter(exporter, runtime::Tokio) + .with_resource(Resource::new(vec![KeyValue::new( + opentelemetry_semantic_conventions::resource::SERVICE_NAME, + "salvo-tracing", + )])) + .build(); + Ok(provider) } diff --git a/examples/otel-jaeger/src/client.rs b/examples/otel-jaeger/src/client.rs index 886b4dd0d..1a11eb74e 100644 --- a/examples/otel-jaeger/src/client.rs +++ b/examples/otel-jaeger/src/client.rs @@ -8,19 +8,20 @@ use opentelemetry::{ use opentelemetry_http::HeaderInjector; use opentelemetry_otlp::WithExportConfig; use opentelemetry_sdk::propagation::TraceContextPropagator; +use opentelemetry_sdk::runtime; +use opentelemetry_sdk::trace::TracerProvider; use reqwest::{Client, Method, Url}; fn init_tracer() { global::set_text_map_propagator(TraceContextPropagator::new()); - let provider = opentelemetry_otlp::new_pipeline() - .tracing() - .with_exporter( - opentelemetry_otlp::new_exporter() - .http() - .with_endpoint("http://localhost:14268/api/traces"), - ) - .install_batch(opentelemetry_sdk::runtime::Tokio) - .unwrap(); + let exporter = opentelemetry_otlp::SpanExporter::builder() + .with_tonic() + .with_endpoint("http://localhost:14268/api/traces") + .build() + .expect("failed to create exporter"); + let provider = TracerProvider::builder() + .with_batch_exporter(exporter, runtime::Tokio) + .build(); let _ = global::set_tracer_provider(provider); } diff --git a/examples/otel-jaeger/src/exporter.rs b/examples/otel-jaeger/src/exporter.rs index 7437c757f..4b47de52f 100644 --- a/examples/otel-jaeger/src/exporter.rs +++ b/examples/otel-jaeger/src/exporter.rs @@ -23,7 +23,8 @@ impl Exporter { let mut body = Vec::new(); match encoder.encode(&metric_families, &mut body) { Ok(()) => { - let _ = res.add_header(header::CONTENT_TYPE, "text/javascript; charset=utf-8", true); + let _ = + res.add_header(header::CONTENT_TYPE, "text/javascript; charset=utf-8", true); res.body(body); } Err(_) => { diff --git a/examples/otel-jaeger/src/server1.rs b/examples/otel-jaeger/src/server1.rs index c9b5605f1..7e3462298 100644 --- a/examples/otel-jaeger/src/server1.rs +++ b/examples/otel-jaeger/src/server1.rs @@ -6,8 +6,9 @@ use opentelemetry::trace::{ }; use opentelemetry::{global, KeyValue}; use opentelemetry_http::HeaderInjector; +use opentelemetry_sdk::propagation::TraceContextPropagator; use opentelemetry_sdk::trace::{Tracer, TracerProvider}; -use opentelemetry_sdk::{propagation::TraceContextPropagator, Resource}; +use opentelemetry_sdk::{runtime, Resource}; use reqwest::{Client, Method, Url}; use salvo::otel::{Metrics, Tracing}; use salvo::prelude::*; @@ -17,14 +18,18 @@ use exporter::Exporter; fn init_tracer_provider() -> TracerProvider { global::set_text_map_propagator(TraceContextPropagator::new()); - opentelemetry_otlp::new_pipeline() - .tracing() - .with_trace_config(opentelemetry_sdk::trace::Config::default().with_resource( - Resource::new(vec![KeyValue::new("service.name", "server1")]), - )) - .with_exporter(opentelemetry_otlp::new_exporter().tonic()) - .install_batch(opentelemetry_sdk::runtime::Tokio) - .unwrap() + let exporter = opentelemetry_otlp::SpanExporter::builder() + .with_tonic() + .build() + .expect("failed to create exporter"); + TracerProvider::builder() + .with_batch_exporter(exporter, runtime::Tokio) + .with_config( + opentelemetry_sdk::trace::Config::default().with_resource(Resource::new(vec![ + KeyValue::new("service.name", "server1"), + ])), + ) + .build() } #[handler] diff --git a/examples/otel-jaeger/src/server2.rs b/examples/otel-jaeger/src/server2.rs index 99f6a0a12..4aaebaf53 100644 --- a/examples/otel-jaeger/src/server2.rs +++ b/examples/otel-jaeger/src/server2.rs @@ -1,5 +1,7 @@ use opentelemetry::{global, trace::TracerProvider as _, KeyValue}; -use opentelemetry_sdk::{propagation::TraceContextPropagator, trace::TracerProvider, Resource}; +use opentelemetry_sdk::{ + propagation::TraceContextPropagator, runtime, trace::TracerProvider, Resource, +}; use salvo::otel::{Metrics, Tracing}; use salvo::prelude::*; @@ -8,14 +10,18 @@ use exporter::Exporter; fn init_tracer_provider() -> TracerProvider { global::set_text_map_propagator(TraceContextPropagator::new()); - opentelemetry_otlp::new_pipeline() - .tracing() - .with_trace_config(opentelemetry_sdk::trace::Config::default().with_resource( - Resource::new(vec![KeyValue::new("service.name", "server2")]), - )) - .with_exporter(opentelemetry_otlp::new_exporter().tonic()) - .install_batch(opentelemetry_sdk::runtime::Tokio) - .unwrap() + let exporter = opentelemetry_otlp::SpanExporter::builder() + .with_tonic() + .build() + .expect("failed to create exporter"); + opentelemetry_sdk::trace::TracerProvider::builder() + .with_config( + opentelemetry_sdk::trace::Config::default().with_resource(Resource::new(vec![ + KeyValue::new("service.name", "server2"), + ])), + ) + .with_batch_exporter(exporter, runtime::Tokio) + .build() } #[handler] diff --git a/examples/with-sentry/src/main.rs b/examples/with-sentry/src/main.rs index 89ddaa27c..a93c88152 100644 --- a/examples/with-sentry/src/main.rs +++ b/examples/with-sentry/src/main.rs @@ -9,11 +9,14 @@ fn main() { let _sentry; if let Ok(sentry_dsn) = std::env::var("SENTRY_DSN") { - _sentry = sentry::init((sentry_dsn, sentry::ClientOptions { - release: sentry::release_name!(), - traces_sample_rate: 1.0, - ..Default::default() - })); + _sentry = sentry::init(( + sentry_dsn, + sentry::ClientOptions { + release: sentry::release_name!(), + traces_sample_rate: 1.0, + ..Default::default() + }, + )); } tokio::runtime::Builder::new_multi_thread()