mirror of
https://github.com/tokio-rs/tracing.git
synced 2025-10-02 07:20:35 +00:00
meta: consolidate & clean up crates (#323)
## Motivation `tracing` currently consists of a large number of crates. The number of crates has the potential to be quite intimidating to users. ## Solution This branch makes the following changes: - Delete `tracing-fmt`. This crate's functionality has already been moved into `tracing-subscriber`, and a final version has been published to deprecate the crate & link to the code's new home. - Delete `tracing-tower-http`, as this functionality is now subsumed by `tracing-tower`. Since the crate was never published, we do not need to deprecate it. - Delete `tracing-slog`. This crate was never implemented, so we can just remove it from the repository. It can be re-created if we ever implement `slog` integration. - Move `tracing-env-logger` into a `tracing-log` module, and feature flag it. I updated some of the APIs as well. - Remove deleted crates from documentation. This makes most of the changes discussed in #308. Closes #308 Signed-off-by: Eliza Weisman <eliza@buoyant.io>
This commit is contained in:
parent
c38c247f53
commit
8bd4d90e78
@ -4,13 +4,9 @@ members = [
|
||||
"tracing",
|
||||
"tracing-core",
|
||||
"tracing-attributes",
|
||||
"tracing-fmt",
|
||||
"tracing-futures",
|
||||
"tracing-tower",
|
||||
"tracing-tower-http",
|
||||
"tracing-log",
|
||||
"tracing-env-logger",
|
||||
"tracing-slog",
|
||||
"tracing-macros",
|
||||
"tracing-subscriber",
|
||||
"tracing-serde",
|
||||
|
21
README.md
21
README.md
@ -63,9 +63,6 @@ state, and are less stable than the `tracing` and `tracing-core` crates.
|
||||
|
||||
The crates included as part of Tracing are:
|
||||
|
||||
* [`tracing-fmt`]: A subscriber for formatting and logging trace events.
|
||||
([crates.io][fmt-crates]|[docs][fmt-docs])
|
||||
|
||||
* [`tracing-futures`]: Utilities for instrumenting `futures`.
|
||||
([crates.io][fut-crates]|[docs][fut-docs])
|
||||
|
||||
@ -76,36 +73,26 @@ The crates included as part of Tracing are:
|
||||
|
||||
* [`tracing-log`]: Compatibility with the `log` crate (unstable).
|
||||
|
||||
* [`tracing-env-logger`]: A subscriber that logs trace events using the
|
||||
`env_logger` crate (unstable).
|
||||
|
||||
* [`tracing-serde`]: A compatibility layer for serializing trace data with
|
||||
`serde` (unstable).
|
||||
|
||||
* [`tracing-subscriber`]: Utilities for implementing and composing
|
||||
`Subscriber`s. ([crates.io][sub-crates]|[docs][sub-docs])
|
||||
* [`tracing-subscriber`]: Subscriber implementations, and utilities for
|
||||
implementing and composing `Subscriber`s.
|
||||
([crates.io][sub-crates]|[docs][sub-docs])
|
||||
|
||||
* [`tracing-tower`]: Compatibility with the `tower` ecosystem (unstable).
|
||||
|
||||
* [`tracing-tower-http`]: `tower` compatibility for HTTP services (unstable).
|
||||
|
||||
[`tracing`]: tracing
|
||||
[`tracing-core`]: tracing
|
||||
[`tracing-fmt`]: tracing-fmt
|
||||
[`tracing-futures`]: tracing-futures
|
||||
[`tracing-macros`]: tracing-macros
|
||||
[`tracing-attributes`]: tracing-attributes
|
||||
[`tracing-log`]: tracing-log
|
||||
[`tracing-env-logger`]: tracing-env-logger
|
||||
[`tracing-serde`]: tracing-serde
|
||||
[`tracing-subscriber`]: tracing-subscriber
|
||||
[`tracing-tower`]: tracing-tower
|
||||
[`tracing-tower-http`]: tracing-tower-http
|
||||
|
||||
[fmt-crates]: https://crates.io/crates/tracing-fmt
|
||||
[fmt-docs]: https://docs.rs/tracing-fmt/0.0.1-alpha.2
|
||||
|
||||
[fut-crates]: https://crates.io/crates/tracing-futures/0.0.1-alpha.1
|
||||
[fut-crates]: https://crates.io/crates/tracing-futures
|
||||
[fut-docs]: https://docs.rs/tracing-futures
|
||||
|
||||
[attr-crates]: https://crates.io/crates/tracing-attributes
|
||||
|
@ -13,8 +13,7 @@ tracing-tower = { version = "0.1.0", path = "../tracing-tower" }
|
||||
tracing-subscriber = { version = "0.1", path = "../tracing-subscriber" }
|
||||
tracing-futures = { version = "0.0.1-alpha.1", path = "../tracing-futures" }
|
||||
tracing-attributes = "0.1.2"
|
||||
tracing-log = { path = "../tracing-log", version = "0.1" }
|
||||
tracing-env-logger = { path = "../tracing-env-logger" }
|
||||
tracing-log = { path = "../tracing-log", version = "0.1.1", features = ["env_logger"] }
|
||||
tracing-serde = { path = "../tracing-serde" }
|
||||
|
||||
# serde example
|
||||
@ -25,7 +24,7 @@ tokio = "0.1"
|
||||
hyper = "0.12"
|
||||
|
||||
# env-logger example
|
||||
env_logger = "0.5"
|
||||
env_logger = "0.6"
|
||||
|
||||
# tower examples
|
||||
bytes = "0.4"
|
||||
|
@ -107,12 +107,15 @@ fn echo(req: Request<Body>) -> Instrumented<BoxFut> {
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
use tracing_log::env_logger::BuilderExt;
|
||||
|
||||
let subscriber = tracing_subscriber::FmtSubscriber::new();
|
||||
let mut builder = env_logger::Builder::new();
|
||||
builder
|
||||
.filter(Some("hyper_echo"), log::LevelFilter::Off)
|
||||
.filter(Some("hyper"), log::LevelFilter::Trace);
|
||||
tracing_env_logger::try_init_from_builder(builder)?;
|
||||
.filter(Some("hyper"), log::LevelFilter::Trace)
|
||||
.emit_traces() // from `tracing_log::env_logger::BuilderExt`
|
||||
.try_init()?;
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
|
||||
let local_addr: std::net::SocketAddr = ([127, 0, 0, 1], 3000).into();
|
||||
|
@ -1,26 +0,0 @@
|
||||
[package]
|
||||
name = "tracing-env-logger"
|
||||
version = "0.1.0"
|
||||
authors = ["Eliza Weisman <eliza@buoyant.io>"]
|
||||
repository = "https://github.com/tokio-rs/tracing"
|
||||
homepage = "https://tokio.rs"
|
||||
documentation = "https://docs.rs/tracing-env-logger/0.1.0/tracing_env_logger"
|
||||
description = """
|
||||
A tracing subscriber that logs trace events using the `env_logger` crate
|
||||
"""
|
||||
categories = [
|
||||
"development-tools::debugging",
|
||||
"asynchronous",
|
||||
]
|
||||
keywords = ["logging", "tracing"]
|
||||
license = "MIT"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
tracing-log = { version = "0.1", path = "../tracing-log" }
|
||||
env_logger = "0.5"
|
||||
log = "0.4"
|
||||
|
||||
[badges]
|
||||
azure-devops = { project = "tracing/tracing", pipeline = "tokio-rs.tracing", build = "1" }
|
||||
maintenance = { status = "experimental" }
|
@ -1,18 +0,0 @@
|
||||
use env_logger;
|
||||
use log;
|
||||
use tracing_log;
|
||||
|
||||
pub fn try_init_from_builder(mut builder: env_logger::Builder) -> Result<(), log::SetLoggerError> {
|
||||
// TODO: make this an extension trait method
|
||||
builder
|
||||
.format(|_, record| tracing_log::format_trace(record))
|
||||
.try_init()
|
||||
}
|
||||
|
||||
pub fn try_init() -> Result<(), log::SetLoggerError> {
|
||||
try_init_from_builder(env_logger::Builder::from_default_env())
|
||||
}
|
||||
|
||||
pub fn init() {
|
||||
try_init().unwrap()
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
[package]
|
||||
name = "tracing-fmt"
|
||||
version = "0.1.1"
|
||||
authors = ["Eliza Weisman <eliza@buoyant.io>"]
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
repository = "https://github.com/tokio-rs/tracing"
|
||||
homepage = "https://tokio.rs"
|
||||
documentation = "https://docs.rs/tracing-fmt/0.1.1/tracing_fmt"
|
||||
description = """
|
||||
A `tracing` subscriber that formats and logs trace data. Moved to the `tracing-subscriber` crate.
|
||||
"""
|
||||
categories = [
|
||||
"development-tools::debugging",
|
||||
"asynchronous",
|
||||
]
|
||||
keywords = ["logging", "tracing"]
|
||||
readme = "README.md"
|
||||
|
||||
[badges]
|
||||
azure-devops = { project = "tracing/tracing", pipeline = "tokio-rs.tracing", build = "1" }
|
||||
maintenance = { status = "deprecated" }
|
||||
|
||||
[features]
|
||||
default = ["ansi", "chrono", "tracing-log"]
|
||||
|
||||
ansi = ["tracing-subscriber/ansi"]
|
||||
chrono = ["tracing-subscriber/chrono"]
|
||||
tracing-log = ["tracing-subscriber/tracing-log"]
|
||||
|
||||
[dependencies.tracing-subscriber]
|
||||
version = "0.1"
|
||||
features = ["fmt", "filter"]
|
||||
|
||||
[dev-dependencies]
|
||||
tracing = { version = "0.1" }
|
@ -1,54 +0,0 @@
|
||||
# tracing-fmt
|
||||
|
||||
**Note**: This library is now part of the [`tracing-subscriber`] crate. This
|
||||
crate now re-exports its public API from `tracing-subscriber`. Using
|
||||
`tracing-fmt` is now deprecated; users are encouraged to use the APIs in
|
||||
this library from their new home in `tracing-subscriber::fmt`.
|
||||
|
||||
[![Crates.io][crates-badge]][crates-url]
|
||||
[![Documentation][docs-badge]][docs-url]
|
||||
[![Documentation (master)][docs-master-badge]][docs-master-url]
|
||||
[![MIT licensed][mit-badge]][mit-url]
|
||||
[![Build Status][azure-badge]][azure-url]
|
||||
[![Gitter chat][gitter-badge]][gitter-url]
|
||||

|
||||
|
||||
|
||||
[Documentation][docs-url] |
|
||||
[Chat][gitter-url]
|
||||
|
||||
[tracing]: https://crates.io/crates/tracing
|
||||
[tracing-fmt]: https://github.com/tokio-rs/tracing/tree/master/tracing-fmt
|
||||
[crates-badge]: https://img.shields.io/crates/v/tracing-fmt.svg
|
||||
[crates-url]: https://crates.io/crates/tracing-fmt
|
||||
[docs-badge]: https://docs.rs/tracing-fmt/badge.svg
|
||||
[docs-url]: https://docs.rs/tracing-fmt
|
||||
[docs-master-badge]: https://img.shields.io/badge/docs-master-blue
|
||||
[docs-master-url]: https://tracing-rs.netlify.com/tracing_fmt
|
||||
[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg
|
||||
[mit-url]: LICENSE
|
||||
[azure-badge]: https://dev.azure.com/tracing/tracing/_apis/build/status/tokio-rs.tracing?branchName=master
|
||||
[azure-url]: https://dev.azure.com/tracing/tracing/_build/latest?definitionId=1&branchName=master
|
||||
[gitter-badge]: https://img.shields.io/gitter/room/tokio-rs/tracing.svg
|
||||
[gitter-url]: https://gitter.im/tokio-rs/tracing
|
||||
|
||||
|
||||
## Overview
|
||||
|
||||
[`tracing`][tracing] is a framework for instrumenting Rust programs with context-aware,
|
||||
structured, event-based diagnostic information. This crate provides an
|
||||
implementation of the [`Subscriber`] trait that records `tracing`'s `Event`s
|
||||
and `Span`s by formatting them as text and logging them to stdout.
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the [MIT license](LICENSE).
|
||||
|
||||
### Contribution
|
||||
|
||||
Unless you explicitly state otherwise, any contribution intentionally submitted
|
||||
for inclusion in Tracing by you, shall be licensed as MIT, without any additional
|
||||
terms or conditions.
|
||||
|
||||
[`Subscriber`]: https://docs.rs/tracing/latest/tracing/trait.Subscriber.html
|
||||
[`tracing-subscriber`]: https://crates.io/crates/tracing-subscriber/
|
@ -1,53 +0,0 @@
|
||||
//! A `Subscriber` for formatting and logging `tracing` data.
|
||||
//!
|
||||
//! **Note**: This library is now part of the [`tracing-subscriber`] crate. This
|
||||
//! crate now re-exports its public API from `tracing-subscriber`. Using
|
||||
//! `tracing-fmt` is now deprecated; users are encouraged to use the APIs in
|
||||
//! this library from their new home in `tracing-subscriber::fmt`.
|
||||
//!
|
||||
//! ## Overview
|
||||
//!
|
||||
//! [`tracing`] is a framework for instrumenting Rust programs with context-aware,
|
||||
//! structured, event-based diagnostic information. This crate provides an
|
||||
//! implementation of the [`Subscriber`] trait that records `tracing`'s `Event`s
|
||||
//! and `Span`s by formatting them as text and logging them to stdout.
|
||||
//!
|
||||
//!
|
||||
//! [`tracing`]: https://crates.io/crates/tracing
|
||||
//! [`Subscriber`]: https://docs.rs/tracing/latest/tracing/trait.Subscriber.html
|
||||
//! [`tracing-subscriber`]: https://crates.io/crates/tracing-subscriber/
|
||||
#![doc(html_root_url = "https://docs.rs/tracing-fmt/0.1.1")]
|
||||
#![cfg_attr(test, deny(warnings))]
|
||||
#![deprecated(since = "0.1.1", note = "moved to `tracing-subscriber::fmt`")]
|
||||
|
||||
#[deprecated(since = "0.1.1", note = "moved to `tracing-subscriber::fmt`")]
|
||||
#[doc(inline)]
|
||||
pub use crate::{format::FormatEvent, writer::MakeWriter};
|
||||
|
||||
#[deprecated(since = "0.1.1", note = "moved to `tracing-subscriber::fmt`")]
|
||||
#[doc(inline)]
|
||||
pub use tracing_subscriber::{fmt::Builder, fmt::Context, FmtSubscriber};
|
||||
|
||||
#[deprecated(since = "0.1.1", note = "moved to `tracing-subscriber::fmt::format`")]
|
||||
pub mod format {
|
||||
#[doc(inline)]
|
||||
pub use tracing_subscriber::fmt::format::*;
|
||||
}
|
||||
|
||||
#[deprecated(since = "0.1.1", note = "moved to `tracing-subscriber::fmt::writer`")]
|
||||
pub mod writer {
|
||||
#[doc(inline)]
|
||||
pub use tracing_subscriber::fmt::writer::*;
|
||||
}
|
||||
|
||||
#[deprecated(since = "0.1.1", note = "moved to `tracing-subscriber::fmt::time`")]
|
||||
pub mod time {
|
||||
#[doc(inline)]
|
||||
pub use tracing_subscriber::fmt::time::*;
|
||||
}
|
||||
|
||||
#[deprecated(since = "0.1.1", note = "moved to `tracing-subscriber::filter`")]
|
||||
pub mod filter {
|
||||
#[doc(inline)]
|
||||
pub use tracing_subscriber::Filter as EnvFilter;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tracing-log"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
authors = ["Tokio Contributors <team@tokio.rs>"]
|
||||
edition = "2018"
|
||||
repository = "https://github.com/tokio-rs/tracing"
|
||||
@ -26,6 +26,7 @@ trace-logger = []
|
||||
tracing-core = "0.1.2"
|
||||
log = { version = "0.4", features = ["std"] }
|
||||
lazy_static = "1.3.0"
|
||||
env_logger = { version = "0.6", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
tracing = "0.1"
|
||||
|
51
tracing-log/src/env_logger.rs
Normal file
51
tracing-log/src/env_logger.rs
Normal file
@ -0,0 +1,51 @@
|
||||
//! Utilities for configuring the `env_logger` crate to emit `tracing` events.
|
||||
use env_logger;
|
||||
use log;
|
||||
|
||||
/// Extension trait to configure an `env_logger::Builder` to emit traces.
|
||||
pub trait BuilderExt: crate::sealed::Sealed {
|
||||
/// Configure the built `env_logger::Logger` to emit `tracing` events for
|
||||
/// all consumed `log` records, rather than printing them to standard out.
|
||||
///
|
||||
/// Note that this replaces any previously configured formatting.
|
||||
fn emit_traces(&mut self) -> &mut Self;
|
||||
}
|
||||
|
||||
impl crate::sealed::Sealed for env_logger::Builder {}
|
||||
|
||||
impl BuilderExt for env_logger::Builder {
|
||||
fn emit_traces(&mut self) -> &mut Self {
|
||||
self.format(|_, record| super::format_trace(record))
|
||||
}
|
||||
}
|
||||
|
||||
/// Attempts to initialize the global logger with an env logger configured to
|
||||
/// emit `tracing` events.
|
||||
///
|
||||
/// This should be called early in the execution of a Rust program. Any log
|
||||
/// events that occur before initialization will be ignored.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function will fail if it is called more than once, or if another
|
||||
/// library has already initialized a global logger.
|
||||
pub fn try_init() -> Result<(), log::SetLoggerError> {
|
||||
env_logger::Builder::from_default_env()
|
||||
.emit_traces()
|
||||
.try_init()
|
||||
}
|
||||
|
||||
/// Initializes the global logger with an env logger configured to
|
||||
/// emit `tracing` events.
|
||||
///
|
||||
/// This should be called early in the execution of a Rust program. Any log
|
||||
/// events that occur before initialization will be ignored.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This function will panic if it is called more than once, or if another
|
||||
/// library has already initialized a global logger.
|
||||
pub fn init() {
|
||||
try_init()
|
||||
.expect("tracing_log::env_logger::init should not be called after logger initialized");
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
//! Adapters for connecting unstructured log records from the `log` crate into
|
||||
//! the `tracing` ecosystem.
|
||||
//!
|
||||
//! ## Overview
|
||||
//! # Overview
|
||||
//!
|
||||
//! [`tracing`] is a framework for instrumenting Rust programs with context-aware,
|
||||
//! structured, event-based diagnostic information. This crate provides
|
||||
@ -10,15 +10,18 @@
|
||||
//!
|
||||
//! This crate provides:
|
||||
//!
|
||||
//! - [`AsTrace`] and [`AsLog`] traits for converting between `tracing` and `log` types.
|
||||
//! - [`LogTracer`], a [`log::Log`] implementation that consumes [`log::Record`]s
|
||||
//! and outputs them as [`tracing::Event`].
|
||||
//! - [`TraceLogger`], a [`tracing::Subscriber`] implementation that consumes
|
||||
//! [`tracing::Event`]s and outputs [`log::Record`], allowing an existing logger
|
||||
//! implementation to be used to record trace events.
|
||||
//! - An [`env_logger`] module, with helpers for using the [`env_logger` crate]
|
||||
//! with `tracing` (optional, enabled by the `env-logger` feature).
|
||||
//!
|
||||
//! ## Usage
|
||||
//! # Usage
|
||||
//!
|
||||
//! ### Convert log records to tracing `Event`s
|
||||
//! ## Convert log records to tracing `Event`s
|
||||
//!
|
||||
//! To convert [`log::Record`]s as [`tracing::Event`]s, set `LogTracer` as the default
|
||||
//! logger by calling its [`init`] or [`init_with_filter`] methods.
|
||||
@ -45,12 +48,12 @@
|
||||
//! records emitted by dependencies which use `log` within the context of a
|
||||
//! trace.
|
||||
//!
|
||||
//! ### Convert tracing `Event`s to logs
|
||||
//! ## Convert tracing `Event`s to logs
|
||||
//!
|
||||
//! This conversion can be done with [`TraceLogger`], a [`Subscriber`] which
|
||||
//! records `tracing` spans and events and outputs log records.
|
||||
//!
|
||||
//! ### Caution: Mixing both conversions
|
||||
//! ## Caution: Mixing both conversions
|
||||
//!
|
||||
//! Note that logger implementations that convert log records to trace events
|
||||
//! should not be used with `Subscriber`s that convert trace events _back_ into
|
||||
@ -67,19 +70,25 @@
|
||||
//!
|
||||
//! * `trace-logger`: enables the `TraceLogger` type (on by default)
|
||||
//! * `log-tracer`: enables the `LogTracer` type (on by default)
|
||||
//! * `env_logger`: enables the `env_logger` module, with helpers for working
|
||||
//! with the [`env_logger` crate].
|
||||
//!
|
||||
//! [`init`]: struct.LogTracer.html#method.init
|
||||
//! [`init_with_filter`]: struct.LogTracer.html#method.init_with_filter
|
||||
//! [`AsTrace`]: trait.AsTrace.html
|
||||
//! [`AsLog`]: trait.AsLog.html
|
||||
//! [`LogTracer`]: struct.LogTracer.html
|
||||
//! [`TraceLogger`]: struct.TraceLogger.html
|
||||
//! [`env_logger`]: env_logger/index.html
|
||||
//! [`tracing`]: https://crates.io/crates/tracing
|
||||
//! [`log`]: https://crates.io/crates/log
|
||||
//! [`env_logger` crate]: https://crates.io/crates/env-logger
|
||||
//! [`log::Log`]: https://docs.rs/log/latest/log/trait.Log.html
|
||||
//! [`log::Record`]: https://docs.rs/log/latest/log/struct.Record.html
|
||||
//! [`tracing::Subscriber`]: https://docs.rs/tracing/latest/tracing/trait.Subscriber.html
|
||||
//! [`Subscriber`]: https://docs.rs/tracing/latest/tracing/trait.Subscriber.html
|
||||
//! [`tracing::Event`]: https://docs.rs/tracing/latest/tracing/struct.Event.html
|
||||
#![doc(html_root_url = "https://docs.rs/tracing-log/0.0.1-alpha.1")]
|
||||
#![doc(html_root_url = "https://docs.rs/tracing-log/0.1.1")]
|
||||
#![warn(
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
@ -142,6 +151,9 @@ pub use self::log_tracer::LogTracer;
|
||||
#[doc(inline)]
|
||||
pub use self::trace_logger::TraceLogger;
|
||||
|
||||
#[cfg(feature = "env_logger")]
|
||||
pub mod env_logger;
|
||||
|
||||
/// Format a log record as a trace event in the current span.
|
||||
pub fn format_trace(record: &log::Record<'_>) -> io::Result<()> {
|
||||
let filter_meta = record.as_trace();
|
||||
|
@ -1,20 +0,0 @@
|
||||
[package]
|
||||
name = "tracing-slog"
|
||||
version = "0.1.0"
|
||||
authors = ["David Barsky <dbarsky@amazon.com>"]
|
||||
edition = "2018"
|
||||
repository = "https://github.com/tokio-rs/tracing"
|
||||
homepage = "https://tokio.rs"
|
||||
documentation = "https://docs.rs/tracing-slog/0.1.0/tracing_slog"
|
||||
description = """
|
||||
Provides compatibility between `tracing` and `slog` crate
|
||||
"""
|
||||
categories = [
|
||||
"development-tools::debugging",
|
||||
"asynchronous",
|
||||
]
|
||||
keywords = ["logging", "tracing"]
|
||||
license = "MIT"
|
||||
|
||||
[dependencies]
|
||||
tracing = "0.1.3"
|
@ -1,7 +0,0 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
[package]
|
||||
name = "tracing-tower-http"
|
||||
version = "0.1.0"
|
||||
authors = ["Eliza Weisman <eliza@buoyant.io>"]
|
||||
edition = "2018"
|
||||
repository = "https://github.com/tokio-rs/tracing"
|
||||
homepage = "https://tokio.rs"
|
||||
license = "MIT"
|
||||
documentation = "https://docs.rs/tracing-tower-http/0.1.0/tracing_tower_http"
|
||||
description = """
|
||||
`tower` compatibility for HTTP services.
|
||||
"""
|
||||
categories = [
|
||||
"development-tools::debugging",
|
||||
"development-tools::profiling",
|
||||
"asynchronous",
|
||||
]
|
||||
keywords = ["logging", "tracing"]
|
||||
|
||||
[dependencies]
|
||||
tracing = "0.1"
|
||||
tracing-futures = { path = "../tracing-futures" }
|
||||
futures = "0.1"
|
||||
tower-service = "0.2"
|
||||
tower = { git = "https://github.com/tower-rs/tower.git" }
|
||||
http = "0.1"
|
||||
|
||||
[badges]
|
||||
azure-devops = { project = "tracing/tracing", pipeline = "tokio-rs.tracing", build = "1" }
|
||||
maintenance = { status = "experimental" }
|
@ -1,149 +0,0 @@
|
||||
extern crate http;
|
||||
extern crate tower;
|
||||
extern crate tower_service;
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
extern crate futures;
|
||||
extern crate tracing_futures;
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use futures::{Async, Future, Poll};
|
||||
use tower::MakeService;
|
||||
use tower_service::Service;
|
||||
use tracing::{field, Span};
|
||||
use tracing_futures::{Instrument, Instrumented};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct InstrumentedHttpService<T> {
|
||||
inner: T,
|
||||
span: Option<Span>,
|
||||
}
|
||||
|
||||
impl<T> InstrumentedHttpService<T> {
|
||||
pub fn new(inner: T) -> Self {
|
||||
Self { inner, span: None }
|
||||
}
|
||||
|
||||
pub fn with_span(inner: T, span: impl Into<Option<Span>>) -> Self {
|
||||
Self {
|
||||
inner,
|
||||
span: span.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct InstrumentedMakeService<T, B> {
|
||||
inner: T,
|
||||
span: Option<Span>,
|
||||
_p: PhantomData<fn() -> B>,
|
||||
}
|
||||
|
||||
impl<T, B> InstrumentedMakeService<T, B> {
|
||||
pub fn new<Target>(inner: T) -> Self
|
||||
where
|
||||
T: MakeService<Target, http::Request<B>>,
|
||||
{
|
||||
Self {
|
||||
inner,
|
||||
span: None,
|
||||
_p: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_span<Target>(inner: T, span: impl Into<Option<Span>>) -> Self
|
||||
where
|
||||
T: MakeService<Target, http::Request<B>>,
|
||||
{
|
||||
Self {
|
||||
inner,
|
||||
span: span.into(),
|
||||
_p: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, Target, B> Service<Target> for InstrumentedMakeService<T, B>
|
||||
where
|
||||
T: MakeService<Target, http::Request<B>>,
|
||||
{
|
||||
type Response = InstrumentedHttpService<T::Service>;
|
||||
type Error = T::MakeError;
|
||||
type Future = InstrumentedMakeServiceFuture<T::Future>;
|
||||
|
||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||
if let Some(span) = self.span.as_ref() {
|
||||
let _enter = span.enter();
|
||||
self.inner.poll_ready()
|
||||
} else {
|
||||
self.inner.poll_ready()
|
||||
}
|
||||
}
|
||||
|
||||
fn call(&mut self, req: Target) -> Self::Future {
|
||||
let span = self.span.clone();
|
||||
let inner = self.inner.make_service(req);
|
||||
InstrumentedMakeServiceFuture { inner, span }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InstrumentedMakeServiceFuture<T> {
|
||||
inner: T,
|
||||
span: Option<Span>,
|
||||
}
|
||||
|
||||
impl<T> Future for InstrumentedMakeServiceFuture<T>
|
||||
where
|
||||
T: Future,
|
||||
{
|
||||
type Item = InstrumentedHttpService<T::Item>;
|
||||
type Error = T::Error;
|
||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||
match self.inner.poll()? {
|
||||
Async::Ready(svc) => {
|
||||
let svc = InstrumentedHttpService::with_span(
|
||||
svc,
|
||||
self.span
|
||||
.take()
|
||||
.expect("Future was polled after Ready was returned."),
|
||||
);
|
||||
Ok(Async::Ready(svc))
|
||||
}
|
||||
Async::NotReady => Ok(Async::NotReady),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, B> Service<http::Request<B>> for InstrumentedHttpService<T>
|
||||
where
|
||||
T: Service<http::Request<B>>,
|
||||
{
|
||||
type Response = T::Response;
|
||||
type Future = Instrumented<T::Future>;
|
||||
type Error = T::Error;
|
||||
|
||||
fn poll_ready(&mut self) -> futures::Poll<(), Self::Error> {
|
||||
if let Some(span) = self.span.as_ref() {
|
||||
let _enter = span.enter();
|
||||
self.inner.poll_ready()
|
||||
} else {
|
||||
self.inner.poll_ready()
|
||||
}
|
||||
}
|
||||
|
||||
fn call(&mut self, request: http::Request<B>) -> Self::Future {
|
||||
let span = trace_span!(
|
||||
parent: self.span.as_ref().and_then(Into::into),
|
||||
"request",
|
||||
// TODO: custom `Value` impls for `http` types would be nicer
|
||||
// than just sticking these in `debug`s...
|
||||
method = &field::debug(request.method()),
|
||||
version = &field::debug(request.version()),
|
||||
uri = &field::debug(request.uri()),
|
||||
headers = &field::debug(request.headers())
|
||||
);
|
||||
let _enter = span.enter();
|
||||
self.inner.call(request).instrument(span.clone())
|
||||
}
|
||||
}
|
@ -262,10 +262,11 @@ In particular, the following crates are likely to be of interest:
|
||||
|
||||
- [`tracing-futures`] provides a compatibility layer with the `futures`
|
||||
crate, allowing spans to be attached to `Future`s, `Stream`s, and `Executor`s.
|
||||
- [`tracing-fmt`] provides a `Subscriber` implementation for
|
||||
logging formatted trace data to stdout, with similar filtering and
|
||||
formatting to the `env-logger` crate.
|
||||
- [`tracing-log`] provides a compatibility layer with the `log` crate,
|
||||
- [`tracing-subscriber`] provides `Subscriber` implementations and
|
||||
utilities for working with `Subscriber`s. This includes a [`FmtSubscriber`]
|
||||
`FmtSubscriber` for logging formatted trace data to stdout, with similar
|
||||
filtering and formatting to the [`env_logger`] crate.
|
||||
- [`tracing-log`] provides a compatibility layer with the [`log`] crate,
|
||||
allowing log messages to be recorded as `tracing` `Event`s within the
|
||||
trace tree. This is useful when a project using `tracing` have
|
||||
dependencies which use `log`.
|
||||
@ -281,9 +282,11 @@ undergoing active development. They may be less stable than `tracing` and
|
||||
[`log`]: https://docs.rs/log/0.4.6/log/
|
||||
[`tokio-rs/tracing`]: https://github.com/tokio-rs/tracing
|
||||
[`tracing-futures`]: https://github.com/tokio-rs/tracing/tree/master/tracing-futures
|
||||
[`tracing-fmt`]: https://github.com/tokio-rs/tracing/tree/master/tracing-fmt
|
||||
[`tracing-subscriber`]: https://github.com/tokio-rs/tracing/tree/master/tracing-subscriber
|
||||
[`tracing-log`]: https://github.com/tokio-rs/tracing/tree/master/tracing-log
|
||||
[`tracing-timing`]: https://crates.io/crates/tracing-timing
|
||||
[`env_logger`]: https://crates.io/crates/env_logger
|
||||
[`FmtSubscriber`]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/struct.Subscriber.html
|
||||
|
||||
## License
|
||||
|
||||
|
@ -556,8 +556,10 @@
|
||||
//! - [`tracing-futures`] provides a compatibility layer with the `futures`
|
||||
//! crate, allowing spans to be attached to `Future`s, `Stream`s, and `Executor`s.
|
||||
//! - [`tracing-subscriber`] provides `Subscriber` implementations and
|
||||
//! utilities for working with `Subscriber`s.
|
||||
//! - [`tracing-log`] provides a compatibility layer with the `log` crate,
|
||||
//! utilities for working with `Subscriber`s. This includes a [`FmtSubscriber`]
|
||||
//! `FmtSubscriber` for logging formatted trace data to stdout, with similar
|
||||
//! filtering and formatting to the [`env_logger`] crate.
|
||||
//! - [`tracing-log`] provides a compatibility layer with the [`log`] crate,
|
||||
//! allowing log messages to be recorded as `tracing` `Event`s within the
|
||||
//! trace tree. This is useful when a project using `tracing` have
|
||||
//! dependencies which use `log`.
|
||||
@ -609,6 +611,8 @@
|
||||
//! [`tracing-subscriber`]: https://crates.io/crates/tracing-subscriber
|
||||
//! [`tracing-log`]: https://crates.io/crates/tracing-log
|
||||
//! [`tracing-timing`]: https://crates.io/crates/tracing-timing
|
||||
//! [`env_logger`]: https://crates.io/crates/env_logger
|
||||
//! [`FmtSubscriber`]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/struct.Subscriber.html
|
||||
//! [static verbosity level]: level_filters/index.html#compile-time-filters
|
||||
//! [instrument]: https://docs.rs/tracing-attributes/latest/tracing_attributes/attr.instrument.html
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user