Skip to content

Commit 12db977

Browse files
feat: send telemetry data to backend (#4152)
1 parent a952eba commit 12db977

File tree

6 files changed

+350
-13
lines changed

6 files changed

+350
-13
lines changed

Cargo.lock

+7-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dfx/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ bytes.workspace = true
4444
candid = { workspace = true }
4545
candid_parser = { workspace = true, features = ["random", "assist"] }
4646
cargo_metadata = "0.18.1"
47+
chrono = "0.4.39"
4748
ci_info = "0.14"
4849
clap = { workspace = true, features = [
4950
"derive",
@@ -124,6 +125,7 @@ time = { workspace = true, features = [
124125
] }
125126
tokio = { workspace = true, features = ["full"] }
126127
url.workspace = true
128+
uuid = { version = "1.15.1", features = [ "v4", ] }
127129
walkdir.workspace = true
128130
walrus = "0.21.1"
129131
which = "4.2.5"

src/dfx/src/commands/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ mod ping;
2727
mod quickstart;
2828
mod remote;
2929
mod schema;
30+
mod send_telemetry;
3031
mod start;
3132
mod stop;
3233
mod toolchain;
@@ -60,6 +61,8 @@ pub enum DfxCommand {
6061
Quickstart(quickstart::QuickstartOpts),
6162
Remote(remote::RemoteOpts),
6263
Schema(schema::SchemaOpts),
64+
#[command(name = "_send-telemetry", hide = true)]
65+
SendTelemetry(send_telemetry::SendTelemetryOpts),
6366
Start(start::StartOpts),
6467
Stop(stop::StopOpts),
6568
#[command(hide = true)]
@@ -94,6 +97,7 @@ pub fn exec(env: &dyn Environment, cmd: DfxCommand) -> DfxResult {
9497
DfxCommand::Quickstart(v) => quickstart::exec(env, v),
9598
DfxCommand::Remote(v) => remote::exec(env, v),
9699
DfxCommand::Schema(v) => schema::exec(v),
100+
DfxCommand::SendTelemetry(v) => send_telemetry::exec(v),
97101
DfxCommand::Start(v) => start::exec(env, v),
98102
DfxCommand::Stop(v) => stop::exec(env, v),
99103
DfxCommand::Toolchain(v) => toolchain::exec(env, v),
@@ -105,6 +109,7 @@ pub fn exec(env: &dyn Environment, cmd: DfxCommand) -> DfxResult {
105109
pub fn exec_without_env(cmd: DfxCommand) -> DfxResult {
106110
match cmd {
107111
DfxCommand::Schema(v) => schema::exec(v),
112+
DfxCommand::SendTelemetry(v) => send_telemetry::exec(v),
108113
_ => bail!("Cannot execute this command without environment."),
109114
}
110115
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use crate::lib::error::DfxResult;
2+
use crate::lib::telemetry::Telemetry;
3+
use clap::Parser;
4+
use url::Url;
5+
6+
const DEFAULT_URL: &str = "https://sdk.telemetry.dfinity.network";
7+
8+
#[derive(Parser)]
9+
#[command(hide = true)]
10+
pub struct SendTelemetryOpts {
11+
#[clap(long)]
12+
url: Option<String>,
13+
}
14+
15+
pub fn exec(opts: SendTelemetryOpts) -> DfxResult {
16+
let url = opts.url.unwrap_or_else(|| DEFAULT_URL.to_string());
17+
let url = Url::parse(&url)?;
18+
19+
Telemetry::send(&url)
20+
}

0 commit comments

Comments
 (0)