Skip to content

Commit

Permalink
chore(telemetry): track dot env usage (#7876)
Browse files Browse the repository at this point in the history
### Description

Adds tracking for usage of `globalDotEnv` and `dotEnv` in `turbo.json`

### Testing Instructions

👀 


Closes TURBO-2741
  • Loading branch information
chris-olszewski authored Apr 1, 2024
1 parent f1d64e9 commit a76ab4c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/turborepo-lib/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use petgraph::Graph;
use thiserror::Error;
use turborepo_errors::Spanned;
use turborepo_repository::package_graph::{PackageGraph, PackageName};
use turborepo_telemetry::events::generic::GenericEventBuilder;

use crate::{run::task_id::TaskId, task_graph::TaskDefinition};

Expand Down Expand Up @@ -177,6 +178,12 @@ impl Engine<Built> {
&self.task_definitions
}

pub fn track_usage(&self, telemetry: &GenericEventBuilder) {
for task in self.task_definitions.values() {
telemetry.track_dot_env(task.dot_env.as_deref());
}
}

pub fn validate(
&self,
package_graph: &PackageGraph,
Expand Down
2 changes: 2 additions & 0 deletions crates/turborepo-lib/src/run/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ impl RunBuilder {
&root_package_json,
is_single_package,
)?;
root_turbo_json.track_usage(&run_telemetry);

pkg_dep_graph.validate()?;

Expand Down Expand Up @@ -358,6 +359,7 @@ impl RunBuilder {
pkg_dep_graph.remove_package_dependencies();
engine = self.build_engine(&pkg_dep_graph, &root_turbo_json, &filtered_pkgs)?;
}
engine.track_usage(&run_telemetry);

let color_selector = ColorSelector::default();

Expand Down
6 changes: 6 additions & 0 deletions crates/turborepo-lib/src/turbo_json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use tracing::debug;
use turbopath::{AbsoluteSystemPath, AnchoredSystemPath, RelativeUnixPathBuf};
use turborepo_errors::Spanned;
use turborepo_repository::{package_graph::ROOT_PKG_NAME, package_json::PackageJson};
use turborepo_telemetry::events::generic::GenericEventBuilder;

use crate::{
cli::OutputLogsMode,
Expand Down Expand Up @@ -657,6 +658,11 @@ impl TurboJson {
.flat_map(|validation| validation(self))
.collect()
}

pub fn track_usage(&self, telemetry: &GenericEventBuilder) {
let global_dot_env = self.global_dot_env.as_deref();
telemetry.track_global_dot_env(global_dot_env);
}
}

type TurboJSONValidation = fn(&TurboJson) -> Vec<Error>;
Expand Down
23 changes: 23 additions & 0 deletions crates/turborepo-telemetry/src/events/generic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fmt::Display;

use serde::{Deserialize, Serialize};
use turbopath::RelativeUnixPathBuf;
use turborepo_vercel_api::telemetry::{TelemetryEvent, TelemetryGenericEvent};
use uuid::Uuid;

Expand Down Expand Up @@ -212,6 +213,28 @@ impl GenericEventBuilder {
self
}

pub fn track_global_dot_env(&self, global_dot_env: Option<&[RelativeUnixPathBuf]>) -> &Self {
if let Some(global_dot_env) = global_dot_env {
self.track(Event {
key: "global_dot_env".into(),
value: global_dot_env.len().to_string(),
is_sensitive: EventType::NonSensitive,
});
}
self
}

pub fn track_dot_env(&self, dot_env: Option<&[RelativeUnixPathBuf]>) -> &Self {
if let Some(dot_env) = dot_env {
self.track(Event {
key: "dot_env".into(),
value: dot_env.len().to_string(),
is_sensitive: EventType::NonSensitive,
});
}
self
}

// errors
pub fn track_error(&self, error: TrackedErrors) -> &Self {
self.track(Event {
Expand Down

0 comments on commit a76ab4c

Please sign in to comment.