sea_orm_tracing/
lib.rs

1//! # sea-orm-tracing
2//!
3//! OpenTelemetry-compatible tracing instrumentation for SeaORM database operations.
4//!
5//! This crate provides transparent tracing for all SeaORM database queries, automatically
6//! creating spans with proper parent-child relationships that integrate with your existing
7//! tracing infrastructure (like HTTP request spans from axum or actix-web).
8//!
9//! ## Features
10//!
11//! - **Automatic Instrumentation**: All queries executed through `TracedConnection` are traced
12//! - **OpenTelemetry Compatible**: Spans include semantic conventions for database operations
13//! - **Proper Span Nesting**: Database spans appear as children of HTTP request spans
14//! - **SQL Visibility**: Optionally include the actual SQL statement in spans
15//! - **Performance Metrics**: Query duration, row counts, and error tracking
16//! - **Zero Config**: Works out of the box with sensible defaults
17//!
18//! ## Quick Start
19//!
20//! ```rust,ignore
21//! use sea_orm::Database;
22//! use sea_orm_tracing::TracedConnection;
23//!
24//! // Wrap your existing connection
25//! let db = Database::connect("postgres://localhost/mydb").await?;
26//! let traced_db = TracedConnection::from(db);
27//!
28//! // Use it exactly like a normal DatabaseConnection
29//! let users = Users::find().all(&traced_db).await?;
30//! ```
31//!
32//! ## Configuration
33//!
34//! ```rust,ignore
35//! use sea_orm_tracing::{TracedConnection, TracingConfig};
36//!
37//! let config = TracingConfig::default()
38//!     .with_statement_logging(true)  // Include SQL in spans (default: false for security)
39//!     .with_parameter_logging(false) // Include query parameters (default: false)
40//!     .with_slow_query_threshold(Duration::from_millis(100));
41//!
42//! let traced_db = TracedConnection::new(db, config);
43//! ```
44//!
45//! ## Span Attributes
46//!
47//! The following OpenTelemetry semantic convention attributes are recorded:
48//!
49//! | Attribute | Description |
50//! |-----------|-------------|
51//! | `db.system` | Always "postgresql", "mysql", or "sqlite" |
52//! | `db.operation` | SQL operation (SELECT, INSERT, UPDATE, DELETE) |
53//! | `db.sql.table` | Target table name (when detectable) |
54//! | `db.statement` | Full SQL query (when enabled) |
55//! | `db.rows_affected` | Number of rows returned/affected |
56//! | `otel.status_code` | "OK" or "ERROR" |
57//! | `error.message` | Error details (on failure) |
58
59mod config;
60mod connection;
61mod parser;
62
63pub use config::TracingConfig;
64pub use connection::{TracedConnection, TracingExt};
65
66/// Prelude module for convenient imports
67pub mod prelude {
68    pub use crate::{TracedConnection, TracingConfig, TracingExt};
69}