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

fix(telemetry): don't report usage data for dev builds #258

Merged
merged 1 commit into from
Feb 11, 2021
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
2 changes: 1 addition & 1 deletion crates/sputnik/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl Session {

/// sends anonymous usage data to the endpoint defined in ReportingInfo.
pub fn report(&self) -> Result<(), SputnikError> {
if self.reporting_info.is_telemetry_enabled {
if self.reporting_info.is_telemetry_enabled && !cfg!(debug_assertions) {
// set timeout to 400 ms to prevent blocking for too long on reporting
let timeout = Duration::from_millis(4000);
let body = serde_json::to_string(&self)?;
Expand Down
298 changes: 297 additions & 1 deletion installers/npm/package-lock.json

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

23 changes: 11 additions & 12 deletions src/utils/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use sputnik::{Command, Report, SputnikError};
use std::collections::HashMap;

const TELEMETRY_URL: &str = "https://install.apollographql.workers.dev/telemetry";
const ROVER_VERSION: &str = env!("CARGO_PKG_VERSION");
const ROVER_NAME: &str = env!("CARGO_PKG_NAME");

fn get_command_from_args(mut raw_arguments: &mut serde_json::Value) -> Command {
let mut commands = Vec::new();
Expand Down Expand Up @@ -96,11 +98,11 @@ impl Report for Rover {
}

fn tool_name(&self) -> String {
env!("CARGO_PKG_NAME").to_string()
ROVER_NAME.to_string()
}

fn version(&self) -> String {
env!("CARGO_PKG_VERSION").to_string()
ROVER_VERSION.to_string()
}

fn machine_id_config(&self) -> Result<PathBuf, SputnikError> {
Expand All @@ -124,10 +126,11 @@ mod tests {

use std::collections::HashMap;

use super::ROVER_NAME;

#[test]
fn it_can_serialize_commands() {
let cli_name = env!("CARGO_PKG_NAME");
let args = vec![cli_name, "config", "list"];
let args = vec![ROVER_NAME, "config", "list"];
let rover = Rover::from_iter(args);
let actual_serialized_command = rover
.serialize_command()
Expand All @@ -141,8 +144,7 @@ mod tests {

#[test]
fn it_can_serialize_commands_with_arguments() {
let cli_name = env!("CARGO_PKG_NAME");
let args = vec![cli_name, "config", "show", "default", "--sensitive"];
let args = vec![ROVER_NAME, "config", "show", "default", "--sensitive"];
let rover = Rover::from_iter(args);
let actual_serialized_command = rover
.serialize_command()
Expand All @@ -159,8 +161,7 @@ mod tests {
#[test]
fn it_respects_apollo_telemetry_url() {
let apollo_telemetry_url = "https://example.com/telemetry";
let cli_name = env!("CARGO_PKG_NAME");
let args = vec![cli_name, "config", "list"];
let args = vec![ROVER_NAME, "config", "list"];
let mut rover = Rover::from_iter(args);
rover
.env_store
Expand All @@ -176,8 +177,7 @@ mod tests {

#[test]
fn it_can_be_disabled() {
let cli_name = env!("CARGO_PKG_NAME");
let args = vec![cli_name, "config", "list"];
let args = vec![ROVER_NAME, "config", "list"];
let mut rover = Rover::from_iter(args);
rover.env_store.insert(RoverEnvKey::TelemetryDisabled, "1");
let expect_enabled = false;
Expand All @@ -188,8 +188,7 @@ mod tests {

#[test]
fn it_is_enabled_by_default() {
let cli_name = env!("CARGO_PKG_NAME");
let args = vec![cli_name, "config", "list"];
let args = vec![ROVER_NAME, "config", "list"];
let rover = Rover::from_iter(args);
let expect_enabled = true;
let is_telemetry_enabled = rover.is_telemetry_enabled().unwrap();
Expand Down