Skip to content

Conversation

lcian
Copy link
Member

@lcian lcian commented Oct 7, 2025

Description

  • Instead of using a hidden indicatif progress bar when SENTRY_NO_PROGRESS_BAR, use no progress bar instead, and just forward messages on it to log::debug/info.
  • Also, use std::io::stderr().is_terminal() to determine whether or not to use a progress bar when SENTRY_NO_PROGRESS_BAR is not specified.
  • This prevents the progress bar from "swallowing" messages that are set on it AND also those logged using log, as our log utility ultimately forwards to the progress bar when one is active.

Issues

Close #2829
Close CLI-180
Close #2790
Close CLI-171

Testing

  1. sentry-cli debug-files bundle-jvm --log-level=debug

stdout and stderr before and after the change:
stdout_before.txt
stdout_after.txt
stderr_before.txt
stderr_after.txt

The stdout remains the same.
The stderr changes, now we see more output, such as the file being currently processed (DEBUG level), and other messages at INFO level, such as Skipping ./File.java because it is not valid UTF-8 which is what motivated this PR in the first place.

  1. sentry-cli sourcemaps upload --log-level=debug

stdout and stderr before and after the change:
stdout_before.txt
stdout_after.txt
stderr_before.txt
stderr_after.txt

The stdout remains the same as well.
The stderr now shows 2 POST calls to /artifactbundle/assemble, in contrast with the single POST call to that endpoint that we would see without the change.

Copy link

linear bot commented Oct 7, 2025

pub fn is_progress_bar_visible() -> bool {
env::var("SENTRY_NO_PROGRESS_BAR") != Ok("1".into())
pub fn use_progress_bar() -> bool {
(env::var("SENTRY_NO_PROGRESS_BAR") != Ok("1".into())) || std::io::stdout().is_terminal()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should verify whether stdout or stderr is used for the progress bar

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It uses stderr, changed it.

@lcian
Copy link
Member Author

lcian commented Oct 10, 2025

Without this PR we're indeed missing not only the messages emitted on the progress bar itself (with pb.set_message) but also those emitted with log:: macros. This is because here we use the progress bar to print those messages too, if one is active:
see https://github.com/getsentry/sentry-cli/blob/master/src/utils/logging.rs#L92
So this will solve that problem too


let mut found_files = vec![];
let pb = ProgressBar::new_spinner();
let mut pb = ProgressBar::new_spinner();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to become mut to handle set_prefix

Copy link

linear bot commented Oct 10, 2025

@lcian lcian marked this pull request as ready for review October 10, 2025 14:51
@lcian lcian requested a review from a team as a code owner October 10, 2025 14:51
Copy link
Member

@szokeasaurusrex szokeasaurusrex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing find, thanks so much for the PR!

I added some minor suggestions for the implementation; overall, this is an excellent improvement though!

Side note: it is interesting that we do two assemble endpoints for the sourcemap upload in the "after" logs, as the first assemble request already shows all the chunks are uploaded, the second call is redundant. But, I suppose this is an edge case, so it is fine, but it is interesting behavior that we would not have observed without your change

if env::var("SENTRY_NO_PROGRESS_BAR") == Ok("1".into()) {
return false;
}
std::io::stderr().is_terminal()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the PR description to also use stderr

inner.finish_with_message(&msg);
logging::set_progress_bar(None);
} else {
log::info!("> {msg}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log::info! by default would be hidden (as log level is by default at WARN). I think eprintln! is therefore more suitable here, assuming these final messages typically show in the stderr when running in terminal

Suggested change
log::info!("> {msg}");
eprintln!("> {msg}");

Comment on lines +97 to 106
} else {
log::debug!(
"{}{}",
self.prefix
.as_deref()
.map(|s| format!("{s} "))
.unwrap_or_default(),
msg.as_ref()
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: As this output would not remain visible for long in the terminal, I don't think it makes much sense to print it at all when we don't use a progress bar. Logs at debug level are not visible by default anyways. Unless we find a case where this could be useful, I would omit it.

Suggested change
} else {
log::debug!(
"{}{}",
self.prefix
.as_deref()
.map(|s| format!("{s} "))
.unwrap_or_default(),
msg.as_ref()
);
}
}

Comment on lines +118 to +120
} else {
self.prefix = Some(prefix.as_ref().to_owned());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going along with my previous suggestion, getting rid of logging in the no progress bar case lets us simplify here. We can probably even remove the prefix field from the struct.

Suggested change
} else {
self.prefix = Some(prefix.as_ref().to_owned());
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid swallowing of messages when using progress bar and not running in terminal Logs are missing from sourcemaps upload

2 participants