use opentelemetry::{KeyValue, global};
use std::collections::HashMap;
#[cfg(feature = "opentelemetry")]
pub fn init_opentelemetry_with_otlp(_otlp_endpoint: &str) {
log::warn!(
"OpenTelemetry OTLP metrics export not configured for current versions; using default meter provider"
);
}
#[cfg(not(feature = "opentelemetry"))]
pub fn init_opentelemetry_with_otlp(_otlp_endpoint: &str) {
log::warn!("OpenTelemetry OTLP metrics export is disabled (feature not enabled)");
}
#[cfg(feature = "opentelemetry")]
pub fn track_counter(name: &str, value: u64, labels: &HashMap<String, String>) {
let meter = global::meter("relay-rl");
let counter = meter.u64_counter(name.to_string()).build();
let attributes: Vec<KeyValue> = labels
.iter()
.map(|(k, v)| KeyValue::new(k.clone(), v.clone()))
.collect();
counter.add(value, &attributes);
}
#[cfg(feature = "opentelemetry")]
pub fn track_histogram(name: &str, value: f64, labels: &HashMap<String, String>) {
let meter = global::meter("relay-rl");
let histogram = meter.f64_histogram(name.to_string()).build();
let attributes: Vec<KeyValue> = labels
.iter()
.map(|(k, v)| KeyValue::new(k.clone(), v.clone()))
.collect();
histogram.record(value, &attributes);
}
#[cfg(feature = "opentelemetry")]
pub fn create_span(_name: &str, _labels: &HashMap<String, String>) -> Option<()> {
None
}
#[cfg(not(feature = "opentelemetry"))]
pub fn track_counter(_name: &str, _value: u64, _labels: &HashMap<String, String>) {
}
#[cfg(not(feature = "opentelemetry"))]
pub fn track_histogram(_name: &str, _value: f64, _labels: &HashMap<String, String>) {
}
#[cfg(not(feature = "opentelemetry"))]
pub fn create_span(_name: &str, _labels: &HashMap<String, String>) -> Option<()> {
None
}