diff --git a/Cargo.toml b/Cargo.toml index dfa846a..c4817f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,10 +6,10 @@ 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"] } -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" @@ -17,26 +17,26 @@ 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.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 = [ +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.23.0" -tracing-subscriber = "0.3.18" +tracing-subscriber = "0.5.0" shuttle-runtime = "0.49.0" -shuttle-axum = "0.39.0" -async-trait = "0.1" +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" diff --git a/src/main.rs b/src/main.rs index 7e2aed4..5bfa192 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,9 +9,8 @@ use once_cell::sync::Lazy; use opentelemetry::{global, trace::TraceError, trace::TracerProvider, KeyValue}; use opentelemetry_otlp::WithExportConfig; use opentelemetry_sdk::{propagation::TraceContextPropagator, runtime, Resource}; -use tonic::{metadata::MetadataMap, transport::Server as TonicServer, Response, Status}; -use tonic_tracing_opentelemetry::middleware::server; -use tower::make::Shared; +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; @@ -210,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(()) @@ -229,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 = hyper::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(()) }