Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
brynary committed Nov 21, 2024
1 parent da64aa7 commit e410c60
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
8 changes: 2 additions & 6 deletions qlty-cli/src/commands/telemetry.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::{
telemetry::{segment::Track, SegmentClient},
telemetry::{analytics::Track, AnalyticsClient},
Arguments, CommandError, CommandSuccess,
};
use anyhow::{anyhow, Result};
use clap::Args;
use qlty_analysis::version::BUILD_PROFILE;
use qlty_config::Workspace;
use std::path::PathBuf;
use tracing::{debug, info};

Expand Down Expand Up @@ -35,9 +34,6 @@ impl Telemetry {

fn send_track(&self) -> Result<CommandSuccess, CommandError> {
let payload_path = self.track.clone().unwrap();
let current = std::env::current_dir().expect("current dir");
let repository_path = Workspace::closest_git_repository_path(&current);

let payload = std::fs::read_to_string(&payload_path).map_err(|err| {
anyhow!(
"Unable to read telemetry payload file: {} ({:?})",
Expand All @@ -46,7 +42,7 @@ impl Telemetry {
)
})?;

let client = SegmentClient::new(repository_path.clone())?;
let client = AnalyticsClient::new()?;
let event: Track = serde_json::from_str(&payload).unwrap();
client.send_track(event)?;

Expand Down
13 changes: 5 additions & 8 deletions qlty-cli/src/telemetry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use self::sanitize::sanitize_command;
use crate::arguments::is_subcommand;
use crate::telemetry::analytics::{event_context, event_user, Track};
use crate::telemetry::git::repository_identifier;
use crate::telemetry::segment::{event_context, event_user, Track};
use crate::{errors::CommandError, success::CommandSuccess};
use ::sentry::integrations::panic::message_from_panic_info;
use anyhow::Result;
Expand All @@ -16,12 +16,12 @@ use time::OffsetDateTime;
use tracing::{debug, warn};
use uuid::Uuid;

pub mod analytics;
mod git;
mod locale;
mod sanitize;
pub mod segment;

pub use segment::SegmentClient;
pub use analytics::AnalyticsClient;

#[cfg(windows)]
use std::os::windows::process::CommandExt;
Expand Down Expand Up @@ -122,10 +122,7 @@ impl Telemetry {
}

fn track(&self, event: &str, properties: serde_json::Value) -> Result<()> {
debug!(
"Tracking event to Segment (foreground): {}: {:?}",
event, properties
);
debug!("Tracking event (foreground): {}: {:?}", event, properties);
let message_id = Uuid::new_v4().to_string();

let track = Track {
Expand All @@ -149,7 +146,7 @@ impl Telemetry {
const COMMAND_ARG: &str = "--track";

let payload = serde_json::to_string(&event)?;
let filename = format!("qlty-segment-event-{}.json", message_id);
let filename = format!("qlty-event-{}.json", message_id);
let tempfile_path = std::env::temp_dir().join(filename);

std::fs::write(&tempfile_path, payload)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,18 @@ use qlty_analysis::version::QLTY_VERSION;
use serde::{Deserialize, Serialize};
use serde_json::json;
use serde_json::{Map, Value};
use std::path::PathBuf;
use time::OffsetDateTime;
use tracing::debug;

const WRITE_KEY: Option<&str> = option_env!("CIO_WRITE_KEY");
const TRACK_URL: &str = "https://cdp.customer.io/v1/track";

#[derive(Clone)]
pub struct AnalyticsClient {
repository_path: Option<PathBuf>,
}
pub struct AnalyticsClient;

impl AnalyticsClient {
pub fn new(repository_path: Option<PathBuf>) -> Result<Self> {
Ok(Self { repository_path })
pub fn new() -> Result<Self> {
Ok(Self {})
}

pub fn send_track(&self, track: Track) -> Result<()> {
Expand Down

0 comments on commit e410c60

Please sign in to comment.