cognee_lib/telemetry.rs
1//! Telemetry surface for embedders.
2//!
3//! Re-exports the public API of [`cognee_observability`] (OTEL setup,
4//! gap 01) and [`cognee_telemetry`] (`send_telemetry` product-analytics
5//! client, gap 02) so consumers reach both through the same
6//! `cognee_lib::telemetry` namespace.
7//!
8//! When the `telemetry` cargo feature is on, observability re-exports
9//! pull in `cognee-observability` and the `send_telemetry` re-exports
10//! pull in the real `cognee-telemetry` impl. When the feature is off,
11//! observability re-exports vanish and the `send_telemetry` re-exports
12//! resolve to the noop bodies inside `cognee-telemetry` (so
13//! `cognee_telemetry::send_telemetry` and
14//! `cognee_telemetry::TelemetryError` are always available — they
15//! exist regardless of feature state in the leaf crate).
16
17// --- gap 01: OTEL/observability surface (feature-gated) ---------------------
18
19#[cfg(feature = "telemetry")]
20pub use cognee_observability::{
21 BoxedTelemetryLayer, SettingsView, TelemetryGuard, TelemetryInitError, already_instrumented,
22 init_telemetry, is_tracing_enabled, parse_otlp_headers,
23};
24
25#[cfg(feature = "telemetry")]
26use crate::config::Settings;
27
28#[cfg(feature = "telemetry")]
29impl SettingsView for Settings {
30 fn tracing_enabled(&self) -> bool {
31 self.cognee_tracing_enabled
32 }
33
34 fn service_name(&self) -> &str {
35 &self.otel_service_name
36 }
37
38 fn otlp_endpoint(&self) -> &str {
39 &self.otel_exporter_otlp_endpoint
40 }
41
42 fn otlp_headers(&self) -> &str {
43 &self.otel_exporter_otlp_headers
44 }
45
46 fn otlp_protocol(&self) -> &str {
47 &self.otel_exporter_otlp_protocol
48 }
49
50 fn span_processor(&self) -> &str {
51 &self.otel_span_processor
52 }
53
54 fn traces_sampler(&self) -> &str {
55 &self.otel_traces_sampler
56 }
57
58 fn traces_sampler_arg(&self) -> &str {
59 &self.otel_traces_sampler_arg
60 }
61}
62
63// --- gap 02: send_telemetry product-analytics surface (always available) ----
64//
65// `cognee_telemetry::{send_telemetry, try_send_telemetry, TelemetryError,
66// UserIdRef, PropertyValue}` are exported by the leaf crate in BOTH
67// feature states (the leaf crate switches between real and noop bodies
68// internally, but the symbols are stable). Re-export them unconditionally
69// so callers compile under `--no-default-features` and can name
70// `cognee_lib::telemetry::TelemetryError`.
71
72pub use cognee_telemetry::{
73 PropertyValue, TelemetryError, UserIdRef, send_telemetry, try_send_telemetry,
74};
75
76#[cfg(feature = "telemetry")]
77pub use cognee_telemetry::{env, ids, payload, sanitize};