Skip to content

Commit d52ff83

Browse files
authored
opentelemetry-proto-support-feature-gen-grpcio-messages (#1316)
In some cases (e.g. rust wasm), it is not possible to have network-related crates (e.g. grpcio) included, and we would like to support protobuf encoding support. so similar to the already existing feature `gen-tonic-messages`, here introduce a feature `gen-grpcio-messages` to support protobuf encoding without any network client/server included. ## Changes replaces some of existing `gen-grpcio` to `gen-grpcio-messages` enables feature `gen-grpcio` will automatically enable `gen-grpcio-messages`
1 parent f2d57b1 commit d52ff83

File tree

6 files changed

+18
-11
lines changed

6 files changed

+18
-11
lines changed

opentelemetry-proto/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ full = ["gen-tonic", "gen-grpcio", "trace", "logs", "metrics", "zpages", "with-s
3131
# crates used to generate rs files
3232
gen-tonic = ["gen-tonic-messages", "tonic/transport"]
3333
gen-tonic-messages = ["tonic", "prost"]
34-
gen-grpcio = ["grpcio", "prost"]
34+
gen-grpcio = ["gen-grpcio-messages", "grpcio"]
35+
gen-grpcio-messages = ["prost"]
3536

3637
# telemetry pillars and functions
3738
trace = ["opentelemetry/trace", "opentelemetry_sdk/trace"]

opentelemetry-proto/src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
//! - `zpages`: generate types that used in zPages. Currently only tracez related types will be generated. Currently supports `gen-tonic` or `gen-grpcio`.
1818
//!
1919
//! ## Creates used to generate files
20-
//! - `gen-tonic`: generate rs files using [tonic](https://github.com/hyperium/tonic) and [prost](https://github.com/tokio-rs/prost).
21-
//! - `gen-grpcio`: generate rs files using [grpcio](https://github.com/tikv/grpc-rs).
20+
//! - `gen-tonic-messages`: generate rs files using [tonic](https://github.com/hyperium/tonic) and [prost](https://github.com/tokio-rs/prost).
21+
//! - `gen-tonic`: adding tonic transport to "`gen-tonic-messages"
22+
//! - `gen-grpcio-messages`: generate rs files using [grpcio](https://github.com/tikv/grpc-rs).
23+
//! - `gen-grpcio`: adding gRPC core to "gen-grpcio-messages"
2224
//!
2325
//! ## Misc
2426
//! - `full`: enabled all features above.
@@ -32,10 +34,13 @@
3234
#[doc(hidden)]
3335
mod proto;
3436

35-
#[cfg(feature = "gen-grpcio")]
37+
#[cfg(feature = "gen-grpcio-messages")]
3638
pub use proto::grpcio;
3739

3840
#[cfg(feature = "gen-tonic-messages")]
3941
pub use proto::tonic;
4042

41-
mod transform;
43+
pub mod transform;
44+
45+
#[cfg(feature = "gen-grpcio-messages")]
46+
pub use prost;

opentelemetry-proto/src/proto.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ pub mod tonic {
7676
pub use crate::transform::common::tonic::Attributes;
7777
}
7878

79-
#[cfg(feature = "gen-grpcio")]
79+
#[cfg(feature = "gen-grpcio-messages")]
8080
/// Generated files using [`grpcio`](https://docs.rs/crate/grpcio) and [`grpcio-compiler`](https://docs.rs/grpcio-compiler)
8181
pub mod grpcio {
8282
/// Service stub and clients
83+
#[cfg(feature = "gen-grpcio")]
8384
#[path = ""]
8485
pub mod collector {
8586
#[cfg(feature = "logs")]

opentelemetry-proto/src/transform/common.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#[cfg(all(
2-
any(feature = "gen-tonic-messages", feature = "gen-grpcio"),
2+
any(feature = "gen-tonic-messages", feature = "gen-grpcio-messages"),
33
any(feature = "trace", feature = "metrics", feature = "logs")
44
))]
55
use std::time::{Duration, SystemTime, UNIX_EPOCH};
66

77
#[cfg(all(
8-
any(feature = "gen-tonic-messages", feature = "gen-grpcio"),
8+
any(feature = "gen-tonic-messages", feature = "gen-grpcio-messages"),
99
any(feature = "trace", feature = "metrics", feature = "logs")
1010
))]
1111
pub(crate) fn to_nanos(time: SystemTime) -> u64 {
@@ -123,7 +123,7 @@ pub mod tonic {
123123
}
124124
}
125125

126-
#[cfg(feature = "gen-grpcio")]
126+
#[cfg(feature = "gen-grpcio-messages")]
127127
pub mod grpcio {
128128
use crate::proto::grpcio::common::v1::{
129129
any_value, AnyValue, ArrayValue, InstrumentationScope, KeyValue,

opentelemetry-proto/src/transform/metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ pub mod tonic {
343343
}
344344
}
345345

346-
#[cfg(feature = "gen-grpcio")]
346+
#[cfg(feature = "gen-grpcio-messages")]
347347
pub mod grpcio {
348348
use std::any::Any;
349349
use std::fmt;

opentelemetry-proto/src/transform/trace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub mod tonic {
109109
}
110110
}
111111

112-
#[cfg(feature = "gen-grpcio")]
112+
#[cfg(feature = "gen-grpcio-messages")]
113113
pub mod grpcio {
114114
use crate::proto::grpcio::resource::v1::Resource;
115115
use crate::proto::grpcio::trace::v1::{span, status, ResourceSpans, ScopeSpans, Span, Status};

0 commit comments

Comments
 (0)