opentelemetry-rust icon indicating copy to clipboard operation
opentelemetry-rust copied to clipboard

enh: permit users with different versions of tonic

Open rbtcollins opened this issue 3 years ago • 2 comments

Right now tonic is used in two quite different ways: 1) it is an internal library that facilitates e.g. grpc handling and 2) tonic types are part of the public interface of opentelemetry-otlp.

For case (2) it would be really nice to have access to the version of tonic that opentelemetry-otlp expects as a re-export, rather than having to do lock-step upgrades of opentelemetry & tonic across our codebases.

something as simple as a pub use tonic in the root of opentelemetry-otlp might well be enough to fix this.

Example of (2) code today:

       TracingProtocol::Otlp(url, token) => {
            let mut map = tonic::metadata::map::MetadataMap::new();
            map.insert(ACCESS_TOKEN_HEADER, token.parse().unwrap());

            opentelemetry_otlp::new_pipeline()
                .tracing()
                .with_exporter(
                    opentelemetry_otlp::new_exporter()
                        .tonic()
                        .with_metadata(map)
                        .with_timeout(OTLP_TIMEOUT)
                        .with_protocol(Protocol::Grpc)
                        .with_endpoint(url),
                )
                .with_trace_config(trace_config)
                .install_batch(opentelemetry::runtime::Tokio)?
        }

The challenge here is that without reference to an exactly matching tonic version, this code will fail like so:

error[E0308]: mismatched types
Error:    --> src/tracing.rs:148:40
    |
148 |                         .with_metadata(map)
    |                          ------------- ^^^ expected struct `tonic::metadata::map::MetadataMap`, found struct `tonic::metadata::map::MetadataMap`
    |                          |
    |                          arguments to this function are incorrect
    |
    = note: perhaps two different versions of crate `tonic` are being used?
note: associated function defined here
   --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/opentelemetry-otlp-0.10.0/src/exporter/tonic.rs:44:12
    |
44  |     pub fn with_metadata(mut self, metadata: MetadataMap) -> Self {
    |            ^^^^^^^^^^^^^

rbtcollins avatar Sep 21 '22 12:09 rbtcollins

Re-exporting this makes sense to me. Would you be able to submit a PR?

djc avatar Sep 21 '22 13:09 djc

Not immediately, but sure.

rbtcollins avatar Sep 21 '22 14:09 rbtcollins

I ran into this as well - what is common practice/solution? anyone have any luck?

jt55401 avatar Nov 19 '23 19:11 jt55401