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

Move tracing init into its own file #1381

Merged
merged 2 commits into from
Feb 28, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ reqwest = { git = "https://github.com/getsentry/reqwest", branch = "restricted-c
# This patch adds limited "templated lambdas" demangling support
cpp_demangle = { git = "https://github.com/getsentry/cpp_demangle", branch = "sentry-patches" }


# For local development: uncomment the following three lines (and adjust the path if necessary)
# to use a local symbolic checkout everywhere.
# This only works for the very specific crate listed here, and not for its dependency tree.
Expand Down
1 change: 1 addition & 0 deletions crates/symbolicator-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ thiserror = "1.0.31"
tokio = { version = "1.24.2", features = ["rt", "macros", "fs"] }
tokio-util = { version = "0.7.1", features = ["io"] }
tracing = "0.1.34"
tracing-subscriber = { version = "0.3.17", features = ["env-filter", "time", "json"] }
url = { version = "2.2.0", features = ["serde"] }
uuid = { version = "1.0.0", features = ["v4", "serde"] }
zip = { version = "0.6.4", default-features = false, features = ["deflate"] }
Expand Down
1 change: 1 addition & 0 deletions crates/symbolicator-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod caches;
pub mod caching;
pub mod config;
pub mod download;
pub mod logging;
pub mod objects;
pub mod services;
pub mod source_context;
Expand Down
24 changes: 24 additions & 0 deletions crates/symbolicator-service/src/logging.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use tracing_subscriber::fmt::time::UtcTime;
use tracing_subscriber::fmt::{fmt, MakeWriter};
use tracing_subscriber::prelude::*;
use tracing_subscriber::util::SubscriberInitExt;

pub fn init_json_logging<W>(env_filter: &str, make_writer: W)
where
W: for<'writer> MakeWriter<'writer> + Send + Sync + 'static,
{
fmt()
.with_timer(UtcTime::rfc_3339())
.with_target(true)
.with_env_filter(env_filter)
.json()
.flatten_event(true)
.with_current_span(true)
.with_span_list(true)
.with_file(true)
.with_line_number(true)
.with_writer(make_writer)
.finish()
.with(sentry::integrations::tracing::layer())
.init();
}
1 change: 0 additions & 1 deletion crates/symbolicator-stress/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ symbolicator-service = { path = "../symbolicator-service" }
symbolicator-test = { path = "../symbolicator-test" }
tempfile = "3.2.0"
tokio = { version = "1.24.2", features = ["rt-multi-thread", "macros", "time", "sync"] }
tracing-subscriber = "0.3.17"

[target.'cfg(not(target_env = "msvc"))'.dependencies]
jemallocator = { version = "0.5", features = ["unprefixed_malloc_on_supported_platforms"] }
47 changes: 7 additions & 40 deletions crates/symbolicator-stress/src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
use std::collections::BTreeMap;
use std::env;
use std::future::Future;
use std::io::Write;
use std::net::{SocketAddr, TcpListener, UdpSocket};
use std::pin::Pin;

use symbolicator_service::metrics;
use tracing_subscriber::fmt::fmt;
use tracing_subscriber::fmt::time::UtcTime;
use tracing_subscriber::prelude::*;
use symbolicator_service::{logging, metrics};

#[derive(Debug, Default)]
pub struct Config {
Expand Down Expand Up @@ -61,27 +57,12 @@ pub fn init(config: Config) -> Guard {
}

if config.tracing {
let rust_log = "INFO";
let subscriber = fmt()
.with_timer(UtcTime::rfc_3339())
.with_target(true)
.with_env_filter(rust_log);

// we want all the tracing machinery to be active, but not spam the console,
// so redirect everything into the void:
let subscriber = subscriber.with_writer(|| NoopWriter);

// this should mimic the settings used in production:
subscriber
.json()
.flatten_event(true)
.with_current_span(true)
.with_span_list(true)
.with_file(true)
.with_line_number(true)
.finish()
.with(sentry::integrations::tracing::layer())
.init();
let env_filter = "INFO,\
minidump=ERROR,\
trust_dns_proto=WARN";
// we want all the tracing machinery to be active and use the production JSON output,
// but not spam the console, so redirect everything into the void (`std::io::sink`):
logging::init_json_logging(env_filter, std::io::sink);
}

if config.metrics {
Expand Down Expand Up @@ -111,17 +92,3 @@ pub fn init(config: Config) -> Guard {

guard
}

struct NoopWriter;
impl Write for NoopWriter {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
// try to prevent the compiler from optimizing away all the formatting code:
let buf = std::hint::black_box(buf);

Ok(buf.len())
}

fn flush(&mut self) -> std::io::Result<()> {
Ok(())
}
}
2 changes: 1 addition & 1 deletion crates/symbolicator-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ symbolicator-sources = { path = "../symbolicator-sources" }
tempfile = "3.2.0"
tokio = { version = "1.26.0", features = ["rt", "macros", "fs"] }
tower-http = { version = "0.5.0", features = ["fs", "trace"] }
tracing-subscriber = { version = "0.3.17", features = ["tracing-log", "local-time", "env-filter", "json"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
2 changes: 1 addition & 1 deletion crates/symbolicator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tower = "0.4"
tower-layer = "0.3"
tower-service = "0.3"
tracing = "0.1.34"
tracing-subscriber = { version = "0.3.17", features = ["tracing-log", "local-time", "env-filter", "json"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter", "time"] }
url = { version = "2.2.0", features = ["serde"] }
uuid = { version = "1.0.0", features = ["v4", "serde"] }

Expand Down
14 changes: 3 additions & 11 deletions crates/symbolicator/src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env;

use symbolicator_service::logging::init_json_logging;
use tracing::level_filters::LevelFilter;
use tracing_subscriber::fmt::fmt;
use tracing_subscriber::fmt::time::UtcTime;
Expand Down Expand Up @@ -52,7 +53,7 @@ pub fn init_logging(config: &Config) {
let subscriber = fmt()
.with_timer(UtcTime::rfc_3339())
.with_target(true)
.with_env_filter(rust_log);
.with_env_filter(&rust_log);

match (config.logging.format, console::user_attended()) {
(LogFormat::Auto, true) | (LogFormat::Pretty, _) => subscriber
Expand All @@ -66,16 +67,7 @@ pub fn init_logging(config: &Config) {
.finish()
.with(sentry::integrations::tracing::layer())
.init(),
(LogFormat::Json, _) => subscriber
.json()
.flatten_event(true)
.with_current_span(true)
.with_span_list(true)
.with_file(true)
.with_line_number(true)
.finish()
.with(sentry::integrations::tracing::layer())
.init(),
(LogFormat::Json, _) => init_json_logging(&rust_log, std::io::stdout),
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/symbolicli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ tempfile = "3.3.0"
tokio = { version = "1.24.2", features = ["rt-multi-thread", "macros", "time", "sync"] }
toml = "0.8.0"
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["tracing-log", "local-time", "env-filter", "json"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
url = "2.3.1"
Loading