Skip to content

Commit

Permalink
chore(deps): update opentelemetry dependencies (#989)
Browse files Browse the repository at this point in the history
* chore(deps): update opentelemetry dependencies

* fix example

* sea-orm 1.0

* sqlx 0.8

* cargo clippy
  • Loading branch information
chrislearn authored Nov 13, 2024
1 parent 553b5c7 commit 5edccfe
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 106 deletions.
20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/conn/quinn/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ async fn process_web_transport(
.extensions_mut()
.remove::<Arc<Mutex<salvo_http3::server::Connection<salvo_http3::http3_quinn::Connection, Bytes>>>>()
.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::<Arc<salvo_http3::server::RequestStream<salvo_http3::http3_quinn::BidiStream<Bytes>, Bytes>>>()
.and_then(|stream|Arc::into_inner(stream));
.and_then(Arc::into_inner);
}

let Some(conn) = conn else {
Expand Down
2 changes: 1 addition & 1 deletion crates/oapi-macros/src/schema/enum_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ cfg_feature! {
pub(crate) type_path: &'r syn::TypePath,
}

impl<'r, T> Variant for ReprVariant<'r, T>
impl<T> Variant for ReprVariant<'_, T>
where
T: ToTokens,
{
Expand Down
2 changes: 1 addition & 1 deletion crates/oapi/src/swagger_ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ impl From<String> for Url<'_> {
}
}

impl<'a> From<Cow<'static, str>> for Url<'a> {
impl From<Cow<'static, str>> for Url<'_> {
fn from(url: Cow<'static, str>) -> Self {
Self {
url,
Expand Down
6 changes: 3 additions & 3 deletions crates/otel/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/serve-static/src/embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
31 changes: 18 additions & 13 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"
time = "0.3"
4 changes: 2 additions & 2 deletions examples/craft/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Opts {
pub(crate) fn add2(
self: ::std::sync::Arc<Self>,
left: QueryParam<i64>,
right: QueryParam<i64>
right: QueryParam<i64>,
) -> String {
(self.state + *left + *right).to_string()
}
Expand All @@ -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;
}
}
12 changes: 7 additions & 5 deletions examples/logging-otlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
58 changes: 23 additions & 35 deletions examples/logging-otlp/src/main.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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);
Expand All @@ -56,24 +51,17 @@ async fn main() -> Result<()> {
Ok(())
}

fn init_tracer() -> anyhow::Result<Tracer> {
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<LoggerProvider> {
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)
}
19 changes: 10 additions & 9 deletions examples/otel-jaeger/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion examples/otel-jaeger/src/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {
Expand Down
23 changes: 14 additions & 9 deletions examples/otel-jaeger/src/server1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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]
Expand Down
Loading

0 comments on commit 5edccfe

Please sign in to comment.