Skip to content

enh: permit users with different versions of tonic #882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rbtcollins opened this issue Sep 21, 2022 · 3 comments · Fixed by #2898
Closed

enh: permit users with different versions of tonic #882

rbtcollins opened this issue Sep 21, 2022 · 3 comments · Fixed by #2898
Labels
A-common Area:common issues that not related to specific pillar enhancement New feature or request

Comments

@rbtcollins
Copy link
Contributor

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 {
    |            ^^^^^^^^^^^^^
@djc
Copy link
Contributor

djc commented Sep 21, 2022

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

@rbtcollins
Copy link
Contributor Author

Not immediately, but sure.

@TommyCpp TommyCpp added enhancement New feature or request A-common Area:common issues that not related to specific pillar labels Sep 24, 2022
@jt55401
Copy link

jt55401 commented Nov 19, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-common Area:common issues that not related to specific pillar enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants