Skip to main content

drizzle_core/
tracing.rs

1//! Tracing utilities for drizzle query and transaction observability.
2//!
3//! Enable the `tracing` feature to emit spans and events via the `tracing` crate.
4//! These macros no-op when the feature is disabled, avoiding `#[cfg]` boilerplate
5//! at every call site.
6
7/// Emit a debug-level tracing event with the SQL text and parameter count.
8///
9/// ```rust
10/// # let _ = r####"
11/// drizzle_trace_query!(&sql_str, params.len());
12/// # "####;
13/// ```
14#[macro_export]
15macro_rules! drizzle_trace_query {
16    ($sql:expr, $param_count:expr) => {
17        #[cfg(feature = "tracing")]
18        tracing::debug!(sql = %$sql, params = $param_count, "drizzle.query");
19    };
20}
21
22/// Emit an info-level tracing event for transaction lifecycle (begin, commit, rollback).
23///
24/// ```rust
25/// # let _ = r####"
26/// drizzle_trace_tx!("begin", "sqlite.rusqlite");
27/// drizzle_trace_tx!("commit", "postgres.sync");
28/// # "####;
29/// ```
30#[macro_export]
31macro_rules! drizzle_trace_tx {
32    ($event:literal, $driver:literal) => {
33        #[cfg(feature = "tracing")]
34        tracing::info!(event = $event, driver = $driver, "drizzle.transaction");
35    };
36}