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

chore(tui): redirect tracing output to files during tui usage #9003

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ triomphe = "0.1.13"
tui-term = { version = "0.1.9", default-features = false }
url = "2.2.2"
urlencoding = "2.1.2"
uuid = "1.5.0"
webbrowser = "0.8.7"
which = "4.4.0"
unicode-segmentation = "1.10.1"
Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ turborepo-unescape = { workspace = true }
turborepo-vercel-api = { path = "../turborepo-vercel-api" }
twox-hash = "1.6.3"
uds_windows = "1.0.2"
uuid = { workspace = true }
wax = { workspace = true }
webbrowser = { workspace = true }
which = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/turborepo-lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ pub async fn run(
}

run_args.track(&event);
let exit_code = run::run(base, event).await.inspect(|code| {
let exit_code = run::run(base, event, logger).await.inspect(|code| {
if *code != 0 {
error!("run failed: command exited ({code})");
}
Expand All @@ -1282,7 +1282,7 @@ pub async fn run(
event.track_call();
let base = CommandBase::new(cli_args, repo_root, version, color_config);

let mut client = WatchClient::new(base, event).await?;
let mut client = WatchClient::new(base, event, logger).await?;
client.start().await?;
// We only exit if we get a signal, so we return a non-zero exit code
return Ok(1);
Expand Down
15 changes: 12 additions & 3 deletions crates/turborepo-lib/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ use std::future::Future;
use tracing::error;
use turborepo_telemetry::events::command::CommandEventBuilder;

use crate::{commands::CommandBase, run, run::builder::RunBuilder, signal::SignalHandler};
use crate::{
commands::CommandBase,
run::{self, builder::RunBuilder},
signal::SignalHandler,
tracing::TurboSubscriber,
};

#[cfg(windows)]
pub fn get_signal() -> Result<impl Future<Output = Option<()>>, run::Error> {
Expand Down Expand Up @@ -31,7 +36,11 @@ pub fn get_signal() -> Result<impl Future<Output = Option<()>>, run::Error> {
})
}

pub async fn run(base: CommandBase, telemetry: CommandEventBuilder) -> Result<i32, run::Error> {
pub async fn run(
base: CommandBase,
telemetry: CommandEventBuilder,
logger: &TurboSubscriber,
) -> Result<i32, run::Error> {
let signal = get_signal()?;
let handler = SignalHandler::new(signal);

Expand All @@ -44,7 +53,7 @@ pub async fn run(base: CommandBase, telemetry: CommandEventBuilder) -> Result<i3
.build(&handler, telemetry)
.await?;

let (sender, handle) = run.start_experimental_ui()?.unzip();
let (sender, handle) = run.start_experimental_ui(logger)?.unzip();
let result = run.run(sender.clone(), false).await;

if let Some(analytics_handle) = analytics_handle {
Expand Down
9 changes: 8 additions & 1 deletion crates/turborepo-lib/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub use cache::{CacheOutput, ConfigCache, Error as CacheError, RunCache, TaskCac
use chrono::{DateTime, Local};
use rayon::iter::ParallelBridge;
use tokio::{select, task::JoinHandle};
use tracing::debug;
use tracing::{debug, warn};
use turbopath::AbsoluteSystemPathBuf;
use turborepo_api_client::{APIAuth, APIClient};
use turborepo_ci::Vendor;
Expand All @@ -43,6 +43,7 @@ use crate::{
signal::SignalHandler,
task_graph::Visitor,
task_hash::{get_external_deps_hash, get_internal_deps_hash, PackageInputsHashes},
tracing::TurboSubscriber,
turbo_json::{TurboJson, UIMode},
DaemonClient, DaemonConnector,
};
Expand Down Expand Up @@ -190,6 +191,7 @@ impl Run {
#[allow(clippy::type_complexity)]
pub fn start_experimental_ui(
&self,
logger: &TurboSubscriber,
) -> Result<Option<(AppSender, JoinHandle<Result<(), tui::Error>>)>, Error> {
// Print prelude here as this needs to happen before the UI is started
if self.should_print_prelude {
Expand All @@ -205,6 +207,11 @@ impl Run {
if task_names.is_empty() {
return Ok(None);
}
// Redirect any tracing logs to a file to prevent logs from corrupting
// the TUI
if let Err(e) = logger.redirect_logs_to_file(&self.repo_root) {
warn!("failed to redirect logs to file: {e}");
}

let (sender, receiver) = AppSender::new();
let handle = tokio::task::spawn_blocking(move || tui::run_app(task_names, receiver));
Expand Down
16 changes: 10 additions & 6 deletions crates/turborepo-lib/src/run/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ use turborepo_ui::{tui, tui::AppSender};

use crate::{
cli::{Command, RunArgs},
commands,
commands::CommandBase,
commands::{self, CommandBase},
daemon::{proto, DaemonConnectorError, DaemonError},
get_version, opts, run,
run::{builder::RunBuilder, scope::target_selector::InvalidSelectorError, Run},
get_version, opts,
run::{self, builder::RunBuilder, scope::target_selector::InvalidSelectorError, Run},
signal::SignalHandler,
tracing::TurboSubscriber,
DaemonConnector, DaemonPaths,
};

Expand Down Expand Up @@ -103,7 +103,11 @@ pub enum Error {
}

impl WatchClient {
pub async fn new(base: CommandBase, telemetry: CommandEventBuilder) -> Result<Self, Error> {
pub async fn new(
base: CommandBase,
telemetry: CommandEventBuilder,
logger: &TurboSubscriber,
) -> Result<Self, Error> {
let signal = commands::run::get_signal()?;
let handler = SignalHandler::new(signal);

Expand All @@ -123,7 +127,7 @@ impl WatchClient {

let watched_packages = run.get_relevant_packages();

let (sender, handle) = run.start_experimental_ui()?.unzip();
let (sender, handle) = run.start_experimental_ui(logger)?.unzip();

let connector = DaemonConnector {
can_start_server: true,
Expand Down
Loading