Skip to content
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

Update example and optional dependencies #568

Merged
merged 2 commits into from Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/tracing-grpc/Cargo.toml
Expand Up @@ -16,11 +16,11 @@ http = "0.2"
tonic = "0.4"
prost = "0.7"
tokio = { version = "1.0", features = ["full"] }
opentelemetry = "0.12"
opentelemetry-jaeger = "0.11"
opentelemetry = { version = "0.14", features = ["rt-tokio"] }
opentelemetry-jaeger = "0.13"
tracing = "0.1"
tracing-subscriber = "0.2"
tracing-opentelemetry = "0.11"
tracing-opentelemetry = "0.13"
tracing-futures = "0.2"

[build-dependencies]
Expand Down
6 changes: 4 additions & 2 deletions examples/tracing-grpc/src/client.rs
Expand Up @@ -53,15 +53,17 @@ async fn greet() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
global::set_text_map_propagator(TraceContextPropagator::new());
let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline()
let tracer = opentelemetry_jaeger::new_pipeline()
.with_service_name("grpc-client")
.install()?;
.install_simple()?;
tracing_subscriber::registry()
.with(tracing_subscriber::EnvFilter::new("INFO"))
.with(tracing_opentelemetry::layer().with_tracer(tracer))
.try_init()?;

greet().await?;

opentelemetry::global::shutdown_tracer_provider();

Ok(())
}
6 changes: 4 additions & 2 deletions examples/tracing-grpc/src/server.rs
Expand Up @@ -66,9 +66,9 @@ impl Greeter for MyGreeter {
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
global::set_text_map_propagator(TraceContextPropagator::new());
let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline()
let tracer = opentelemetry_jaeger::new_pipeline()
.with_service_name("grpc-server")
.install()?;
.install_batch(opentelemetry::runtime::Tokio)?;
tracing_subscriber::registry()
.with(tracing_subscriber::EnvFilter::new("INFO"))
.with(tracing_opentelemetry::layer().with_tracer(tracer))
Expand All @@ -82,5 +82,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>
.serve(addr)
.await?;

opentelemetry::global::shutdown_tracer_provider();

Ok(())
}
2 changes: 1 addition & 1 deletion opentelemetry-datadog/Cargo.toml
Expand Up @@ -40,5 +40,5 @@ lazy_static = "1.4"
base64 = "0.13"
bytes = "1"
futures-util = "0.3"
isahc = "0.9"
isahc = "1.4"
opentelemetry = { path = "../opentelemetry", features = ["trace", "testing"] }
14 changes: 6 additions & 8 deletions opentelemetry-datadog/src/lib.rs
Expand Up @@ -96,19 +96,17 @@
//! #[derive(Debug)]
//! struct IsahcClient(isahc::HttpClient);
//!
//! async fn body_to_bytes(mut body: isahc::Body) -> Result<Bytes, HttpError> {
//! let mut bytes = Vec::with_capacity(body.len().unwrap_or(0).try_into()?);
//! let _ = body.read_to_end(&mut bytes).await?;
//! Ok(bytes.into())
//! }
//!
//! #[async_trait]
//! impl HttpClient for IsahcClient {
//! async fn send(&self, request: Request<Vec<u8>>) -> Result<Response<Bytes>, HttpError> {
//! let response = self.0.send_async(request).await?;
//! let mut response = self.0.send_async(request).await?;
//! let status = response.status();
//! let mut bytes = Vec::with_capacity(response.body().len().unwrap_or(0).try_into()?);
//! isahc::AsyncReadResponseExt::copy_to(&mut response, &mut bytes).await?;
//!
//! Ok(Response::builder()
//! .status(response.status())
//! .body(body_to_bytes(response.into_body()).await?)?)
//! .body(bytes.into())?)
//! }
//! }
//!
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-http/Cargo.toml
Expand Up @@ -14,7 +14,7 @@ async-trait = "0.1"
bytes = "1"
futures-util = { version = "0.3", default-features = false, features = ["io"] }
http = "0.2"
isahc = { version = "0.9", default-features = false, optional = true }
isahc = { version = "1.4", default-features = false, optional = true }
opentelemetry = { version = "0.14", path = "../opentelemetry", features = ["trace"] }
reqwest = { version = "0.11", default-features = false, features = ["blocking"], optional = true }
surf = { version = "2.0", default-features = false, optional = true }
14 changes: 5 additions & 9 deletions opentelemetry-http/src/lib.rs
Expand Up @@ -113,24 +113,20 @@ mod surf {
#[cfg(feature = "isahc")]
mod isahc {
use super::{async_trait, Bytes, HttpClient, HttpError, Request, Response};
use futures_util::io::AsyncReadExt as _;
use isahc::AsyncReadResponseExt;
use std::convert::TryInto as _;

#[async_trait]
impl HttpClient for isahc::HttpClient {
async fn send(&self, request: Request<Vec<u8>>) -> Result<Response<Bytes>, HttpError> {
let response = self.send_async(request).await?;
let mut response = self.send_async(request).await?;
let mut bytes = Vec::with_capacity(response.body().len().unwrap_or(0).try_into()?);
response.copy_to(&mut bytes).await?;
Ok(Response::builder()
.status(response.status())
.body(body_to_bytes(response.into_body()).await?)?)
.body(bytes.into())?)
}
}

async fn body_to_bytes(mut body: isahc::Body) -> Result<Bytes, HttpError> {
let mut bytes = Vec::with_capacity(body.len().unwrap_or(0).try_into()?);
let _ = body.read_to_end(&mut bytes).await?;
Ok(bytes.into())
}
}

/// Methods to make working with responses from the [`HttpClient`] trait easier.
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-jaeger/Cargo.toml
Expand Up @@ -25,7 +25,7 @@ async-trait = "0.1"
base64 = { version = "0.13", optional = true }
futures-util = { version = "0.3", optional = true }
http = { version = "0.2", optional = true }
isahc = { version = "0.9", default-features = false, optional = true }
isahc = { version = "1.4", default-features = false, optional = true }
js-sys = { version = "0.3", optional = true }
opentelemetry = { version = "0.14", default-features = false, features = ["trace"], path = "../opentelemetry" }
opentelemetry-http = { version = "0.3", path = "../opentelemetry-http", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-otlp/Cargo.toml
Expand Up @@ -37,7 +37,7 @@ rustdoc-args = ["--cfg", "docsrs"]
[dependencies]
async-trait = "0.1"
futures = "0.3"
grpcio = { version = "0.8", optional = true }
grpcio = { version = "0.9", optional = true }
opentelemetry = { version = "0.14", default-features = false, features = ["trace"], path = "../opentelemetry" }
prost = { version = "0.7", optional = true }
protobuf = { version = "2.18", optional = true }
Expand All @@ -53,7 +53,7 @@ http = "0.2"
chrono = "0.4"
tokio-stream = { version = "0.1", features = ["net"] }
protobuf-codegen = { version = "2.16"}
protoc-grpcio = { version = "2.0"}
protoc-grpcio = { version = "3.0"}

[features]
trace = ["opentelemetry/trace"]
Expand Down
2 changes: 0 additions & 2 deletions opentelemetry-otlp/src/proto/grpcio/metrics_service_grpc.rs
Expand Up @@ -5,8 +5,6 @@
#![allow(unknown_lints)]
#![allow(clippy::all)]

#![cfg_attr(rustfmt, rustfmt_skip)]

#![allow(box_pointers)]
#![allow(dead_code)]
#![allow(missing_docs)]
Expand Down
2 changes: 0 additions & 2 deletions opentelemetry-otlp/src/proto/grpcio/trace_service_grpc.rs
Expand Up @@ -5,8 +5,6 @@
#![allow(unknown_lints)]
#![allow(clippy::all)]

#![cfg_attr(rustfmt, rustfmt_skip)]

#![allow(box_pointers)]
#![allow(dead_code)]
#![allow(missing_docs)]
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-zipkin/Cargo.toml
Expand Up @@ -32,7 +32,7 @@ opentelemetry = { version = "0.14", path = "../opentelemetry", features = ["trac
opentelemetry-http = { version = "0.3", path = "../opentelemetry-http", optional = true }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
typed-builder = "0.7"
typed-builder = "0.9"
lazy_static = "1.4"
http = "0.2"
reqwest = { version = "0.11", optional = true, default-features = false }
Expand All @@ -42,5 +42,5 @@ thiserror = { version = "1.0"}
[dev-dependencies]
bytes = "1"
futures-util = "0.3"
isahc = "=0.9.6"
isahc = "1.4"
opentelemetry = { version = "0.14", default-features = false, features = ["trace", "testing"], path = "../opentelemetry" }
14 changes: 6 additions & 8 deletions opentelemetry-zipkin/src/lib.rs
Expand Up @@ -105,19 +105,17 @@
//! #[derive(Debug)]
//! struct IsahcClient(isahc::HttpClient);
//!
//! async fn body_to_bytes(mut body: isahc::Body) -> Result<Bytes, HttpError> {
//! let mut bytes = Vec::with_capacity(body.len().unwrap_or(0).try_into()?);
//! let _ = body.read_to_end(&mut bytes).await?;
//! Ok(bytes.into())
//! }
//!
//! #[async_trait]
//! impl HttpClient for IsahcClient {
//! async fn send(&self, request: Request<Vec<u8>>) -> Result<Response<Bytes>, HttpError> {
//! let response = self.0.send_async(request).await?;
//! let mut response = self.0.send_async(request).await?;
//! let status = response.status();
//! let mut bytes = Vec::with_capacity(response.body().len().unwrap_or(0).try_into()?);
//! isahc::AsyncReadResponseExt::copy_to(&mut response, &mut bytes).await?;
//!
//! Ok(Response::builder()
//! .status(response.status())
//! .body(body_to_bytes(response.into_body()).await?)?)
//! .body(bytes.into())?)
//! }
//! }
//!
Expand Down