mas_storage_pg/
telemetry.rs

1// Copyright 2025 New Vector Ltd.
2//
3// SPDX-License-Identifier: AGPL-3.0-only
4// Please see LICENSE in the repository root for full details.
5
6use std::sync::LazyLock;
7
8use opentelemetry::{
9    InstrumentationScope,
10    metrics::{Histogram, Meter},
11};
12use opentelemetry_semantic_conventions as semcov;
13
14static SCOPE: LazyLock<InstrumentationScope> = LazyLock::new(|| {
15    InstrumentationScope::builder(env!("CARGO_PKG_NAME"))
16        .with_version(env!("CARGO_PKG_VERSION"))
17        .with_schema_url(semcov::SCHEMA_URL)
18        .build()
19});
20
21static METER: LazyLock<Meter> =
22    LazyLock::new(|| opentelemetry::global::meter_with_scope(SCOPE.clone()));
23
24pub(crate) static DB_CLIENT_CONNECTIONS_CREATE_TIME_HISTOGRAM: LazyLock<Histogram<u64>> =
25    LazyLock::new(|| {
26        METER
27            .u64_histogram("db.client.connections.create_time")
28            .with_description("The time it took to create a new connection.")
29            .with_unit("ms")
30            .build()
31    });