Skip to content

Adopt Tracing #1410

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

Closed
wants to merge 63 commits into from
Closed
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
f5a8681
WIP
hawkw Jul 21, 2020
debb008
filtering, nicer formatting
hawkw Jul 21, 2020
e0a0bfd
more trace
hawkw Jul 21, 2020
6e0e902
fix filtering
hawkw Jul 21, 2020
47540a9
mounting works
hawkw Jul 21, 2020
88cee8c
WIP
hawkw Jul 22, 2020
d920738
skip span names for "rocket-ier" formatitng
hawkw Jul 22, 2020
bce8f14
this is cute, right?
hawkw Jul 22, 2020
e3398e5
fix contrib
hawkw Jul 23, 2020
86c5ef5
use span names if there's no message
hawkw Jul 23, 2020
88feb8e
start removing underscore macros
hawkw Jul 23, 2020
cbe5581
less obnoxious bold, nicer debug/trace
hawkw Jul 23, 2020
43c95db
don't constantly screw up colors
hawkw Jul 23, 2020
1eec8f6
unpatch
hawkw Jul 25, 2020
2589dee
add docs & reexports
hawkw Aug 11, 2020
533d792
cleanup, remove logger module
hawkw Aug 11, 2020
e7b55d7
whoops
hawkw Aug 11, 2020
2dbd927
Merge branch 'master' into eliza/trace
hawkw Aug 11, 2020
4bd3da2
trailing whitespace
hawkw Aug 13, 2020
9905887
trailing whitespace again
hawkw Aug 13, 2020
118e13e
fixup
hawkw Aug 13, 2020
03533ce
use `macro_use` imports everywhere
hawkw Aug 13, 2020
9e6adc6
use spans for all indentation-based messages
hawkw Aug 13, 2020
ec5066b
update codegen
hawkw Aug 13, 2020
6144caa
add spans to generated catcher/route fns
hawkw Aug 13, 2020
e1b67db
make catcher spans info
hawkw Aug 13, 2020
cd124d8
bold span names when no message is present
hawkw Aug 13, 2020
bc492ba
add more info to generated spans
hawkw Aug 14, 2020
88e965e
Replace `log` with `tracing` and `tracing-subscriber`.
hawkw Oct 31, 2020
6fbbf94
style: remove most usage of span.enter()
jebrosen Nov 1, 2020
c8e4b6b
fix: macros are weird sometimes
jebrosen Nov 1, 2020
eeeab88
fix: use of moved value
jebrosen Nov 1, 2020
41237b6
Merge remote-tracking branch 'jebrosen/adopt-tracing' into eliza/trace
hawkw Nov 2, 2020
9f86214
allow libtest to capture trace logs
hawkw Nov 2, 2020
9e95437
remove workaround
hawkw Nov 2, 2020
9776ca3
remove workarounds, add `log` compat
hawkw Nov 3, 2020
fa5f30d
examples for a custom subscriber, env_logger
hawkw Nov 3, 2020
73ca07c
Merge branch 'master' into eliza/trace
hawkw Nov 4, 2020
e68d66d
use structured fields in more places
hawkw Nov 4, 2020
4e9a308
post-rebase fixup
hawkw Nov 4, 2020
a868cab
use `in_scope` for errors
hawkw Nov 4, 2020
cb1b024
allow adding directives to Rocket's filter
hawkw Nov 4, 2020
6de1180
make examples a little fancier
hawkw Nov 4, 2020
4ddaedf
fix trace in contrib
hawkw Nov 4, 2020
0025a58
propagate spans to spawned threads
hawkw Nov 4, 2020
f15d432
put all request processing inside request span
hawkw Nov 4, 2020
dd77f67
add another span in 'Fairings::pretty_print_counts'
jebrosen Nov 4, 2020
d5006de
feat: use rocket::trace::info in fairings, manual_routes examples
jebrosen Nov 4, 2020
4bf5f33
remove trailing whitespace
jebrosen Nov 5, 2020
50a224d
fix(codegen): log parameter names in a way that will work for any kin…
jebrosen Nov 12, 2020
55faca7
fix compile error in manual_routes example
jebrosen Nov 12, 2020
732a613
fix(test): missing semicolon
jebrosen Nov 12, 2020
8dba51d
feat: rework log output formatting
jebrosen Nov 13, 2020
39ae1d5
feat: print request IDs
jebrosen Nov 13, 2020
910ad1c
feat/experiment: remove connection span, making 'request' the top-lev…
jebrosen Nov 13, 2020
63e0ef3
handle `log` metadata properly
hawkw Nov 16, 2020
8ac9625
use tracing instead of log in http
jebrosen Nov 15, 2020
2f098a7
call Paint::disable in more cases of 'tracing' initialization failure
jebrosen Nov 17, 2020
2cfad83
add new log level 'support'
jebrosen Nov 18, 2020
d69340c
fixup: add string form to description of 'support' to make consistent…
jebrosen Nov 19, 2020
0d506c1
Use 'in_scope' instead of 'enter' in most places.
jebrosen Nov 19, 2020
c19799b
fix: under feature="log", skip formatting of fields whose names start…
jebrosen Nov 21, 2020
85f2e5b
fix: test the 'log' feature individually
jebrosen Nov 21, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ members = [
"examples/tls",
"examples/fairings",
"examples/hello_2018",
]
]
8 changes: 4 additions & 4 deletions contrib/codegen/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ pub fn database_attr(attr: TokenStream, input: TokenStream) -> Result<TokenStrea
match pool {
Ok(Ok(p)) => Ok(rocket.manage(#pool_type(p))),
Err(config_error) => {
::rocket::logger::error(
::rocket::trace::error(
&format!("Database configuration failure: '{}'", #name));
::rocket::logger::error_(&format!("{}", config_error));
::rocket::trace::error_(&format!("{}", config_error));
Err(rocket)
},
Ok(Err(pool_error)) => {
::rocket::logger::error(
::rocket::trace::error(
&format!("Failed to initialize pool for '{}'", #name));
::rocket::logger::error_(&format!("{:?}", pool_error));
::rocket::trace::error_(&format!("{:?}", pool_error));
Err(rocket)
},
}
Expand Down
2 changes: 1 addition & 1 deletion contrib/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ memcache_pool = ["databases", "memcache", "r2d2-memcache"]
tokio = { version = "0.2.0", optional = true }
rocket_contrib_codegen = { version = "0.5.0-dev", path = "../codegen", optional = true }
rocket = { version = "0.5.0-dev", path = "../../core/lib/", default-features = false }
log = "0.4"
tracing = { version = "0.1", default-features = false }

# Serialization and templating dependencies.
serde = { version = "1.0", optional = true }
Expand Down
8 changes: 4 additions & 4 deletions contrib/lib/src/compression/fairing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,17 @@ impl Fairing for Compression {
if let Value::String(s) = ex {
let mt = MediaType::parse_flexible(s);
if mt.is_none() {
warn_!("Ignoring invalid media type '{:?}'", s);
warn!("Ignoring invalid media type '{:?}'", s);
}
mt
} else {
warn_!("Ignoring non-string media type '{:?}'", ex);
warn!("Ignoring non-string media type '{:?}'", ex);
None
}
}).collect();
}
None => {
warn_!(
warn!(
"Exclusions is not an array; using default compression exclusions '{:?}'",
ctxt.exclusions
);
Expand All @@ -134,7 +134,7 @@ impl Fairing for Compression {
Err(ConfigError::Missing(_)) => { /* ignore missing */ }
Err(e) => {
e.pretty_print();
warn_!(
warn!(
"Using default compression exclusions '{:?}'",
ctxt.exclusions
);
Expand Down
8 changes: 4 additions & 4 deletions contrib/lib/src/helmet/helmet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl SpaceHelmet {
let name = policy.name();
if response.headers().contains(name.as_str()) {
warn!("Space Helmet: response contains a '{}' header.", name);
warn_!("Refusing to overwrite existing header.");
warn!("Refusing to overwrite existing header.");
continue
}

Expand Down Expand Up @@ -206,9 +206,9 @@ impl Fairing for SpaceHelmet {
&& !cargo.config().environment.is_dev()
&& !self.is_enabled::<Hsts>()
{
warn_!("Space Helmet: deploying with TLS without enabling HSTS.");
warn_!("Enabling default HSTS policy.");
info_!("To disable this warning, configure an HSTS policy.");
warn!("Space Helmet: deploying with TLS without enabling HSTS.");
warn!("Enabling default HSTS policy.");
info!("To disable this warning, configure an HSTS policy.");
self.force_hsts.store(true, Ordering::Relaxed);
}
}
Expand Down
4 changes: 2 additions & 2 deletions contrib/lib/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl<'a, T: Deserialize<'a>> FromTransformedData<'a> for Json<T> {
match serde_json::from_str(&string) {
Ok(v) => Success(Json(v)),
Err(e) => {
error_!("Couldn't parse JSON body: {:?}", e);
error!("Couldn't parse JSON body: {:?}", e);
if e.is_data() {
Failure((Status::UnprocessableEntity, JsonError::Parse(string, e)))
} else {
Expand All @@ -166,7 +166,7 @@ impl<'r, T: Serialize> Responder<'r, 'static> for Json<T> {
fn respond_to(self, req: &'r Request<'_>) -> response::Result<'static> {
let string = serde_json::to_string(&self.0)
.map_err(|e| {
error_!("JSON failed to serialize: {:?}", e);
error!("JSON failed to serialize: {:?}", e);
Status::InternalServerError
})?;

Expand Down
2 changes: 1 addition & 1 deletion contrib/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
//! This crate is expected to grow with time, bringing in outside crates to be
//! officially supported by Rocket.

#[allow(unused_imports)] #[macro_use] extern crate log;
#[allow(unused_imports)] #[macro_use] extern crate tracing;
#[allow(unused_imports)] #[macro_use] extern crate rocket;

#[cfg(feature="json")] #[macro_use] pub mod json;
Expand Down
4 changes: 2 additions & 2 deletions contrib/lib/src/msgpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl<'a, T: Deserialize<'a>> FromTransformedData<'a> for MsgPack<T> {
match rmp_serde::from_slice(&buf) {
Ok(val) => Success(MsgPack(val)),
Err(e) => {
error_!("Couldn't parse MessagePack body: {:?}", e);
error!("Couldn't parse MessagePack body: {:?}", e);
match e {
TypeMismatch(_) | OutOfRange | LengthMismatch(_) => {
Failure((Status::UnprocessableEntity, e))
Expand All @@ -158,7 +158,7 @@ impl<'r, T: Serialize> Responder<'r, 'static> for MsgPack<T> {
fn respond_to(self, req: &'r Request<'_>) -> response::Result<'static> {
let buf = rmp_serde::to_vec(&self.0)
.map_err(|e| {
error_!("MsgPack failed to serialize: {:?}", e);
error!("MsgPack failed to serialize: {:?}", e);
Status::InternalServerError
})?;

Expand Down
8 changes: 4 additions & 4 deletions contrib/lib/src/templates/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ impl Context {
for path in glob::glob(glob_path).unwrap().filter_map(Result::ok) {
let (name, data_type_str) = split_path(&root, &path);
if let Some(info) = templates.get(&*name) {
warn_!("Template name '{}' does not have a unique path.", name);
info_!("Existing path: {:?}", info.path);
info_!("Additional path: {:?}", path);
warn_!("Using existing path for template '{}'.", name);
let span = warn_span!("invalid_template_path", "Template name '{}' does not have a unique path.", name);
info!(parent: &span, "Existing path: {:?}", info.path);
info!(parent: &span, "Additional path: {:?}", path);
warn!(parent: &span, "Using existing path for template '{}'.", name);
continue;
}

Expand Down
12 changes: 6 additions & 6 deletions contrib/lib/src/templates/fairing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ mod context {
Ok(watcher) => Some(Mutex::new((watcher, rx))),
Err(e) => {
warn!("Failed to enable live template reloading: {}", e);
debug_!("Reload error: {:?}", e);
warn_!("Live template reloading is unavailable.");
debug!("Reload error: {:?}", e);
warn!("Live template reloading is unavailable.");
None
}
};
Expand Down Expand Up @@ -98,14 +98,14 @@ mod context {
}

if changed {
info_!("Change detected: reloading templates.");
info!("Change detected: reloading templates.");
let mut ctxt = self.context_mut();
if let Some(mut new_ctxt) = Context::initialize(ctxt.root.clone()) {
custom_callback(&mut new_ctxt.engines);
*ctxt = new_ctxt;
} else {
warn_!("An error occurred while reloading templates.");
warn_!("The previous templates will remain active.");
warn!("An error occurred while reloading templates.");
warn!("The previous templates will remain active.");
};
}
});
Expand Down Expand Up @@ -159,7 +159,7 @@ impl Fairing for TemplateFairing {
Err(ConfigError::Missing(_)) => { /* ignore missing */ }
Err(e) => {
e.pretty_print();
warn_!("Using default templates directory '{:?}'", template_root);
warn!("Using default templates directory '{:?}'", template_root);
}
};

Expand Down
8 changes: 4 additions & 4 deletions contrib/lib/src/templates/handlebars_templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ impl Engine for Handlebars<'static> {
let path = &info.path;
if let Err(e) = hb.register_template_file(name, path) {
error!("Error in Handlebars template '{}'.", name);
info_!("{}", e);
info_!("Template path: '{}'.", path.to_string_lossy());
info!("{}", e);
info!("Template path: '{}'.", path.to_string_lossy());
return None;
}
}
Expand All @@ -24,14 +24,14 @@ impl Engine for Handlebars<'static> {

fn render<C: Serialize>(&self, name: &str, context: C) -> Option<String> {
if self.get_template(name).is_none() {
error_!("Handlebars template '{}' does not exist.", name);
error!("Handlebars template '{}' does not exist.", name);
return None;
}

match Handlebars::render(self, name, &context) {
Ok(string) => Some(string),
Err(e) => {
error_!("Error rendering Handlebars template '{}': {}", name, e);
error!("Error rendering Handlebars template '{}': {}", name, e);
None
}
}
Expand Down
6 changes: 3 additions & 3 deletions contrib/lib/src/templates/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ impl<'a, 'r> FromRequest<'a, 'r> for Metadata<'a> {
.succeeded()
.and_then(|cm| Some(request::Outcome::Success(Metadata(cm.inner()))))
.unwrap_or_else(|| {
error_!("Uninitialized template context: missing fairing.");
info_!("To use templates, you must attach `Template::fairing()`.");
info_!("See the `Template` documentation for more information.");
error!("Uninitialized template context: missing fairing.");
info!("To use templates, you must attach `Template::fairing()`.");
info!("See the `Template` documentation for more information.");
request::Outcome::Failure((Status::InternalServerError, ()))
})
}
Expand Down
16 changes: 8 additions & 8 deletions contrib/lib/src/templates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,19 +362,19 @@ impl Template {
let name = &*self.name;
let info = ctxt.templates.get(name).ok_or_else(|| {
let ts: Vec<_> = ctxt.templates.keys().map(|s| s.as_str()).collect();
error_!("Template '{}' does not exist.", name);
info_!("Known templates: {}", ts.join(","));
info_!("Searched in '{:?}'.", ctxt.root);
error!("Template '{}' does not exist.", name);
info!("Known templates: {}", ts.join(","));
info!("Searched in '{:?}'.", ctxt.root);
Status::InternalServerError
})?;

let value = self.value.ok_or_else(|| {
error_!("The provided template context failed to serialize.");
error!("The provided template context failed to serialize.");
Status::InternalServerError
})?;

let string = ctxt.engines.render(name, &info, value).ok_or_else(|| {
error_!("Template '{}' failed to render.", name);
error!("Template '{}' failed to render.", name);
Status::InternalServerError
})?;

Expand All @@ -389,9 +389,9 @@ impl<'r> Responder<'r, 'static> for Template {
fn respond_to(self, req: &'r Request<'_>) -> response::Result<'static> {
let (render, content_type) = {
let ctxt = req.managed_state::<ContextManager>().ok_or_else(|| {
error_!("Uninitialized template context: missing fairing.");
info_!("To use templates, you must attach `Template::fairing()`.");
info_!("See the `Template` documentation for more information.");
error!("Uninitialized template context: missing fairing.");
info!("To use templates, you must attach `Template::fairing()`.");
info!("See the `Template` documentation for more information.");
Status::InternalServerError
})?.context();

Expand Down
10 changes: 5 additions & 5 deletions contrib/lib/src/templates/tera_templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Engine for Tera {

let mut error = Some(&e as &dyn Error);
while let Some(err) = error {
info_!("{}", err);
info!("{}", err);
error = err.source();
}

Expand All @@ -37,14 +37,14 @@ impl Engine for Tera {

fn render<C: Serialize>(&self, name: &str, context: C) -> Option<String> {
if self.get_template(name).is_err() {
error_!("Tera template '{}' does not exist.", name);
error!("Tera template '{}' does not exist.", name);
return None;
};

let tera_ctx = match Context::from_serialize(context) {
Ok(ctx) => ctx,
Err(_) => {
error_!(
error!(
"Error generating context when rendering Tera template '{}'.",
name
);
Expand All @@ -55,11 +55,11 @@ impl Engine for Tera {
match Tera::render(self, name, &tera_ctx) {
Ok(string) => Some(string),
Err(e) => {
error_!("Error rendering Tera template '{}'.", name);
error!("Error rendering Tera template '{}'.", name);

let mut error = Some(&e as &dyn Error);
while let Some(err) = error {
error_!("{}", err);
error!("{}", err);
error = err.source();
}

Expand Down
11 changes: 11 additions & 0 deletions core/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ atty = "0.2"
async-trait = "0.1"
ref-cast = "1.0"
atomic = "0.4"
tracing = "0.1.19"
ubyte = "0.9.1"

[dependencies.pear]
Expand All @@ -49,6 +50,16 @@ rev = "4b68055"
version = "0.2.9"
features = ["fs", "io-std", "io-util", "rt-threaded", "sync", "signal", "macros"]

[dependencies.tracing-subscriber]
version = "0.2.9"
default-features = false
features = ["fmt", "env-filter", "smallvec"]

[dependencies.tracing-futures]
version = "0.2"
default-features = false
features = ["std-future"]

[build-dependencies]
yansi = "0.5"
version_check = "0.9.1"
Expand Down
22 changes: 11 additions & 11 deletions core/lib/src/config/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,46 +64,46 @@ impl ConfigError {
RandFailure => error!("failed to read randomness from the OS"),
Io(ref error, param) => {
error!("I/O error while setting {}:", Paint::default(param).bold());
info_!("{}", error);
info!("{}", error);
}
BadFilePath(ref path, reason) => {
error!("configuration file path {} is invalid",
Paint::default(path.display()).bold());
info_!("{}", reason);
info!("{}", reason);
}
BadEntry(ref name, ref filename) => {
let valid_entries = format!("{}, global", valid_envs);
error!("{} is not a known configuration environment",
Paint::default(format!("[{}]", name)).bold());
info_!("in {}", Paint::default(filename.display()).bold());
info_!("valid environments are: {}", Paint::default(valid_entries).bold());
info!("in {}", Paint::default(filename.display()).bold());
info!("valid environments are: {}", Paint::default(&valid_entries).bold());
}
BadEnv(ref name) => {
error!("{} is not a valid ROCKET_ENV value", Paint::default(name).bold());
info_!("valid environments are: {}", Paint::default(valid_envs).bold());
info!("valid environments are: {}", Paint::default(valid_envs).bold());
}
BadType(ref name, expected, actual, ref filename) => {
error!("{} key could not be parsed", Paint::default(name).bold());
if let Some(filename) = filename {
info_!("in {}", Paint::default(filename.display()).bold());
info!("in {}", Paint::default(filename.display()).bold());
}

info_!("expected value to be {}, but found {}",
info!("expected value to be {}, but found {}",
Paint::default(expected).bold(), Paint::default(actual).bold());
}
ParseError(_, ref filename, ref desc, line_col) => {
error!("config file failed to parse due to invalid TOML");
info_!("{}", desc);
info_!("in {}", Paint::default(filename.display()).bold());
info!("{}", desc);
info!("in {}", Paint::default(filename.display()).bold());
if let Some((line, col)) = line_col {
info_!("at line {}, column {}",
info!("at line {}, column {}",
Paint::default(line + 1).bold(), Paint::default(col + 1).bold());
}
}
BadEnvVal(ref key, ref value, ref error) => {
error!("environment variable {} could not be parsed",
Paint::default(format!("ROCKET_{}={}", key.to_uppercase(), value)).bold());
info_!("{}", error);
info!("{}", error);
}
UnknownKey(ref key) => {
error!("the configuration key {} is unknown and disallowed in \
Expand Down
Loading