From aadc48f400b7ecf01bc7849befaa4092c5a98838 Mon Sep 17 00:00:00 2001 From: Mathieu Tricoire Date: Thu, 3 Apr 2025 21:04:20 +0200 Subject: [PATCH 1/6] feat(otlp): Re-export tonic crate --- opentelemetry-otlp/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/opentelemetry-otlp/src/lib.rs b/opentelemetry-otlp/src/lib.rs index 05c84744cc..42e51ff846 100644 --- a/opentelemetry-otlp/src/lib.rs +++ b/opentelemetry-otlp/src/lib.rs @@ -407,3 +407,7 @@ pub enum Protocol { #[doc(hidden)] /// Placeholder type when no exporter pipeline has been configured in telemetry pipeline. pub struct NoExporterConfig(()); + +#[cfg(feature = "grpc-tonic")] +#[doc(no_inline)] +pub use tonic; From 31f38a719a0b007e59bf37b341f06b20d022210f Mon Sep 17 00:00:00 2001 From: Mathieu Tricoire Date: Thu, 3 Apr 2025 21:41:42 +0200 Subject: [PATCH 2/6] add tonic to allowed external type list --- opentelemetry-otlp/allowed-external-types.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/opentelemetry-otlp/allowed-external-types.toml b/opentelemetry-otlp/allowed-external-types.toml index 2412d22715..6428d2d4ce 100644 --- a/opentelemetry-otlp/allowed-external-types.toml +++ b/opentelemetry-otlp/allowed-external-types.toml @@ -13,6 +13,7 @@ allowed_external_types = [ # prost is a pre 1.0 crate "prost::error::EncodeError", # tonic is a pre 1.0 crate + "tonic", "tonic::status::Code", "tonic::status::Status", "tonic::metadata::map::MetadataMap", From bd0af70718ec421e767088d5ba50f4a6d03ba40a Mon Sep 17 00:00:00 2001 From: Mathieu Tricoire Date: Tue, 22 Apr 2025 23:25:38 +0200 Subject: [PATCH 3/6] re-export cherry-picked tonic types --- opentelemetry-otlp/allowed-external-types.toml | 4 +++- opentelemetry-otlp/src/lib.rs | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/opentelemetry-otlp/allowed-external-types.toml b/opentelemetry-otlp/allowed-external-types.toml index 6428d2d4ce..6dd02c434a 100644 --- a/opentelemetry-otlp/allowed-external-types.toml +++ b/opentelemetry-otlp/allowed-external-types.toml @@ -13,10 +13,12 @@ allowed_external_types = [ # prost is a pre 1.0 crate "prost::error::EncodeError", # tonic is a pre 1.0 crate - "tonic", "tonic::status::Code", "tonic::status::Status", "tonic::metadata::map::MetadataMap", + "tonic::transport::channel::tls::ClientTlsConfig", + "tonic::transport::tls::Certificate", + "tonic::transport::tls::Identity", "tonic::transport::channel::Channel", "tonic::transport::error::Error", "tonic::service::interceptor::Interceptor", diff --git a/opentelemetry-otlp/src/lib.rs b/opentelemetry-otlp/src/lib.rs index 90c76d3cda..5947a297b3 100644 --- a/opentelemetry-otlp/src/lib.rs +++ b/opentelemetry-otlp/src/lib.rs @@ -452,5 +452,15 @@ pub enum Protocol { pub struct NoExporterConfig(()); #[cfg(feature = "grpc-tonic")] -#[doc(no_inline)] -pub use tonic; +pub mod tonic_types { + pub mod metadata { + #[doc(no_inline)] + pub use tonic::metadata::MetadataMap; + } + + #[cfg(feature = "tls")] + pub mod transport { + #[doc(no_inline)] + pub use tonic::transport::{Certificate, ClientTlsConfig, Identity}; + } +} From 2150812d5bd15e73e14eb840ac3cf5ca73dd7a63 Mon Sep 17 00:00:00 2001 From: Mathieu Tricoire Date: Tue, 22 Apr 2025 23:44:58 +0200 Subject: [PATCH 4/6] add documentation to re-exported tonic types --- opentelemetry-otlp/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/opentelemetry-otlp/src/lib.rs b/opentelemetry-otlp/src/lib.rs index 5947a297b3..86180e3e6f 100644 --- a/opentelemetry-otlp/src/lib.rs +++ b/opentelemetry-otlp/src/lib.rs @@ -451,13 +451,16 @@ pub enum Protocol { /// Placeholder type when no exporter pipeline has been configured in telemetry pipeline. pub struct NoExporterConfig(()); +/// Re-exported types from the `tonic` crate. #[cfg(feature = "grpc-tonic")] pub mod tonic_types { + /// Re-exported types from `tonic::metadata`. pub mod metadata { #[doc(no_inline)] pub use tonic::metadata::MetadataMap; } + /// Re-exported types from `tonic::transport`. #[cfg(feature = "tls")] pub mod transport { #[doc(no_inline)] From 19b5c9090e3f1c1bfe0320abb2f1a8d30a608b9c Mon Sep 17 00:00:00 2001 From: Mathieu Tricoire Date: Mon, 28 Apr 2025 18:51:29 +0200 Subject: [PATCH 5/6] clean allowed external types + update CI --- .github/workflows/ci.yml | 2 +- opentelemetry-otlp/allowed-external-types.toml | 13 +++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 532693b3cf..353ecf6c45 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -102,7 +102,7 @@ jobs: run: | cargo install cargo-check-external-types@0.1.13 cd ${{ matrix.example }} - cargo check-external-types --config allowed-external-types.toml + cargo check-external-types --all-features --config allowed-external-types.toml msrv: strategy: matrix: diff --git a/opentelemetry-otlp/allowed-external-types.toml b/opentelemetry-otlp/allowed-external-types.toml index 6dd02c434a..7995873ee8 100644 --- a/opentelemetry-otlp/allowed-external-types.toml +++ b/opentelemetry-otlp/allowed-external-types.toml @@ -3,23 +3,16 @@ # This is used with cargo-check-external-types to reduce the surface area of downstream crates from # the public API. Ideally this can have a few exceptions as possible. allowed_external_types = [ - "opentelemetry::*", "opentelemetry_http::*", "opentelemetry_sdk::*", - # http is a pre 1.0 crate - "http::uri::InvalidUri", - "http::header::name::InvalidHeaderName", - "http::header::value::InvalidHeaderValue", - # prost is a pre 1.0 crate - "prost::error::EncodeError", + # serde + "serde::de::Deserialize", + "serde::ser::Serialize", # tonic is a pre 1.0 crate - "tonic::status::Code", - "tonic::status::Status", "tonic::metadata::map::MetadataMap", "tonic::transport::channel::tls::ClientTlsConfig", "tonic::transport::tls::Certificate", "tonic::transport::tls::Identity", "tonic::transport::channel::Channel", - "tonic::transport::error::Error", "tonic::service::interceptor::Interceptor", ] From 0809e5b8fccd6b2ac4944de9ae4b1521aceabbfb Mon Sep 17 00:00:00 2001 From: Mathieu Tricoire Date: Wed, 30 Apr 2025 18:32:33 +0200 Subject: [PATCH 6/6] update CHANGELOG --- opentelemetry-otlp/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/opentelemetry-otlp/CHANGELOG.md b/opentelemetry-otlp/CHANGELOG.md index 4ad96907a7..28038d3b60 100644 --- a/opentelemetry-otlp/CHANGELOG.md +++ b/opentelemetry-otlp/CHANGELOG.md @@ -3,6 +3,8 @@ ## vNext - Update `tonic` dependency version to 0.13 +- Re-export `tonic` types under `tonic_types` + [2898](https://github.com/open-telemetry/opentelemetry-rust/pull/2898) ## 0.29.0