Rebrand to Galaxy, major improvements to Bedrock support, still needs some TLC though

This commit is contained in:
Ryan Ward
2026-05-07 11:29:34 -05:00
parent f4e2475c60
commit a41cbd8cc7
2433 changed files with 14208 additions and 9409 deletions
+113
View File
@@ -0,0 +1,113 @@
mod event_store;
use chrono::{DateTime, Utc};
use lazy_static::lazy_static;
use parking_lot::Mutex;
use serde_json::Value;
use std::borrow::Cow;
use event_store::*;
pub use event_store::{Event, EventPayload};
lazy_static! {
static ref TELEMETRY: Mutex<EventStore> = Mutex::new(EventStore::new());
}
#[macro_export]
macro_rules! record_telemetry_from_ctx {
($user_id: expr, $anonymous_id: expr, $name:expr, $payload: expr, $contains_ugc: expr, $ctx: expr) => {{
let timestamp = $crate::time::get_current_time();
$ctx.background_executor()
.spawn(async move {
$crate::telemetry::record_event(
$user_id,
$anonymous_id,
$name,
$payload,
$contains_ugc,
timestamp,
)
})
.detach();
}};
}
#[macro_export]
macro_rules! record_telemetry_on_executor {
($user_id: expr, $anonymous_id: expr, $name:expr, $payload: expr, $contains_ugc: expr, $executor: expr) => {{
let timestamp = $crate::time::get_current_time();
let _ = $executor
.spawn(async move {
$crate::telemetry::record_event(
$user_id,
$anonymous_id,
$name,
$payload,
$contains_ugc,
timestamp,
)
})
.detach();
}};
}
/// Creates a new `Event`, but does not record it. It is up to the caller to determine when, and
/// how, the event should be recorded.
pub fn create_event(
user_id: Option<String>,
anonymous_id: String,
name: Cow<'static, str>,
payload: Option<Value>,
contains_ugc: bool,
timestamp: DateTime<Utc>,
) -> Event {
let mut telemetry = TELEMETRY.lock();
telemetry.create_event(
user_id,
anonymous_id,
name,
payload,
contains_ugc,
timestamp,
)
}
pub fn record_event(
user_id: Option<String>,
anonymous_id: String,
name: Cow<'static, str>,
payload: Option<Value>,
contains_ugc: bool,
timestamp: DateTime<Utc>,
) {
let mut telemetry = TELEMETRY.lock();
telemetry.record_event(
user_id,
anonymous_id,
name,
payload,
contains_ugc,
timestamp,
);
}
pub fn record_identify_user_event(user_id: String, anonymous_id: String, timestamp: DateTime<Utc>) {
let mut telemetry = TELEMETRY.lock();
telemetry.record_identify_user_event(user_id, anonymous_id, timestamp);
}
/// Adds a 'App Active' event to the global event queue. This should only be called in an async
/// context.
pub fn record_app_active_event(
user_id: Option<String>,
anonymous_id: String,
timestamp: DateTime<Utc>,
) {
let mut telemetry = TELEMETRY.lock();
telemetry.record_app_active(user_id, anonymous_id, timestamp);
}
pub fn flush_events() -> Vec<Event> {
TELEMETRY.lock().events.drain(..).collect()
}