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
//! OpenTelemetry instrumentation helpers for the `redis` crate.
//!
//! Wrapping [`redis::aio::ConnectionLike`] directly is fragile because
//! `redis::cmd(...).query_async(&mut conn)` requires `&mut conn` of the
//! concrete type. We instead expose a small helper that opens a
//! `tracing::Span` per command. The caller drives the redis call inside
//! the span (typically via `Span::in_scope`).
//!
//! ```ignore
//! use hwhkit_observability::redis_instrument::redis_span;
//! use tracing::Instrument;
//!
//! let span = redis_span("GET", Some("user:42"));
//! let val: Option<String> = redis::cmd("GET")
//! .arg("user:42")
//! .query_async(&mut conn)
//! .instrument(span)
//! .await?;
//! ```
use Span;
/// Open a span describing a single redis command. `cmd_name` is the redis
/// verb (uppercase by convention). `key` is an optional key hint — only
/// the *prefix* (up to the first `:`) is recorded so high-cardinality
/// keys don't blow up the span attribute set.