mirror of https://github.com/buster-so/buster.git
posthog telemetry for domain name
This commit is contained in:
parent
80bfde0dd4
commit
2858bedac5
|
@ -9,6 +9,8 @@ REDIS_URL="redis://buster-redis:6379"
|
||||||
LOG_LEVEL="debug"
|
LOG_LEVEL="debug"
|
||||||
SUPABASE_URL="http://kong:8000"
|
SUPABASE_URL="http://kong:8000"
|
||||||
SUPABASE_SERVICE_ROLE_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.ey AgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q"
|
SUPABASE_SERVICE_ROLE_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.ey AgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q"
|
||||||
|
POSTHOG_TELEMETRY_KEY="phc_zZraCicSTfeXX5b9wWQv2rWG8QB4Z3xlotOT7gFtoNi"
|
||||||
|
TELEMETRY_ENABLED="true"
|
||||||
|
|
||||||
# AI VARS
|
# AI VARS
|
||||||
RERANK_API_KEY="your_rerank_api_key"
|
RERANK_API_KEY="your_rerank_api_key"
|
||||||
|
|
|
@ -34,6 +34,7 @@ diesel = { version = "2", features = [
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"postgres",
|
"postgres",
|
||||||
] }
|
] }
|
||||||
|
posthog-rs = "0.3.5"
|
||||||
diesel-async = { version = "0.5.2", features = ["postgres", "bb8"] }
|
diesel-async = { version = "0.5.2", features = ["postgres", "bb8"] }
|
||||||
futures = "0.3.30"
|
futures = "0.3.30"
|
||||||
async-trait = "0.1.85"
|
async-trait = "0.1.85"
|
||||||
|
|
|
@ -19,6 +19,7 @@ futures = { workspace = true }
|
||||||
regex = { workspace = true }
|
regex = { workspace = true }
|
||||||
indexmap = { workspace = true }
|
indexmap = { workspace = true }
|
||||||
async-trait = { workspace = true }
|
async-trait = { workspace = true }
|
||||||
|
posthog-rs = { workspace = true }
|
||||||
|
|
||||||
|
|
||||||
# Local dependencies
|
# Local dependencies
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::env;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use database::{
|
use database::{
|
||||||
|
@ -9,13 +11,11 @@ use database::{
|
||||||
use diesel::insert_into;
|
use diesel::insert_into;
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
use middleware::AuthenticatedUser;
|
use middleware::AuthenticatedUser;
|
||||||
|
use posthog_rs::{client, ClientOptions, ClientOptionsBuilder, Event};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
/// Creates a new organization and adds the creating user as a WorkspaceAdmin.
|
/// Creates a new organization and adds the creating user as a WorkspaceAdmin.
|
||||||
pub async fn post_organization_handler(
|
pub async fn post_organization_handler(name: String, user: AuthenticatedUser) -> Result<()> {
|
||||||
name: String,
|
|
||||||
user: AuthenticatedUser,
|
|
||||||
) -> Result<()> {
|
|
||||||
let pool = get_pg_pool();
|
let pool = get_pg_pool();
|
||||||
let mut conn = pool
|
let mut conn = pool
|
||||||
.get()
|
.get()
|
||||||
|
@ -75,5 +75,48 @@ pub async fn post_organization_handler(
|
||||||
user.id
|
user.id
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if env::var("TELEMETRY_ENABLED").unwrap_or_default() == "true" {
|
||||||
|
let user_domain = user.email.split('@').last().unwrap_or_default().to_string();
|
||||||
|
let user_company_name = new_organization.name.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let posthog_telemetry_key = env::var("POSTHOG_TELEMETRY_KEY").unwrap_or_default();
|
||||||
|
let client_options = match ClientOptionsBuilder::default()
|
||||||
|
.api_key(posthog_telemetry_key)
|
||||||
|
.api_endpoint("https://us.i.posthog.com/capture".to_string())
|
||||||
|
.build()
|
||||||
|
{
|
||||||
|
Ok(client_options) => client_options,
|
||||||
|
Err(e) => {
|
||||||
|
tracing::error!("Failed to create client options: {}", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let client = client(client_options).await;
|
||||||
|
|
||||||
|
let mut event = Event::new("New Company Signup", &user.id.to_string());
|
||||||
|
|
||||||
|
let _ = event
|
||||||
|
.insert_prop("User Domain", &user_domain)
|
||||||
|
.map_err(|e| {
|
||||||
|
tracing::error!("Failed to insert user domain: {}", e);
|
||||||
|
e
|
||||||
|
});
|
||||||
|
let _ = event
|
||||||
|
.insert_prop("User Company Name", &user_company_name)
|
||||||
|
.map_err(|e| {
|
||||||
|
tracing::error!("Failed to insert user company name: {}", e);
|
||||||
|
e
|
||||||
|
});
|
||||||
|
|
||||||
|
match client.capture(event).await {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(e) => {
|
||||||
|
tracing::error!("Failed to capture event: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
|
@ -152,9 +152,40 @@ async fn setup_persistent_app_environment() -> Result<PathBuf, BusterError> {
|
||||||
async fn run_docker_compose_command(
|
async fn run_docker_compose_command(
|
||||||
args: &[&str],
|
args: &[&str],
|
||||||
operation_name: &str,
|
operation_name: &str,
|
||||||
|
no_track: bool,
|
||||||
) -> Result<(), BusterError> {
|
) -> Result<(), BusterError> {
|
||||||
let persistent_app_dir = setup_persistent_app_environment().await?;
|
let persistent_app_dir = setup_persistent_app_environment().await?;
|
||||||
|
|
||||||
|
// --- BEGIN Telemetry Update ---
|
||||||
|
if operation_name == "Starting" && no_track {
|
||||||
|
let main_dot_env_target_path = persistent_app_dir.join(".env");
|
||||||
|
if main_dot_env_target_path.exists() {
|
||||||
|
let mut content = fs::read_to_string(&main_dot_env_target_path).map_err(|e| {
|
||||||
|
BusterError::CommandError(format!(
|
||||||
|
"Failed to read root .env file for telemetry update: {}",
|
||||||
|
e
|
||||||
|
))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let original_content = content.clone();
|
||||||
|
content = content.replace("TELEMETRY_ENABLED=\"true\"", "TELEMETRY_ENABLED=\"false\"");
|
||||||
|
content = content.replace("TELEMETRY_ENABLED=true", "TELEMETRY_ENABLED=false"); // Also handle without quotes
|
||||||
|
|
||||||
|
if content != original_content {
|
||||||
|
fs::write(&main_dot_env_target_path, content).map_err(|e| {
|
||||||
|
BusterError::CommandError(format!(
|
||||||
|
"Failed to write updated .env file for telemetry update: {}",
|
||||||
|
e
|
||||||
|
))
|
||||||
|
})?;
|
||||||
|
println!("Telemetry disabled in {}", main_dot_env_target_path.display());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("Warning: Root .env file not found at {}. Could not disable telemetry.", main_dot_env_target_path.display());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// --- END Telemetry Update ---
|
||||||
|
|
||||||
// Handle LiteLLM config if a start or reset operation is being performed
|
// Handle LiteLLM config if a start or reset operation is being performed
|
||||||
if operation_name == "Starting" || operation_name == "Resetting" {
|
if operation_name == "Starting" || operation_name == "Resetting" {
|
||||||
// Check if litellm_config path is in environment
|
// Check if litellm_config path is in environment
|
||||||
|
@ -306,12 +337,13 @@ async fn run_docker_compose_command(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn start() -> Result<(), BusterError> {
|
pub async fn start(no_track: bool) -> Result<(), BusterError> {
|
||||||
run_docker_compose_command(&["up", "-d"], "Starting").await
|
run_docker_compose_command(&["up", "-d"], "Starting", no_track).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn stop() -> Result<(), BusterError> {
|
pub async fn stop() -> Result<(), BusterError> {
|
||||||
run_docker_compose_command(&["down"], "Stopping").await
|
// Pass false for no_track as it's irrelevant for 'stop'
|
||||||
|
run_docker_compose_command(&["down"], "Stopping", false).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn reset() -> Result<(), BusterError> {
|
pub async fn reset() -> Result<(), BusterError> {
|
||||||
|
|
|
@ -91,7 +91,11 @@ pub enum Commands {
|
||||||
/// Interactively manage LLM and Reranker configurations
|
/// Interactively manage LLM and Reranker configurations
|
||||||
Config,
|
Config,
|
||||||
/// Start the Buster services
|
/// Start the Buster services
|
||||||
Start,
|
Start {
|
||||||
|
/// Disable telemetry tracking
|
||||||
|
#[arg(long, default_value_t = false)]
|
||||||
|
no_track: bool,
|
||||||
|
},
|
||||||
/// Stop the Buster services
|
/// Stop the Buster services
|
||||||
Stop,
|
Stop,
|
||||||
/// Restart the Buster services
|
/// Restart the Buster services
|
||||||
|
@ -157,7 +161,7 @@ async fn main() {
|
||||||
} => commands::generate::generate_semantic_models_command(path, target_semantic_file).await,
|
} => commands::generate::generate_semantic_models_command(path, target_semantic_file).await,
|
||||||
Commands::Parse { path } => commands::parse::parse_models_command(path).await,
|
Commands::Parse { path } => commands::parse::parse_models_command(path).await,
|
||||||
Commands::Config => commands::config::manage_settings_interactive().await.map_err(anyhow::Error::from),
|
Commands::Config => commands::config::manage_settings_interactive().await.map_err(anyhow::Error::from),
|
||||||
Commands::Start => run::start().await.map_err(anyhow::Error::from),
|
Commands::Start { no_track } => run::start(no_track).await.map_err(anyhow::Error::from),
|
||||||
Commands::Stop => run::stop().await.map_err(anyhow::Error::from),
|
Commands::Stop => run::stop().await.map_err(anyhow::Error::from),
|
||||||
Commands::Reset => run::reset().await.map_err(anyhow::Error::from),
|
Commands::Reset => run::reset().await.map_err(anyhow::Error::from),
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,6 +41,8 @@ services:
|
||||||
- LLM_API_KEY=${LLM_API_KEY}
|
- LLM_API_KEY=${LLM_API_KEY}
|
||||||
- LLM_BASE_URL=${LLM_BASE_URL}
|
- LLM_BASE_URL=${LLM_BASE_URL}
|
||||||
- RUST_LOG=debug
|
- RUST_LOG=debug
|
||||||
|
- POSTHOG_TELEMETRY_KEY=${POSTHOG_TELEMETRY_KEY}
|
||||||
|
- TELEMETRY_ENABLED=${TELEMETRY_ENABLED}
|
||||||
ports:
|
ports:
|
||||||
- "3001:3001"
|
- "3001:3001"
|
||||||
- "3000:3000"
|
- "3000:3000"
|
||||||
|
|
Loading…
Reference in New Issue