Skip to content

Commit 387f06c

Browse files
authored
tracing: Disable colored log output on Heroku (#7505)
Having ANSI escape sequences sprinkled across the log lines helps the readability on Papertrail, but Datadog does not support them and displays them as their regular characters which makes the logs hard to read and parse. This commit disables the color support when run on Heroku to address that issue. This might also cause a small decrease in our log volume due to the escape characters no longer counting against it.
1 parent ef0218a commit 387f06c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/util/tracing.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crates_io_env_vars::var;
12
use sentry::integrations::tracing::EventFilter;
23
use tracing::Level;
34
use tracing::Metadata;
@@ -17,12 +18,15 @@ pub fn init() {
1718
}
1819

1920
fn init_with_default_level(level: LevelFilter) {
21+
let is_heroku = matches!(var("HEROKU"), Ok(Some(_)));
22+
2023
let env_filter = EnvFilter::builder()
2124
.with_default_directive(level.into())
2225
.from_env_lossy();
2326

2427
let log_layer = tracing_subscriber::fmt::layer()
2528
.compact()
29+
.with_ansi(!is_heroku)
2630
.without_time()
2731
.with_filter(env_filter);
2832

0 commit comments

Comments
 (0)