From 9bf4e434277a4dda88228e1506e2cc0cfc44e6c7 Mon Sep 17 00:00:00 2001 From: imperivox Date: Fri, 29 Nov 2024 18:46:06 +0100 Subject: [PATCH 1/5] Update Deps --- Cargo.toml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dfa846a..901acb1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,33 +6,33 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -hyper = { version = "0.14.28", features = ["full"] } -tokio = { version = "1.36.0", features = ["full"] } +hyper = { version = "1.2.0", features = ["full"] } +tokio = { version = "1.37.0", features = ["full"] } tonic = "0.11.0" tonic-reflection = "0.11.0" prost = "0.12.3" prost-types = "0.12.3" tower = "0.4.13" -hyper-util = { version = "0.1.3", features = ["tokio"] } -http-body-util = "0.1.0" +hyper-util = { version = "0.1.5", features = ["tokio"] } +http-body-util = "0.1.1" anyhow = "1.0.82" once_cell = "1.19.0" tonic-tracing-opentelemetry = "0.18.1" -opentelemetry = { version = "0.22.0", features = ["trace"] } -opentelemetry_sdk = { version = "0.22.1", features = ["trace", "rt-tokio"] } -opentelemetry-semantic-conventions = "0.14.0" -opentelemetry-http = "0.11.0" -opentelemetry-otlp = { version = "0.15.0", features = [ +opentelemetry = { version = "0.23.0", features = ["trace"] } +opentelemetry_sdk = { version = "0.23.1", features = ["trace", "rt-tokio"] } +opentelemetry-semantic-conventions = "0.15.0" +opentelemetry-http = "0.12.0" +opentelemetry-otlp = { version = "0.16.0", features = [ "trace", # required to make grpc requests "tls-roots", ] } tracing = "0.1.40" -tracing-opentelemetry = "0.23.0" +tracing-opentelemetry = "0.24.0" tracing-subscriber = "0.3.18" shuttle-runtime = "0.49.0" shuttle-axum = "0.39.0" -async-trait = "0.1" +async-trait = "0.1.80" [build-dependencies] gh-workflow = "0.5.1" From be94611b49c763cc08b97c77c05d7b001b072ed5 Mon Sep 17 00:00:00 2001 From: imperivox Date: Fri, 29 Nov 2024 19:05:17 +0100 Subject: [PATCH 2/5] Update Cargo.toml --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 901acb1..d646cba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ anyhow = "1.0.82" once_cell = "1.19.0" tonic-tracing-opentelemetry = "0.18.1" opentelemetry = { version = "0.23.0", features = ["trace"] } -opentelemetry_sdk = { version = "0.23.1", features = ["trace", "rt-tokio"] } +opentelemetry_sdk = { version = "0.27.1", features = ["trace", "rt-tokio"] } opentelemetry-semantic-conventions = "0.15.0" opentelemetry-http = "0.12.0" opentelemetry-otlp = { version = "0.16.0", features = [ From eb9e64480fd4bd9faead962e0fb28d858e00e3bf Mon Sep 17 00:00:00 2001 From: imperivox Date: Fri, 29 Nov 2024 19:40:34 +0100 Subject: [PATCH 3/5] Update main.rs --- src/main.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7e2aed4..f32bdf6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,10 +6,10 @@ use hyper::{ HeaderMap, }; use once_cell::sync::Lazy; -use opentelemetry::{global, trace::TraceError, trace::TracerProvider, KeyValue}; +use opentelemetry::{global, trace::TraceError, trace::TracerProvider}; use opentelemetry_otlp::WithExportConfig; -use opentelemetry_sdk::{propagation::TraceContextPropagator, runtime, Resource}; -use tonic::{metadata::MetadataMap, transport::Server as TonicServer, Response, Status}; +use opentelemetry_sdk::{propagation::TraceContextPropagator, runtime, Resource, trace::Config as SdkTraceConfig,}; +use tonic::{metadata::MetadataMap, transport::{Server, Server as TonicServer}, Response, Status,}; use tonic_tracing_opentelemetry::middleware::server; use tower::make::Shared; @@ -18,6 +18,7 @@ use news::news_service_server::NewsServiceServer; use news::{MultipleNewsId, News, NewsId, NewsList}; use shuttle_runtime::Service; use tracing_subscriber::layer::SubscriberExt; +use opentelemetry::KeyValue as OtelKeyValue; pub mod news { tonic::include_proto!("news"); // The package name specified in your .proto @@ -166,11 +167,11 @@ impl NewsService for MyNewsService { static RESOURCE: Lazy = Lazy::new(|| { Resource::default().merge(&Resource::new(vec![ - KeyValue::new( + OtelKeyValue::new( opentelemetry_semantic_conventions::resource::SERVICE_NAME, "rust-grpc", ), - KeyValue::new( + OtelKeyValue::new( opentelemetry_semantic_conventions::resource::SERVICE_VERSION, "test", ), @@ -189,13 +190,15 @@ fn init_tracer() -> Result<()> { let otlp_exporter = opentelemetry_otlp::new_exporter() .tonic() .with_endpoint(TELEMETRY_URL) - .with_metadata(MetadataMap::from_headers(headers)); + .with_metadata(MetadataMap::from_iter( + headers.iter().map(|(k, v)| (k.clone(), v.as_bytes().to_vec())) + )); let provider = opentelemetry_otlp::new_pipeline() .tracing() .with_exporter(otlp_exporter) - .with_trace_config(opentelemetry_sdk::trace::config().with_resource(RESOURCE.clone())) - .install_batch(runtime::Tokio)? + .with_trace_config(SdkTraceConfig::default().with_resource(RESOURCE.clone())) + .install_batch(runtime::Tokio) .provider() .ok_or(TraceError::Other( anyhow!("Failed to instantiate OTLP provider").into(), @@ -244,7 +247,7 @@ impl Service for MyNewsService { .into_service(); let make_svc = Shared::new(tonic_service); - let server = hyper::Server::bind(&addr).serve(make_svc); + let server = Server::bind(&addr).serve(make_svc); server .await .map_err(|e| shuttle_runtime::Error::Custom(anyhow::anyhow!(e)))?; From 5cf52b092a4fb6389116e1f1545d78b600d1c39d Mon Sep 17 00:00:00 2001 From: imperivox Date: Sat, 30 Nov 2024 09:57:44 +0100 Subject: [PATCH 4/5] Fix main.rs --- src/main.rs | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/src/main.rs b/src/main.rs index f32bdf6..5bfa192 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,19 +6,17 @@ use hyper::{ HeaderMap, }; use once_cell::sync::Lazy; -use opentelemetry::{global, trace::TraceError, trace::TracerProvider}; +use opentelemetry::{global, trace::TraceError, trace::TracerProvider, KeyValue}; use opentelemetry_otlp::WithExportConfig; -use opentelemetry_sdk::{propagation::TraceContextPropagator, runtime, Resource, trace::Config as SdkTraceConfig,}; -use tonic::{metadata::MetadataMap, transport::{Server, Server as TonicServer}, Response, Status,}; -use tonic_tracing_opentelemetry::middleware::server; -use tower::make::Shared; +use opentelemetry_sdk::{propagation::TraceContextPropagator, runtime, Resource}; +use tonic::{metadata::MetadataMap, response::Response, Status, server::Server}; +use tonic_tracing_opentelemetry::layer::OtelGrpcLayer; use news::news_service_server::NewsService; use news::news_service_server::NewsServiceServer; use news::{MultipleNewsId, News, NewsId, NewsList}; use shuttle_runtime::Service; use tracing_subscriber::layer::SubscriberExt; -use opentelemetry::KeyValue as OtelKeyValue; pub mod news { tonic::include_proto!("news"); // The package name specified in your .proto @@ -167,11 +165,11 @@ impl NewsService for MyNewsService { static RESOURCE: Lazy = Lazy::new(|| { Resource::default().merge(&Resource::new(vec![ - OtelKeyValue::new( + KeyValue::new( opentelemetry_semantic_conventions::resource::SERVICE_NAME, "rust-grpc", ), - OtelKeyValue::new( + KeyValue::new( opentelemetry_semantic_conventions::resource::SERVICE_VERSION, "test", ), @@ -190,15 +188,13 @@ fn init_tracer() -> Result<()> { let otlp_exporter = opentelemetry_otlp::new_exporter() .tonic() .with_endpoint(TELEMETRY_URL) - .with_metadata(MetadataMap::from_iter( - headers.iter().map(|(k, v)| (k.clone(), v.as_bytes().to_vec())) - )); + .with_metadata(MetadataMap::from_headers(headers)); let provider = opentelemetry_otlp::new_pipeline() .tracing() .with_exporter(otlp_exporter) - .with_trace_config(SdkTraceConfig::default().with_resource(RESOURCE.clone())) - .install_batch(runtime::Tokio) + .with_trace_config(opentelemetry_sdk::trace::config().with_resource(RESOURCE.clone())) + .install_batch(runtime::Tokio)? .provider() .ok_or(TraceError::Other( anyhow!("Failed to instantiate OTLP provider").into(), @@ -213,7 +209,6 @@ fn init_tracer() -> Result<()> { let subscriber = tracing_subscriber::registry().with(trace_layer); tracing::subscriber::set_global_default(subscriber)?; - global::set_tracer_provider(provider); Ok(()) @@ -232,25 +227,22 @@ async fn shuttle_main() -> Result { #[async_trait::async_trait] impl Service for MyNewsService { - async fn bind(mut self, addr: std::net::SocketAddr) -> Result<(), shuttle_runtime::Error> { - let service = tonic_reflection::server::Builder::configure() + async fn bind(&mut self, addr: std::net::SocketAddr) -> Result<(), shuttle_runtime::Error> { + let reflection_service = tonic_reflection::server::Builder::configure() .register_encoded_file_descriptor_set(news::FILE_DESCRIPTOR_SET) .build() - .unwrap(); + .map_err(|e| shuttle_runtime::Error::Custom(anyhow::anyhow!(e)))?; println!("NewsService server listening on {}", addr); - let tonic_service = TonicServer::builder() - .layer(server::OtelGrpcLayer::default()) - .add_service(NewsServiceServer::new(self)) - .add_service(service) - .into_service(); - let make_svc = Shared::new(tonic_service); + let otel_layer = OtelGrpcLayer::new(); + let server = Server::builder() + .layer(otel_layer) + .add_service(NewsServiceServer::new(self.clone())) + .add_service(reflection_service) + .serve(addr); - let server = Server::bind(&addr).serve(make_svc); - server - .await - .map_err(|e| shuttle_runtime::Error::Custom(anyhow::anyhow!(e)))?; + server.await.map_err(|e| shuttle_runtime::Error::Custom(anyhow::anyhow!(e)))?; Ok(()) } From 42c438d2967b6e1d5a5536290efed0132f0d9058 Mon Sep 17 00:00:00 2001 From: imperivox Date: Sat, 30 Nov 2024 09:58:16 +0100 Subject: [PATCH 5/5] Update Deps Cargo.toml --- Cargo.toml | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d646cba..c4817f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,37 +6,37 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -hyper = { version = "1.2.0", features = ["full"] } -tokio = { version = "1.37.0", features = ["full"] } -tonic = "0.11.0" -tonic-reflection = "0.11.0" +hyper = { version = "0.14.39", features = ["full"] } +tokio = { version = "1.42.0", features = ["full"] } +tonic = "0.14.0" +tonic-reflection = "0.14.0" prost = "0.12.3" prost-types = "0.12.3" tower = "0.4.13" -hyper-util = { version = "0.1.5", features = ["tokio"] } -http-body-util = "0.1.1" +hyper-util = { version = "0.1.3", features = ["tokio"] } +http-body-util = "0.1.0" anyhow = "1.0.82" once_cell = "1.19.0" -tonic-tracing-opentelemetry = "0.18.1" -opentelemetry = { version = "0.23.0", features = ["trace"] } -opentelemetry_sdk = { version = "0.27.1", features = ["trace", "rt-tokio"] } -opentelemetry-semantic-conventions = "0.15.0" -opentelemetry-http = "0.12.0" -opentelemetry-otlp = { version = "0.16.0", features = [ +tonic-tracing-opentelemetry = "0.20.0" +opentelemetry = { version = "0.28.0", features = ["trace"] } +opentelemetry_sdk = { version = "0.28.0", features = ["trace", "rt-tokio"] } +opentelemetry-semantic-conventions = "0.24.0" +opentelemetry-http = "0.14.0" +opentelemetry-otlp = { version = "0.19.0", features = [ "trace", # required to make grpc requests - "tls-roots", + "tls", ] } tracing = "0.1.40" -tracing-opentelemetry = "0.24.0" -tracing-subscriber = "0.3.18" +tracing-opentelemetry = "0.23.0" +tracing-subscriber = "0.5.0" shuttle-runtime = "0.49.0" -shuttle-axum = "0.39.0" -async-trait = "0.1.80" +shuttle-axum = "0.49.0" +async-trait = "0.1.66" [build-dependencies] gh-workflow = "0.5.1" -tonic-build = "0.11.0" +tonic-build = "0.14.0" [dev-dependencies] gh-workflow = "0.5.1"