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
//! Backend-storage metric bridge.
//!
//! Walks the storage engine's [`surrealdb_core::kvs::Datastore::register_metrics`]
//! manifest and registers each entry as an OpenTelemetry observable gauge.
//! The callbacks fire on every collection (Prometheus scrape or OTLP push),
//! pulling fresh values from the datastore.
//!
//! # Security / exposure
//!
//! All storage-backend metrics are prefixed with `surrealdb.storage.` and
//! resolved by the Prometheus text exporter to `surrealdb_storage_*`. None
//! of these names are in [`super::public::PUBLIC_METRICS`], so the
//! `/metrics` handler filters them out for unauthenticated consumers. They
//! only reach scrapers that present root-level credentials.
//!
//! # Name sanitisation
//!
//! Storage engines report hierarchical names with dots (e.g.
//! `rocksdb.block_cache_usage`). We prepend `surrealdb.storage.` and pass
//! the rest through unchanged; the Prometheus text exporter handles the
//! dot-to-underscore conversion at render time.
use Arc;
use Datastore;
use ObservabilityRuntime;
const STORAGE_METER_SCOPE: &str = "surrealdb.storage";
/// Register every metric exposed by `ds.register_metrics()` as an OTel
/// observable gauge under the `surrealdb.storage` meter scope of the
/// supplied runtime.
///
/// Returns the number of metrics registered. Zero indicates the active
/// storage flavour does not expose backend metrics.