Skip to content

Commit

Permalink
feat: add telemetry for DAP debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
obycode committed May 12, 2022
1 parent 0177caa commit c7a29f5
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ mod generate;
mod indexer;
mod integrate;
mod lsp;
mod dap;
mod poke;
mod publish;
mod runnner;
Expand Down
3 changes: 1 addition & 2 deletions src/frontend/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::io::{prelude::*, BufReader, Read};
use std::path::PathBuf;
use std::{env, process};

use crate::dap::run_dap;
use crate::generate::{
self,
changes::{Changes, TOMLEdition},
Expand Down Expand Up @@ -668,7 +667,7 @@ pub fn main() {
}
}
Command::LSP => run_lsp(),
Command::DAP => match run_dap() {
Command::DAP => match super::dap::run_dap() {
Ok(_) => (),
Err(e) => {
println!("{}: {}", red!("error"), e);
Expand Down
28 changes: 21 additions & 7 deletions src/dap/mod.rs → src/frontend/dap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,32 @@ use crate::types::Network;
use clarity_repl::clarity::debug::dap::DAPDebugger;
use std::path::PathBuf;

#[cfg(feature = "telemetry")]
use super::telemetry::{telemetry_report_event, DeveloperUsageDigest, DeveloperUsageEvent};

pub fn run_dap() -> Result<(), String> {
let mut dap = DAPDebugger::new();
match dap.init() {
Ok((manifest, expression)) => {
let manifest_path = PathBuf::from(manifest);
let mut session = match load_session(&manifest_path, false, &Network::Devnet) {
Ok((session, _, _, _)) => session,
Err((_, e)) => {
println!("{}: unable to load session: {}", red!("error"), e);
std::process::exit(1);
}
};
let (mut session, project_manifest) =
match load_session(&manifest_path, false, &Network::Devnet) {
Ok((session, _, project_manifest, _)) => (session, project_manifest),
Err((_, e)) => {
println!("{}: unable to load session: {}", red!("error"), e);
std::process::exit(1);
}
};

if project_manifest.project.telemetry {
#[cfg(feature = "telemetry")]
telemetry_report_event(DeveloperUsageEvent::DAPDebugStarted(
DeveloperUsageDigest::new(
&project_manifest.project.name,
&project_manifest.project.authors,
),
));
}

for contract in &session.settings.initial_contracts {
dap.path_to_contract_id.insert(
Expand Down
1 change: 1 addition & 0 deletions src/frontend/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod cli;
pub mod dap;
#[cfg(feature = "telemetry")]
mod telemetry;
10 changes: 10 additions & 0 deletions src/frontend/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub enum DeveloperUsageEvent {
DevnetExecuted(DeveloperUsageDigest),
ContractPublished(DeveloperUsageDigest, Network),
DebugStarted(DeveloperUsageDigest, u32),
DAPDebugStarted(DeveloperUsageDigest),
UnknownCommand(DeveloperUsageDigest, String),
}

Expand Down Expand Up @@ -121,6 +122,15 @@ async fn send_event(event: DeveloperUsageEvent) {
"sessions": num_sessions,
}),
),
DeveloperUsageEvent::DAPDebugStarted(digest) => (
"DAPDebugStarted",
json!({
"project_id": digest.project_id,
"team_id": digest.team_id,
"clarinet_version": clarinet_version,
"ci_mode": ci_mode,
}),
),
DeveloperUsageEvent::UnknownCommand(digest, command) => (
"UnknownCommand",
json!({
Expand Down

0 comments on commit c7a29f5

Please sign in to comment.