From 758eb758ace5cd088d390ade61d36f3da08ddbdf Mon Sep 17 00:00:00 2001 From: Chrislearn Young Date: Wed, 13 Nov 2024 07:17:00 +0800 Subject: [PATCH 1/5] chore(deps): update opentelemetry dependencies --- Cargo.toml | 20 ++++++++++---------- crates/otel/src/metrics.rs | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) 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/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(), } } } From bb8208079fa1920290584f996c537f07fa9a3aee Mon Sep 17 00:00:00 2001 From: Chrislearn Young Date: Wed, 13 Nov 2024 09:08:15 +0800 Subject: [PATCH 2/5] fix example --- examples/Cargo.toml | 25 +++++++----- examples/craft/src/main.rs | 4 +- examples/logging-otlp/Cargo.toml | 12 +++--- examples/logging-otlp/src/main.rs | 59 +++++++++++----------------- examples/otel-jaeger/src/client.rs | 19 ++++----- examples/otel-jaeger/src/exporter.rs | 3 +- examples/otel-jaeger/src/server1.rs | 23 ++++++----- examples/otel-jaeger/src/server2.rs | 24 ++++++----- examples/with-sentry/src/main.rs | 13 +++--- 9 files changed, 97 insertions(+), 85 deletions(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 61b141ccd..b167788dc 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -22,10 +22,10 @@ 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" @@ -33,11 +33,15 @@ sea-orm-migration = "0.12" 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" 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..813c91b7a 100644 --- a/examples/logging-otlp/src/main.rs +++ b/examples/logging-otlp/src/main.rs @@ -1,20 +1,17 @@ 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::trace::{self, RandomIdGenerator}; +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 +36,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 +52,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() From 544e445132ec62f4c57e32406915d12ce332cde5 Mon Sep 17 00:00:00 2001 From: Chrislearn Young Date: Wed, 13 Nov 2024 09:11:21 +0800 Subject: [PATCH 3/5] sea-orm 1.0 --- examples/Cargo.toml | 4 ++-- examples/logging-otlp/src/main.rs | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index b167788dc..d9d0c35cd 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -28,8 +28,8 @@ 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" diff --git a/examples/logging-otlp/src/main.rs b/examples/logging-otlp/src/main.rs index 813c91b7a..22a8d5983 100644 --- a/examples/logging-otlp/src/main.rs +++ b/examples/logging-otlp/src/main.rs @@ -3,7 +3,6 @@ use opentelemetry::KeyValue; use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge; use opentelemetry_otlp::{LogExporter, WithExportConfig}; use opentelemetry_sdk::logs::LoggerProvider; -use opentelemetry_sdk::trace::{self, RandomIdGenerator}; use opentelemetry_sdk::{runtime, Resource}; use salvo::logging::Logger; use salvo::prelude::*; From 925871b877650dd31925346e8d6b217b2d121d19 Mon Sep 17 00:00:00 2001 From: Chrislearn Young Date: Wed, 13 Nov 2024 09:12:14 +0800 Subject: [PATCH 4/5] sqlx 0.8 --- examples/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index d9d0c35cd..804ff9603 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -59,6 +59,6 @@ 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" From ee7be81c03c97e2b3d2f8187d78673be1c36737c Mon Sep 17 00:00:00 2001 From: Chrislearn Young Date: Wed, 13 Nov 2024 09:29:47 +0800 Subject: [PATCH 5/5] cargo clippy --- crates/core/src/conn/quinn/builder.rs | 4 ++-- crates/oapi-macros/src/schema/enum_variant.rs | 2 +- crates/oapi/src/swagger_ui/mod.rs | 2 +- crates/serve-static/src/embed.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) 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/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() {