Move futures compatibility code to a new tokio-trace-futures crate (#33)

Closes #20. Also needed for #23.

This PR moves the instrumented future types to their own separate crate.
This commit is contained in:
Eliza Weisman 2018-10-02 12:44:29 -07:00 committed by GitHub
parent d2f5590e7f
commit d782db13b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 70 additions and 50 deletions

View File

@ -2,6 +2,7 @@
members = [
"tokio-trace",
"tokio-trace-futures",
"tokio-trace-tower",
"tokio-trace-tower-http",
"tokio-trace-log",

View File

@ -10,6 +10,7 @@ log = "0.4"
[dev-dependencies]
tokio-trace = { path = "../tokio-trace" }
tokio-trace-futures = { path = "../tokio-trace-futures" }
hyper = "0.12"
futures = "0.1"
ansi_term = "0.11"

View File

@ -2,6 +2,7 @@ extern crate futures;
extern crate hyper;
#[macro_use]
extern crate tokio_trace;
extern crate tokio_trace_futures;
extern crate tokio_trace_env_logger;
extern crate tokio;
@ -17,10 +18,8 @@ use std::str;
mod sloggish;
use self::sloggish::SloggishSubscriber;
use tokio_trace::{
Level,
instrument::{Instrument, Instrumented},
};
use tokio_trace::Level;
use tokio_trace_futures::{Instrument, Instrumented};
type BoxFut = Box<dyn Future<Item = Response<Body>, Error = hyper::Error> + Send>;

View File

@ -0,0 +1,11 @@
[package]
name = "tokio-trace-futures"
version = "0.0.1"
authors = ["Eliza Weisman <eliza@buoyant.io>"]
[dependencies]
futures = "0.1"
tokio-trace = { path = "../tokio-trace" }
[dev-dependencies]
tokio-trace = { path = "../tokio-trace", features = ["test-support"] }

View File

@ -1,4 +1,8 @@
use super::Span;
#[cfg_attr(test, macro_use)]
extern crate tokio_trace;
extern crate futures;
use tokio_trace::Span;
use futures::{Async, Future, Sink, Stream, Poll, StartSend};
// TODO: seal?
@ -92,7 +96,7 @@ impl<T: Sink> Sink for Instrumented<T> {
#[cfg(test)]
mod tests {
use futures::{prelude::*, task, future, stream};
use ::{span, subscriber};
use tokio_trace::{span, subscriber};
use super::*;
#[test]
@ -131,7 +135,7 @@ mod tests {
)
.run();
MyFuture { polls: 0 }
.instrument(span!("foo",))
.instrument(span!("foo"))
.wait().unwrap();
}
@ -166,7 +170,7 @@ mod tests {
.with_state(span::State::Idle)
)
.run();
let foo = span!("foo",);
let foo = span!("foo");
MyFuture { polls: 0 }
.instrument(foo.clone())
.wait().unwrap();
@ -204,7 +208,7 @@ mod tests {
)
.run();
MyFuture { polls: 0 }
.instrument(span!("foo",))
.instrument(span!("foo"))
.wait().unwrap_err();
}
@ -233,7 +237,7 @@ mod tests {
)
.run();
stream::iter_ok::<_, ()>(&[1, 2, 3])
.instrument(span!("foo",))
.instrument(span!("foo"))
.for_each(|_| { future::ok(()) })
.wait().unwrap();
}

View File

@ -6,6 +6,3 @@ authors = ["Eliza Weisman <eliza@buoyant.io>"]
[dependencies]
tokio-trace = { path = "../tokio-trace" }
log = "0.4"
[dev-dependencies]
env_logger = "0.5"

View File

@ -5,11 +5,11 @@ authors = ["Eliza Weisman <eliza@buoyant.io>"]
[dependencies]
tokio-trace = { path = "../tokio-trace" }
tokio-trace-futures = { path = "../tokio-trace-futures" }
futures = "0.1"
tower-service = { git = "https://github.com/tower-rs/tower.git" }
http = "0.1"
[dev-dependencies]
bytes = "0.4"
h2 = "0.1.11"

View File

@ -5,6 +5,7 @@ extern crate http;
extern crate tokio;
#[macro_use]
extern crate tokio_trace;
extern crate tokio_trace_futures;
extern crate tokio_trace_tower_http;
extern crate tower_h2;
extern crate tower_service;
@ -16,10 +17,8 @@ use tokio::net::TcpListener;
use tokio::runtime::Runtime;
use tower_h2::{Body, Server, RecvBody};
use tower_service::{NewService, Service};
use tokio_trace::{
Level,
instrument::Instrument,
};
use tokio_trace::Level;
use tokio_trace_futures::Instrument;
#[path = "../../tokio-trace/examples/sloggish/sloggish_subscriber.rs"]
mod sloggish;

View File

@ -2,10 +2,11 @@ extern crate tower_service;
extern crate http;
#[macro_use]
extern crate tokio_trace;
extern crate tokio_trace_futures;
extern crate futures;
use futures::{Future, Poll};
use tokio_trace::instrument::{Instrumented, Instrument};
use tokio_trace_futures::{Instrumented, Instrument};
use tower_service::{Service, NewService};
#[derive(Clone, Debug)]

View File

@ -5,5 +5,6 @@ authors = ["Eliza Weisman <eliza@buoyant.io>"]
[dependencies]
tokio-trace = { path = "../tokio-trace" }
tokio-trace-futures = { path = "../tokio-trace-futures" }
futures = "0.1"
tower-service = { git = "https://github.com/tower-rs/tower.git" }

View File

@ -1,9 +1,10 @@
extern crate tower_service;
#[macro_use]
extern crate tokio_trace;
extern crate tokio_trace_futures;
extern crate futures;
use tokio_trace::instrument::{Instrumented, Instrument};
use tokio_trace_futures::{Instrumented, Instrument};
use tower_service::Service;
use std::fmt;

View File

@ -3,6 +3,10 @@ name = "tokio-trace"
version = "0.1.0"
authors = ["Eliza Weisman <eliza@buoyant.io>"]
[features]
default = []
test-support = []
[dependencies]
futures = "0.1"

View File

@ -117,31 +117,6 @@ use std::{fmt, slice, time::Instant};
use self::dedup::IteratorDedup;
#[repr(usize)]
#[derive(Copy, Eq, Debug, Hash)]
pub enum Level {
/// The "error" level.
///
/// Designates very serious errors.
Error = 1, // This way these line up with the discriminants for LevelFilter below
/// The "warn" level.
///
/// Designates hazardous situations.
Warn,
/// The "info" level.
///
/// Designates useful information.
Info,
/// The "debug" level.
///
/// Designates lower priority information.
Debug,
/// The "trace" level.
///
/// Designates very low priority, often extremely verbose, information.
Trace,
}
#[doc(hidden)]
#[macro_export]
macro_rules! static_meta {
@ -255,9 +230,33 @@ macro_rules! event {
($lvl:expr, { $($k:ident = $val:expr),* }, $($arg:tt)+ ) => (event!(target: None, $lvl, { $($k = $val),* }, $($arg)+))
}
#[repr(usize)]
#[derive(Copy, Eq, Debug, Hash)]
pub enum Level {
/// The "error" level.
///
/// Designates very serious errors.
Error = 1, // This way these line up with the discriminants for LevelFilter below
/// The "warn" level.
///
/// Designates hazardous situations.
Warn,
/// The "info" level.
///
/// Designates useful information.
Info,
/// The "debug" level.
///
/// Designates lower priority information.
Debug,
/// The "trace" level.
///
/// Designates very low priority, often extremely verbose, information.
Trace,
}
mod dedup;
mod dispatcher;
pub mod instrument;
pub mod span;
pub mod subscriber;

View File

@ -542,9 +542,10 @@ impl cmp::PartialEq for DataInner {
}
}
#[cfg(test)]
#[cfg(any(test, feature = "test-support"))]
pub use self::test_support::*;
#[cfg(test)]
#[cfg(any(test, feature = "test-support"))]
mod test_support {
use ::{ Value, span::State };
use std::collections::HashMap;

View File

@ -98,9 +98,10 @@ where
}
}
#[cfg(test)]
#[cfg(any(test, feature = "test-support"))]
pub use self::test_support::*;
#[cfg(test)]
#[cfg(any(test, feature = "test-support"))]
mod test_support {
use super::Subscriber;
use ::{Event, SpanData, Meta};