1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//! Lightweight OpenTelemetry instrumentation helpers for `sqlx`.
//!
//! Rather than wrap [`sqlx::Executor`] (which is impractical because the
//! trait is not dyn-compatible and bounds vary across query types), this
//! module exposes:
//!
//! - [`SqlxSpan::query`]: a constructor that opens a `tracing` span with
//! the canonical OpenTelemetry semantic-conventions database attributes
//! (`db.system`, `db.statement`, …) and lets the caller `.instrument()`
//! the underlying sqlx future.
//!
//! Usage:
//!
//! ```ignore
//! use hwhkit_observability::sqlx_instrument::SqlxSpan;
//! use tracing::Instrument;
//!
//! let stmt = "SELECT name FROM users WHERE id = $1";
//! let span = SqlxSpan::query(DbSystem::Postgres, stmt);
//! let row = sqlx::query(stmt).bind(1).fetch_one(&pool).instrument(span).await?;
//! ```
//!
//! When the `otel` feature is also enabled the spans are picked up by the
//! tracing-opentelemetry layer installed by [`crate::otel_layer::init_with_otel`].
use ;
/// SQL dialect tag used as the `db.system` attribute on instrumented
/// query spans (matching the OpenTelemetry semantic conventions).
///
/// Marked `#[non_exhaustive]` so adding new dialects in a minor release
/// (e.g. `Mssql`) is non-breaking.
/// Span constructor for sqlx queries — see [`SqlxSpan::query`].
;
/// Helper to record the `db.rows_affected` attribute on the current span
/// after a sqlx execute completes.