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

chore: cleanup pin-project dep #830

Merged
merged 3 commits into from Jul 16, 2022
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
4 changes: 2 additions & 2 deletions opentelemetry-api/Cargo.toml
Expand Up @@ -10,7 +10,7 @@ futures-channel = "0.3"
futures-util = { version = "0.3", default-features = false, features = ["std", "sink"] }
indexmap = "=1.8"
once_cell = "1.12.0"
pin-project = { version = "1.0.2", optional = true }
pin-project-lite = { version = "0.2.9", optional = true }
thiserror = "1"
tokio-stream = { version = "0.1", optional = true }

Expand All @@ -23,6 +23,6 @@ js-sys = "0.3"

[features]
default = ["trace"]
trace = ["pin-project"]
trace = ["pin-project-lite"]
metrics = ["fnv"]
testing = ["trace"]
17 changes: 9 additions & 8 deletions opentelemetry-api/src/trace/context.rs
Expand Up @@ -6,7 +6,7 @@ use crate::{
};
use futures_util::{sink::Sink, stream::Stream};
use once_cell::sync::Lazy;
use pin_project::pin_project;
use pin_project_lite::pin_project;
use std::{
borrow::Cow,
error::Error,
Expand Down Expand Up @@ -351,13 +351,14 @@ where
f(Context::current().span())
}

/// A future, stream, or sink that has an associated context.
#[pin_project]
#[derive(Clone, Debug)]
pub struct WithContext<T> {
#[pin]
inner: T,
otel_cx: Context,
pin_project! {
/// A future, stream, or sink that has an associated context.
#[derive(Clone, Debug)]
pub struct WithContext<T> {
#[pin]
inner: T,
otel_cx: Context,
}
}

impl<T: Sized> FutureExt for T {}
Expand Down
2 changes: 0 additions & 2 deletions opentelemetry-dynatrace/Cargo.toml
Expand Up @@ -42,7 +42,6 @@ wasm = [
"futures-util",
"getrandom/js",
"js-sys",
"pin-project",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
Expand All @@ -59,7 +58,6 @@ isahc = { version = "1.4", default-features = false, optional = true }
js-sys = { version = "0.3.5", optional = true }
opentelemetry = { version = "0.17", path = "../opentelemetry", default-features = false }
opentelemetry-http = { version = "0.6", path = "../opentelemetry-http", default-features = false }
pin-project = { version = "1.0", optional = true }
reqwest = { version = "0.11", default-features = false, optional = true }
surf = { version = "2.0", default-features = false, optional = true }
thiserror = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-jaeger/Cargo.toml
Expand Up @@ -33,7 +33,7 @@ once_cell = "1.12"
opentelemetry = { version = "0.17", default-features = false, features = ["trace"], path = "../opentelemetry" }
opentelemetry-http = { version = "0.6", path = "../opentelemetry-http", optional = true }
opentelemetry-semantic-conventions = { version = "0.9", path = "../opentelemetry-semantic-conventions" }
pin-project = { version = "1.0", optional = true }
pin-project-lite = { version = "0.2.9", optional = true }
reqwest = { version = "0.11", default-features = false, optional = true }
surf = { version = "2.0", optional = true }
thiserror = "1.0"
Expand Down Expand Up @@ -90,7 +90,7 @@ wasm_collector_client = [
"futures-util",
"http",
"js-sys",
"pin-project",
"pin-project-lite",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
Expand Down
20 changes: 12 additions & 8 deletions opentelemetry-jaeger/src/exporter/collector.rs
Expand Up @@ -77,6 +77,7 @@ mod wasm_collector_client {
use futures_util::future;
use http::Uri;
use js_sys::Uint8Array;
use pin_project_lite::pin_project;
use std::future::Future;
use std::io::{self, Cursor};
use std::pin::Pin;
Expand Down Expand Up @@ -132,7 +133,7 @@ mod wasm_collector_client {
{
self.build_request(batch)
.map(post_request)
.map(|fut| future::Either::Left(SubmitBatchFuture(fut)))
.map(|fut| future::Either::Left(SubmitBatchFuture { fut }))
.unwrap_or_else(|e| future::Either::Right(future::err(e)))
}

Expand Down Expand Up @@ -199,19 +200,22 @@ mod wasm_collector_client {
Ok(jaeger::BatchSubmitResponse { ok: true })
}

/// Wrapper of web fetch API future marked as Send.
///
/// At the moment, the web APIs are single threaded. Since all opentelemetry futures are
/// required to be Send, we mark this future as Send.
#[pin_project::pin_project]
struct SubmitBatchFuture<F>(#[pin] F);
pin_project! {
/// Wrapper of web fetch API future marked as Send.
///
/// At the moment, the web APIs are single threaded. Since all opentelemetry futures are
/// required to be Send, we mark this future as Send.
struct SubmitBatchFuture<F> {
#[pin] fut: F
}
}

unsafe impl<F> Send for SubmitBatchFuture<F> {}

impl<F: Future> Future for SubmitBatchFuture<F> {
type Output = F::Output;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
self.project().0.poll(cx)
self.project().fut.poll(cx)
}
}

Expand Down
3 changes: 1 addition & 2 deletions opentelemetry-sdk/Cargo.toml
Expand Up @@ -17,7 +17,6 @@ futures-executor = "0.3"
futures-util = { version = "0.3.17", default-features = false, features = ["std", "sink", "async-await-macro"] }
once_cell = "1.10"
percent-encoding = { version = "2.0", optional = true }
pin-project = { version = "1.0.2", optional = true }
rand = { version = "0.8", default-features = false, features = ["std", "std_rng"], optional = true }
serde = { version = "1.0", features = ["derive", "rc"], optional = true }
serde_json = { version = "1", optional = true }
Expand All @@ -38,7 +37,7 @@ rand_distr = "0.4.0"

[features]
default = ["trace"]
trace = ["opentelemetry-api/trace", "crossbeam-channel", "rand", "pin-project", "async-trait", "percent-encoding"]
trace = ["opentelemetry-api/trace", "crossbeam-channel", "rand", "async-trait", "percent-encoding"]
jaeger_remote_sampler = ["trace", "opentelemetry-http", "http", "serde", "serde_json", "url"]
metrics = ["opentelemetry-api/metrics", "dashmap", "fnv"]
testing = ["opentelemetry-api/testing", "trace", "metrics", "rt-async-std", "rt-tokio", "rt-tokio-current-thread", "tokio/macros", "tokio/rt-multi-thread"]
Expand Down