Skip to content

Commit

Permalink
feat: telemetry service (#1243)
Browse files Browse the repository at this point in the history
Description
---
Resolves #1186 
Add new telemetry service which receives events and immediately sends
them.

example event sent:
```json
{
  "app_id": "1b%i31CBnblWxHYxSanG",
  "cpu_name": "11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz",
  "created_at": {
    "nanos_since_epoch": 439482034,
    "secs_since_epoch": 1734106140
  },
  "event_name": "checking-latest-version-mmproxy",
  "event_value": { "percentage": 10, "service": "mmproxy" },
  "gpu_name": "Intel(R) Iris(R) Xe Graphics [0x9a49]",
  "os": "Linux",
  "user_id": "v3,FZNcifkHKvDUJ9Luwc4xBe5HiGHV,0.8.24,VWE2AdhnnMOqNDd7fcQnqVVEBAeee68KBM2+8K7iznY=",
  "version": "0.8.24"
}
```

Motivation and Context
---
This should be useful for tracking how many users are stuck during
application setup. We saw some users being stuck at 30% with now
feedback. This should help in debugging issues like that.

How Has This Been Tested?
---
Run application and watch for error message coming from telemetry
service. If no error are present that means that events were sent
correctly. Also check the telemetry dashboard to check if any messages
are present on the server.

To verify frontend command I created test button to invoke like this:
```Typescript
const sendTelemetry = () =>
    invoke('send_data_telemetry_service', {
        eventName: 'settings_opened',
        data: { service: 'frontend-test', percentage: 100 },
    });
```
And found those event present in the kafka dashboard:
```js
{
  "app_id": "CX4h8%%G$xQ0hpnZSu@N",
  "cpu_name": "11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz",
  "created_at": {
    "nanos_since_epoch": 795656093,
    "secs_since_epoch": 1736248665
  },
  "event_name": "settings_opened",
  "event_value": { "percentage": 100, "service": "frontend-test" },
  "gpu_name": "Intel(R) Iris(R) Xe Graphics [0x9a49]",
  "os": "Linux",
  "user_id": "v3,FZNcifkHKvDUJ9Luwc4xBe5HiGHV,0.8.40,VWE2AdhnnMOqNDd7fcQnqVVEBAeee68KBM2+8K7iznY",
  "version": "0.8.40"
}
```

What process can a PR reviewer use to test or verify this change?
---
Same as above.

Breaking Changes
---

- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify

---------

Co-authored-by: Brian Pearce <[email protected]>
  • Loading branch information
MCozhusheck and brianp authored Jan 13, 2025
1 parent ce5298a commit 8a61985
Show file tree
Hide file tree
Showing 12 changed files with 513 additions and 64 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:
AIRDROP_BASE_URL: http://localhost:4000
AIRDROP_API_BASE_URL: http://localhost:3004
AIRDROP_TWITTER_AUTH_URL: http://localhost:3004/auth/twitter
TELEMETRY_API_URL: http://localhost:3004
run: |
cargo install cargo-lints
cargo lints clippy --all-targets --all-features
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
AIRDROP_BASE_URL: ${{ secrets.BETA_AIRDROP_BASE_URL }}
AIRDROP_API_BASE_URL: ${{ secrets.BETA_AIRDROP_API_BASE_URL }}
AIRDROP_TWITTER_AUTH_URL: ${{ secrets.BETA_AIRDROP_TWITTER_AUTH_URL }}
TELEMETRY_API_URL: ${{ secrets.BETA_TELEMETRY_API_URL }}
AIRDROP_WEBSOCKET_CRYPTO_KEY: ${{ secrets.DEV_AIRDROP_WEBSOCKET_CRYPTO_KEY }}
shell: bash
run: |
Expand All @@ -68,6 +69,7 @@ jobs:
echo "AIRDROP_BASE_URL=${{ env.AIRDROP_BASE_URL }}" >> $GITHUB_ENV
echo "AIRDROP_API_BASE_URL=${{ env.AIRDROP_API_BASE_URL }}" >> $GITHUB_ENV
echo "AIRDROP_TWITTER_AUTH_URL=${{ env.AIRDROP_TWITTER_AUTH_URL }}" >> $GITHUB_ENV
echo "TELEMETRY_API_URL=${{ env.TELEMETRY_API_URL }}" >> $GITHUB_ENV
echo "AIRDROP_WEBSOCKET_CRYPTO_KEY=${{ env.AIRDROP_WEBSOCKET_CRYPTO_KEY }}" >> $GITHUB_ENV
echo "TS_FEATURES=release-ci-beta, airdrop-env" >> $GITHUB_ENV
# numeric-only and cannot be greater than 65535 for msi target
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ sys-locale = "0.3.1"

[features]
airdrop-env = []
telemetry-env = []
airdrop-local = []
custom-protocol = [
"tauri/custom-protocol",
Expand Down
13 changes: 12 additions & 1 deletion src-tauri/src/app_in_memory_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ const AIRDROP_TWITTER_AUTH_URL: &str = std::env!(
"AIRDROP_TWITTER_AUTH_URL",
"AIRDROP_TWITTER_AUTH_URL env var not defined"
);
#[cfg(feature = "telemetry-env")]
const TELEMETRY_API_URL: &str =
std::env!("TELEMETRY_API_URL", "TELEMETRY_API_URL env var not defined");

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct AppInMemoryConfig {
pub airdrop_url: String,
pub airdrop_api_url: String,
pub airdrop_twitter_auth_url: String,
pub airdrop_access_token: Option<String>,
pub telemetry_api_url: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down Expand Up @@ -73,6 +77,7 @@ impl Default for AppInMemoryConfig {
airdrop_api_url: "https://ut.tari.com".into(),
airdrop_twitter_auth_url: "https://airdrop.tari.com/auth".into(),
airdrop_access_token: None,
telemetry_api_url: "https://ut.tari.com/push".into(),
}
}
}
Expand Down Expand Up @@ -118,6 +123,7 @@ impl AppInMemoryConfig {
airdrop_api_url: AIRDROP_API_BASE_URL.into(),
airdrop_twitter_auth_url: AIRDROP_TWITTER_AUTH_URL.into(),
airdrop_access_token: None,
telemetry_api_url: TELEMETRY_API_URL.into(),
};

#[cfg(feature = "airdrop-local")]
Expand All @@ -126,9 +132,14 @@ impl AppInMemoryConfig {
airdrop_api_url: "http://localhost:3004".into(),
airdrop_twitter_auth_url: "http://localhost:3004/auth/twitter".into(),
airdrop_access_token: None,
telemetry_api_url: "http://localhost:3004".into(),
};

#[cfg(not(any(feature = "airdrop-local", feature = "airdrop-env")))]
#[cfg(not(any(
feature = "airdrop-local",
feature = "airdrop-env",
feature = "telemetry-env"
)))]
AppInMemoryConfig::default()
}
}
18 changes: 18 additions & 0 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use log::{debug, error, info, warn};
use monero_address_creator::Seed as MoneroSeed;
use regex::Regex;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::fmt::Debug;
use std::fs::{read_dir, remove_dir_all, remove_file, File};
use std::sync::atomic::Ordering;
Expand Down Expand Up @@ -972,6 +973,23 @@ pub async fn set_allow_telemetry(
Ok(())
}

#[tauri::command]
pub async fn send_data_telemetry_service(
state: tauri::State<'_, UniverseAppState>,
event_name: String,
data: Value,
) -> Result<(), String> {
state
.telemetry_service
.read()
.await
.send(event_name, data)
.await
.inspect_err(|e| error!(target: LOG_TARGET, "error at send_data_telemetry_service {:?}", e))
.map_err(|e| e.to_string())?;
Ok(())
}

#[tauri::command]
pub async fn set_application_language(
state: tauri::State<'_, UniverseAppState>,
Expand Down
Loading

0 comments on commit 8a61985

Please sign in to comment.