这是indexloc提供的服务,不要输入任何密码
Skip to content

feat(telem): track ui mode #9698

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

Merged
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
40 changes: 27 additions & 13 deletions crates/turborepo-lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1273,10 +1273,10 @@ pub async fn run(
}
#[allow(unused_variables)]
Command::Daemon { command, idle_time } => {
CommandEventBuilder::new("daemon")
.with_parent(&root_telemetry)
.track_call();
let event = CommandEventBuilder::new("daemon").with_parent(&root_telemetry);
event.track_call();
let base = CommandBase::new(cli_args.clone(), repo_root, version, color_config)?;
event.track_ui_mode(base.opts.run_opts.ui_mode);

match command {
Some(command) => daemon::daemon_client(command, &base).await,
Expand Down Expand Up @@ -1307,10 +1307,11 @@ pub async fn run(
Ok(0)
}
Command::Info => {
CommandEventBuilder::new("info")
.with_parent(&root_telemetry)
.track_call();
let event = CommandEventBuilder::new("info").with_parent(&root_telemetry);

event.track_call();
let base = CommandBase::new(cli_args.clone(), repo_root, version, color_config)?;
event.track_ui_mode(base.opts.run_opts.ui_mode);

info::run(base).await;
Ok(0)
Expand All @@ -1319,19 +1320,26 @@ pub async fn run(
let event = CommandEventBuilder::new("telemetry").with_parent(&root_telemetry);
event.track_call();
let mut base = CommandBase::new(cli_args.clone(), repo_root, version, color_config)?;
event.track_ui_mode(base.opts.run_opts.ui_mode);
let child_event = event.child();
telemetry::configure(command, &mut base, child_event);
Ok(0)
}
Command::Scan {} => {
let event = CommandEventBuilder::new("scan").with_parent(&root_telemetry);
event.track_call();
let base = CommandBase::new(cli_args.clone(), repo_root, version, color_config)?;
event.track_ui_mode(base.opts.run_opts.ui_mode);
if scan::run(base).await {
Ok(0)
} else {
Ok(1)
}
}
Command::Config => {
CommandEventBuilder::new("config")
.with_parent(&root_telemetry)
.track_call();
config::run(repo_root, cli_args).await?;
Ok(0)
}
Expand All @@ -1345,7 +1353,7 @@ pub async fn run(
let output = *output;
let packages = packages.clone();
let base = CommandBase::new(cli_args, repo_root, version, color_config)?;

event.track_ui_mode(base.opts.run_opts.ui_mode);
ls::run(base, packages, event, output).await?;

Ok(0)
Expand All @@ -1356,9 +1364,8 @@ pub async fn run(
yes,
target,
} => {
CommandEventBuilder::new("link")
.with_parent(&root_telemetry)
.track_call();
let event = CommandEventBuilder::new("link").with_parent(&root_telemetry);
event.track_call();

if cli_args.team.is_some() {
warn!("team flag does not set the scope for linking. Use --scope instead.");
Expand All @@ -1374,6 +1381,7 @@ pub async fn run(
let yes = *yes;
let scope = scope.clone();
let mut base = CommandBase::new(cli_args, repo_root, version, color_config)?;
event.track_ui_mode(base.opts.run_opts.ui_mode);

link::link(&mut base, scope, modify_gitignore, yes, to).await?;

Expand All @@ -1385,6 +1393,7 @@ pub async fn run(
let invalidate = *invalidate;

let mut base = CommandBase::new(cli_args, repo_root, version, color_config)?;
event.track_ui_mode(base.opts.run_opts.ui_mode);
let event_child = event.child();

logout::logout(&mut base, invalidate, event_child).await?;
Expand All @@ -1403,6 +1412,7 @@ pub async fn run(
let force = *force;

let mut base = CommandBase::new(cli_args, repo_root, version, color_config)?;
event.track_ui_mode(base.opts.run_opts.ui_mode);
let event_child = event.child();

if let Some(sso_team) = sso_team {
Expand All @@ -1414,16 +1424,16 @@ pub async fn run(
Ok(0)
}
Command::Unlink { target } => {
CommandEventBuilder::new("unlink")
.with_parent(&root_telemetry)
.track_call();
let event = CommandEventBuilder::new("unlink").with_parent(&root_telemetry);
event.track_call();
if cli_args.test_run {
println!("Unlink test run successful");
return Ok(0);
}

let from = *target;
let mut base = CommandBase::new(cli_args, repo_root, version, color_config)?;
event.track_ui_mode(base.opts.run_opts.ui_mode);

unlink::unlink(&mut base, from)?;

Expand All @@ -1437,6 +1447,7 @@ pub async fn run(
event.track_call();

let base = CommandBase::new(cli_args.clone(), repo_root, version, color_config)?;
event.track_ui_mode(base.opts.run_opts.ui_mode);

if execution_args.tasks.is_empty() {
print_potential_tasks(base, event).await?;
Expand Down Expand Up @@ -1464,6 +1475,7 @@ pub async fn run(
event.track_call();

let base = CommandBase::new(cli_args, repo_root, version, color_config)?;
event.track_ui_mode(base.opts.run_opts.ui_mode);

let query = query::run(base, event, query, variables.as_deref()).await?;

Expand All @@ -1473,6 +1485,7 @@ pub async fn run(
let event = CommandEventBuilder::new("watch").with_parent(&root_telemetry);
event.track_call();
let base = CommandBase::new(cli_args.clone(), repo_root, version, color_config)?;
event.track_ui_mode(base.opts.run_opts.ui_mode);

if execution_args.tasks.is_empty() {
print_potential_tasks(base, event).await?;
Expand Down Expand Up @@ -1503,6 +1516,7 @@ pub async fn run(
let docker = *docker;
let output_dir = output_dir.clone();
let base = CommandBase::new(cli_args, repo_root, version, color_config)?;
event.track_ui_mode(base.opts.run_opts.ui_mode);
let event_child = event.child();
prune::prune(&base, &scope, docker, &output_dir, event_child).await?;
Ok(0)
Expand Down
11 changes: 11 additions & 0 deletions crates/turborepo-lib/src/turbo_json/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{
collections::{BTreeMap, HashMap, HashSet},
fmt::Display,
ops::{Deref, DerefMut},
sync::Arc,
};
Expand Down Expand Up @@ -193,6 +194,16 @@ impl Default for UIMode {
}
}

impl Display for UIMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
UIMode::Tui => write!(f, "tui"),
UIMode::Stream => write!(f, "stream"),
UIMode::Web => write!(f, "web"),
}
}
}

impl UIMode {
pub fn use_tui(&self) -> bool {
matches!(self, Self::Tui)
Expand Down
11 changes: 11 additions & 0 deletions crates/turborepo-telemetry/src/events/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ impl CommandEventBuilder {
self
}

// ui
pub fn track_ui_mode(&self, val: impl Display) -> &Self {
self.track(Event {
key: "ui".to_string(),
value: val.to_string(),
is_sensitive: EventType::NonSensitive,
send_in_ci: false,
});
self
}

// telemetry
pub fn track_telemetry_config(&self, enabled: bool) -> &Self {
self.track(Event {
Expand Down
Loading