Skip to content

Commit 482d951

Browse files
authored
feat: upgrade to tonic 0.9 (#1016)
1 parent ee3efe0 commit 482d951

File tree

10 files changed

+294
-49
lines changed

10 files changed

+294
-49
lines changed

examples/external-otlp-tonic-tokio/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ opentelemetry = {path = "../../opentelemetry", features = ["rt-tokio", "metrics"
1010
opentelemetry-otlp = {path = "../../opentelemetry-otlp", features = ["tonic", "tls", "tls-roots"]}
1111
serde_json = "1.0"
1212
tokio = {version = "1.0", features = ["full"]}
13-
tonic = {version = "0.8.0", features = ["tls"]}
13+
tonic = {version = "0.9.0", features = ["tls"]}
1414
url = "2.2.0"

opentelemetry-jaeger/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ tokio = { version = "1.0", features = ["net", "sync"], optional = true }
4545
wasm-bindgen = { version = "0.2", optional = true }
4646
wasm-bindgen-futures = { version = "0.4.18", optional = true }
4747

48-
tonic = { version = "0.8.3", optional = true }
48+
tonic = { version = "0.9.0", optional = true }
4949
prost = { version = "0.11.6", optional = true }
5050
prost-types = { version = "0.11.6", optional = true }
5151

opentelemetry-otlp/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ opentelemetry-http = { version = "0.8", path = "../opentelemetry-http", optional
4242
protobuf = { version = "2.18", optional = true }
4343

4444
prost = { version = "0.11.0", optional = true }
45-
tonic = { version = "0.8.0", optional = true }
45+
tonic = { version = "0.9.0", optional = true }
4646
tokio = { version = "1.0", features = ["sync", "rt"], optional = true }
4747

4848
reqwest = { version = "0.11", optional = true, default-features = false }

opentelemetry-proto/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ with-serde = ["protobuf/with-serde", "serde", "serde_json"]
4444

4545
[dependencies]
4646
grpcio = { version = "0.12", optional = true }
47-
tonic = { version = "0.8.0", optional = true }
47+
tonic = { version = "0.9.0", optional = true }
4848
prost = { version = "0.11.0", optional = true }
4949
protobuf = { version = "2.18", optional = true } # todo: update to 3.0 so we have docs for generated types.
5050
opentelemetry = { version = "0.19", default-features = false, features = ["trace", "metrics"], path = "../opentelemetry" }
@@ -56,6 +56,6 @@ serde_json = { version = "1.0", optional = true }
5656
[dev-dependencies]
5757
protobuf-codegen = { version = "2.16" }
5858
protoc-grpcio = { version = "3.0" }
59-
tonic-build = { version = "0.8.0" }
59+
tonic-build = { version = "0.9.0" }
6060
prost-build = { version = "0.11.1" }
6161
tempfile = "3.3.0"

opentelemetry-proto/src/proto/tonic/opentelemetry.proto.collector.logs.v1.rs

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub mod logs_service_client {
6767
/// Attempt to create a new client by connecting to a given endpoint.
6868
pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
6969
where
70-
D: std::convert::TryInto<tonic::transport::Endpoint>,
70+
D: TryInto<tonic::transport::Endpoint>,
7171
D::Error: Into<StdError>,
7272
{
7373
let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
@@ -123,12 +123,31 @@ pub mod logs_service_client {
123123
self.inner = self.inner.accept_compressed(encoding);
124124
self
125125
}
126+
/// Limits the maximum size of a decoded message.
127+
///
128+
/// Default: `4MB`
129+
#[must_use]
130+
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
131+
self.inner = self.inner.max_decoding_message_size(limit);
132+
self
133+
}
134+
/// Limits the maximum size of an encoded message.
135+
///
136+
/// Default: `usize::MAX`
137+
#[must_use]
138+
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
139+
self.inner = self.inner.max_encoding_message_size(limit);
140+
self
141+
}
126142
/// For performance reasons, it is recommended to keep this RPC
127143
/// alive for the entire life of the application.
128144
pub async fn export(
129145
&mut self,
130146
request: impl tonic::IntoRequest<super::ExportLogsServiceRequest>,
131-
) -> Result<tonic::Response<super::ExportLogsServiceResponse>, tonic::Status> {
147+
) -> std::result::Result<
148+
tonic::Response<super::ExportLogsServiceResponse>,
149+
tonic::Status,
150+
> {
132151
self.inner
133152
.ready()
134153
.await
@@ -142,7 +161,15 @@ pub mod logs_service_client {
142161
let path = http::uri::PathAndQuery::from_static(
143162
"/opentelemetry.proto.collector.logs.v1.LogsService/Export",
144163
);
145-
self.inner.unary(request.into_request(), path, codec).await
164+
let mut req = request.into_request();
165+
req.extensions_mut()
166+
.insert(
167+
GrpcMethod::new(
168+
"opentelemetry.proto.collector.logs.v1.LogsService",
169+
"Export",
170+
),
171+
);
172+
self.inner.unary(req, path, codec).await
146173
}
147174
}
148175
}
@@ -158,7 +185,10 @@ pub mod logs_service_server {
158185
async fn export(
159186
&self,
160187
request: tonic::Request<super::ExportLogsServiceRequest>,
161-
) -> Result<tonic::Response<super::ExportLogsServiceResponse>, tonic::Status>;
188+
) -> std::result::Result<
189+
tonic::Response<super::ExportLogsServiceResponse>,
190+
tonic::Status,
191+
>;
162192
}
163193
/// Service that can be used to push logs between one Application instrumented with
164194
/// OpenTelemetry and an collector, or between an collector and a central collector (in this
@@ -168,6 +198,8 @@ pub mod logs_service_server {
168198
inner: _Inner<T>,
169199
accept_compression_encodings: EnabledCompressionEncodings,
170200
send_compression_encodings: EnabledCompressionEncodings,
201+
max_decoding_message_size: Option<usize>,
202+
max_encoding_message_size: Option<usize>,
171203
}
172204
struct _Inner<T>(Arc<T>);
173205
impl<T: LogsService> LogsServiceServer<T> {
@@ -180,6 +212,8 @@ pub mod logs_service_server {
180212
inner,
181213
accept_compression_encodings: Default::default(),
182214
send_compression_encodings: Default::default(),
215+
max_decoding_message_size: None,
216+
max_encoding_message_size: None,
183217
}
184218
}
185219
pub fn with_interceptor<F>(
@@ -203,6 +237,22 @@ pub mod logs_service_server {
203237
self.send_compression_encodings.enable(encoding);
204238
self
205239
}
240+
/// Limits the maximum size of a decoded message.
241+
///
242+
/// Default: `4MB`
243+
#[must_use]
244+
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
245+
self.max_decoding_message_size = Some(limit);
246+
self
247+
}
248+
/// Limits the maximum size of an encoded message.
249+
///
250+
/// Default: `usize::MAX`
251+
#[must_use]
252+
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
253+
self.max_encoding_message_size = Some(limit);
254+
self
255+
}
206256
}
207257
impl<T, B> tonic::codegen::Service<http::Request<B>> for LogsServiceServer<T>
208258
where
@@ -216,7 +266,7 @@ pub mod logs_service_server {
216266
fn poll_ready(
217267
&mut self,
218268
_cx: &mut Context<'_>,
219-
) -> Poll<Result<(), Self::Error>> {
269+
) -> Poll<std::result::Result<(), Self::Error>> {
220270
Poll::Ready(Ok(()))
221271
}
222272
fn call(&mut self, req: http::Request<B>) -> Self::Future {
@@ -238,13 +288,15 @@ pub mod logs_service_server {
238288
&mut self,
239289
request: tonic::Request<super::ExportLogsServiceRequest>,
240290
) -> Self::Future {
241-
let inner = self.0.clone();
291+
let inner = Arc::clone(&self.0);
242292
let fut = async move { (*inner).export(request).await };
243293
Box::pin(fut)
244294
}
245295
}
246296
let accept_compression_encodings = self.accept_compression_encodings;
247297
let send_compression_encodings = self.send_compression_encodings;
298+
let max_decoding_message_size = self.max_decoding_message_size;
299+
let max_encoding_message_size = self.max_encoding_message_size;
248300
let inner = self.inner.clone();
249301
let fut = async move {
250302
let inner = inner.0;
@@ -254,6 +306,10 @@ pub mod logs_service_server {
254306
.apply_compression_config(
255307
accept_compression_encodings,
256308
send_compression_encodings,
309+
)
310+
.apply_max_message_size_config(
311+
max_decoding_message_size,
312+
max_encoding_message_size,
257313
);
258314
let res = grpc.unary(method, req).await;
259315
Ok(res)
@@ -282,12 +338,14 @@ pub mod logs_service_server {
282338
inner,
283339
accept_compression_encodings: self.accept_compression_encodings,
284340
send_compression_encodings: self.send_compression_encodings,
341+
max_decoding_message_size: self.max_decoding_message_size,
342+
max_encoding_message_size: self.max_encoding_message_size,
285343
}
286344
}
287345
}
288346
impl<T: LogsService> Clone for _Inner<T> {
289347
fn clone(&self) -> Self {
290-
Self(self.0.clone())
348+
Self(Arc::clone(&self.0))
291349
}
292350
}
293351
impl<T: std::fmt::Debug> std::fmt::Debug for _Inner<T> {

opentelemetry-proto/src/proto/tonic/opentelemetry.proto.collector.metrics.v1.rs

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub mod metrics_service_client {
6767
/// Attempt to create a new client by connecting to a given endpoint.
6868
pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
6969
where
70-
D: std::convert::TryInto<tonic::transport::Endpoint>,
70+
D: TryInto<tonic::transport::Endpoint>,
7171
D::Error: Into<StdError>,
7272
{
7373
let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
@@ -123,12 +123,28 @@ pub mod metrics_service_client {
123123
self.inner = self.inner.accept_compressed(encoding);
124124
self
125125
}
126+
/// Limits the maximum size of a decoded message.
127+
///
128+
/// Default: `4MB`
129+
#[must_use]
130+
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
131+
self.inner = self.inner.max_decoding_message_size(limit);
132+
self
133+
}
134+
/// Limits the maximum size of an encoded message.
135+
///
136+
/// Default: `usize::MAX`
137+
#[must_use]
138+
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
139+
self.inner = self.inner.max_encoding_message_size(limit);
140+
self
141+
}
126142
/// For performance reasons, it is recommended to keep this RPC
127143
/// alive for the entire life of the application.
128144
pub async fn export(
129145
&mut self,
130146
request: impl tonic::IntoRequest<super::ExportMetricsServiceRequest>,
131-
) -> Result<
147+
) -> std::result::Result<
132148
tonic::Response<super::ExportMetricsServiceResponse>,
133149
tonic::Status,
134150
> {
@@ -145,7 +161,15 @@ pub mod metrics_service_client {
145161
let path = http::uri::PathAndQuery::from_static(
146162
"/opentelemetry.proto.collector.metrics.v1.MetricsService/Export",
147163
);
148-
self.inner.unary(request.into_request(), path, codec).await
164+
let mut req = request.into_request();
165+
req.extensions_mut()
166+
.insert(
167+
GrpcMethod::new(
168+
"opentelemetry.proto.collector.metrics.v1.MetricsService",
169+
"Export",
170+
),
171+
);
172+
self.inner.unary(req, path, codec).await
149173
}
150174
}
151175
}
@@ -161,7 +185,10 @@ pub mod metrics_service_server {
161185
async fn export(
162186
&self,
163187
request: tonic::Request<super::ExportMetricsServiceRequest>,
164-
) -> Result<tonic::Response<super::ExportMetricsServiceResponse>, tonic::Status>;
188+
) -> std::result::Result<
189+
tonic::Response<super::ExportMetricsServiceResponse>,
190+
tonic::Status,
191+
>;
165192
}
166193
/// Service that can be used to push metrics between one Application
167194
/// instrumented with OpenTelemetry and a collector, or between a collector and a
@@ -171,6 +198,8 @@ pub mod metrics_service_server {
171198
inner: _Inner<T>,
172199
accept_compression_encodings: EnabledCompressionEncodings,
173200
send_compression_encodings: EnabledCompressionEncodings,
201+
max_decoding_message_size: Option<usize>,
202+
max_encoding_message_size: Option<usize>,
174203
}
175204
struct _Inner<T>(Arc<T>);
176205
impl<T: MetricsService> MetricsServiceServer<T> {
@@ -183,6 +212,8 @@ pub mod metrics_service_server {
183212
inner,
184213
accept_compression_encodings: Default::default(),
185214
send_compression_encodings: Default::default(),
215+
max_decoding_message_size: None,
216+
max_encoding_message_size: None,
186217
}
187218
}
188219
pub fn with_interceptor<F>(
@@ -206,6 +237,22 @@ pub mod metrics_service_server {
206237
self.send_compression_encodings.enable(encoding);
207238
self
208239
}
240+
/// Limits the maximum size of a decoded message.
241+
///
242+
/// Default: `4MB`
243+
#[must_use]
244+
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
245+
self.max_decoding_message_size = Some(limit);
246+
self
247+
}
248+
/// Limits the maximum size of an encoded message.
249+
///
250+
/// Default: `usize::MAX`
251+
#[must_use]
252+
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
253+
self.max_encoding_message_size = Some(limit);
254+
self
255+
}
209256
}
210257
impl<T, B> tonic::codegen::Service<http::Request<B>> for MetricsServiceServer<T>
211258
where
@@ -219,7 +266,7 @@ pub mod metrics_service_server {
219266
fn poll_ready(
220267
&mut self,
221268
_cx: &mut Context<'_>,
222-
) -> Poll<Result<(), Self::Error>> {
269+
) -> Poll<std::result::Result<(), Self::Error>> {
223270
Poll::Ready(Ok(()))
224271
}
225272
fn call(&mut self, req: http::Request<B>) -> Self::Future {
@@ -241,13 +288,15 @@ pub mod metrics_service_server {
241288
&mut self,
242289
request: tonic::Request<super::ExportMetricsServiceRequest>,
243290
) -> Self::Future {
244-
let inner = self.0.clone();
291+
let inner = Arc::clone(&self.0);
245292
let fut = async move { (*inner).export(request).await };
246293
Box::pin(fut)
247294
}
248295
}
249296
let accept_compression_encodings = self.accept_compression_encodings;
250297
let send_compression_encodings = self.send_compression_encodings;
298+
let max_decoding_message_size = self.max_decoding_message_size;
299+
let max_encoding_message_size = self.max_encoding_message_size;
251300
let inner = self.inner.clone();
252301
let fut = async move {
253302
let inner = inner.0;
@@ -257,6 +306,10 @@ pub mod metrics_service_server {
257306
.apply_compression_config(
258307
accept_compression_encodings,
259308
send_compression_encodings,
309+
)
310+
.apply_max_message_size_config(
311+
max_decoding_message_size,
312+
max_encoding_message_size,
260313
);
261314
let res = grpc.unary(method, req).await;
262315
Ok(res)
@@ -285,12 +338,14 @@ pub mod metrics_service_server {
285338
inner,
286339
accept_compression_encodings: self.accept_compression_encodings,
287340
send_compression_encodings: self.send_compression_encodings,
341+
max_decoding_message_size: self.max_decoding_message_size,
342+
max_encoding_message_size: self.max_encoding_message_size,
288343
}
289344
}
290345
}
291346
impl<T: MetricsService> Clone for _Inner<T> {
292347
fn clone(&self) -> Self {
293-
Self(self.0.clone())
348+
Self(Arc::clone(&self.0))
294349
}
295350
}
296351
impl<T: std::fmt::Debug> std::fmt::Debug for _Inner<T> {

0 commit comments

Comments
 (0)