Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/utils/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::utils::from_env::{FromEnv, FromEnvErr, FromEnvVar};
use core::net::SocketAddr;
use metrics_exporter_prometheus::PrometheusBuilder;

use super::from_env::EnvItemInfo;
Expand Down Expand Up @@ -72,8 +73,14 @@ impl FromEnv for MetricsConfig {
pub fn init_metrics() {
let cfg = MetricsConfig::from_env().unwrap();

let address = SocketAddr::from(([0, 0, 0, 0], cfg.port));

PrometheusBuilder::new()
.with_http_listener(([0, 0, 0, 0], cfg.port))
.with_http_listener(address)
.install()
.expect("failed to install prometheus exporter");
.unwrap_or_else(|error| {
panic!(
"failed to install prometheus exporter on {address} (configure with {METRICS_PORT} env var): {error}",
)
});
}
6 changes: 1 addition & 5 deletions src/utils/otlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ impl Drop for OtelGuard {
/// will return [`None`].
/// - OTEL_LEVEL - optional. Specifies the minimum [`tracing::Level`] to
/// export in the [`EnvFilter`] format. Defaults to [`tracing::Level::DEBUG`].
/// - OTEL_TIMEOUT - optional. Specifies the timeout for the exporter in
/// **milliseconds**. Defaults to 1000ms, which is equivalent to 1 second.
/// - OTEL_ENVIRONMENT_NAME - optional. Value for the `deployment.environment.
/// name` resource key according to the OTEL conventions.
#[derive(Debug, Clone)]
Expand All @@ -79,7 +77,7 @@ pub struct OtelConfig {
/// Defaults to DEBUG.
pub level: EnvFilter,

/// OTEL convenition `deployment.environment.name`
/// OTEL convention `deployment.environment.name`
pub environment: String,
}

Expand Down Expand Up @@ -139,8 +137,6 @@ impl OtelConfig {
/// OTLP exporting will be disabled.
/// - `OTEL_LEVEL` - optional. Specifies the minimum [`tracing::Level`] to
/// export. Defaults to [`tracing::Level::DEBUG`].
/// - `OTEL_TIMEOUT` - optional. Specifies the timeout for the exporter in
/// **milliseconds**. Defaults to 1000ms, which is equivalent to 1 second.
/// - `OTEL_ENVIRONMENT_NAME` - optional. Value for the
/// `deployment.environment.name` resource key according to the OTEL
/// conventions. Defaults to `"unknown"`.
Expand Down