Skip to main content

cognis_trace/
lib.rs

1//! Pluggable observability for Cognis.
2//!
3//! Bridges [`cognis_core::CallbackHandler`] events to external observability
4//! backends. Phase 1 ships the bridge handler, three core types, two built-in
5//! exporters (stdout + mock), and the Langfuse backend (traces, prompts,
6//! scores). LangSmith and OpenTelemetry are Phase 2.
7//!
8//! # Quick start
9//!
10//! ```no_run
11//! use cognis_trace::{MockExporter, TraceMeta, TracingHandler};
12//! use cognis_trace::meta::merge_into;
13//!
14//! # async fn main_inner() {
15//! let handler = TracingHandler::builder()
16//!     .with_exporter(MockExporter::new())
17//!     .with_default_pricing()
18//!     .build();
19//!
20//! let metadata = merge_into(serde_json::Value::Null, TraceMeta::session("session-abc"));
21//! # }
22//! ```
23//!
24//! See `docs/superpowers/specs/2026-05-06-cognis-trace-design.md` for the
25//! full design.
26
27#![warn(missing_docs)]
28#![warn(clippy::all)]
29
30pub mod batch;
31pub mod cost;
32pub mod error;
33pub mod exporter;
34pub mod exporters;
35pub mod handler;
36pub mod meta;
37pub mod parent;
38pub mod prompts;
39pub mod scores;
40pub mod span;
41
42pub use batch::{Batcher, BatcherConfig, BatcherStats};
43pub use cost::{default_pricing_2026_05, ModelPrice, PriceTable};
44pub use error::TraceError;
45pub use exporter::TraceExporter;
46pub use exporters::mock::MockExporter;
47pub use handler::{TracingHandler, TracingHandlerBuilder};
48pub use meta::TraceMeta;
49pub use prompts::{ChatMessageTemplate, Prompt, PromptBody, PromptStore};
50pub use scores::ScoreSink;
51pub use span::{
52    CostDetails, Generation, ObservationLevel, ScoreRecord, ScoreValue, Span, SpanBuilder,
53    SpanKind, TokenUsage,
54};
55
56#[cfg(feature = "stdout")]
57pub use exporters::stdout::StdoutExporter;
58
59#[cfg(feature = "langfuse")]
60pub use exporters::langfuse::{
61    LangfuseConfig, LangfuseExporter, LangfusePromptClient, LangfuseScorer,
62};