cognee_http_server/telemetry.rs
1//! Per-endpoint product-analytics emission helper.
2//!
3//! Mirrors the `send_telemetry("… API Endpoint Invoked", user.id, {…})`
4//! calls in the Python FastAPI routers
5//! (`cognee/api/v1/*/routers/get_*_router.py`). Each `/api/v1/*` handler
6//! calls [`emit`] near its top so the wire payload matches Python.
7//!
8//! The whole surface is gated by the `telemetry` cargo feature: with it
9//! off (e.g. a `--no-default-features` build), [`emit`] compiles to a
10//! noop and `cognee-telemetry` is not even a dependency. Callers pass a
11//! fully-built `serde_json::Value::Object` of `additional_properties`
12//! and never need a `#[cfg(...)]` of their own.
13//!
14//! `cognee_version` is intentionally **omitted** from the per-endpoint
15//! properties: the base `send_telemetry` payload already carries it at
16//! `properties.cognee_version`, so the on-the-wire field is present
17//! exactly once and matches Python (which spreads it into
18//! `additional_properties`).
19
20use serde_json::Value;
21use uuid::Uuid;
22
23/// Emit a `"… API Endpoint Invoked"` analytics event for `user_id` with
24/// the given `additional_properties` object.
25///
26/// No-op when the `telemetry` feature is disabled. Fire-and-forget —
27/// returns immediately; transport errors are swallowed at debug level on
28/// the `cognee.telemetry` tracing target.
29#[cfg(feature = "telemetry")]
30#[inline]
31pub fn emit(event_name: &str, user_id: Uuid, additional_properties: Value) {
32 cognee_telemetry::send_telemetry(event_name, user_id, Some(additional_properties));
33}
34
35/// No-op stand-in when the `telemetry` feature is disabled. Keeps router
36/// handlers free of `#[cfg]` clutter.
37#[cfg(not(feature = "telemetry"))]
38#[inline]
39pub fn emit(_event_name: &str, _user_id: Uuid, _additional_properties: Value) {}