Skip to content

Commit 8a9b6e5

Browse files
committed
feat: dockerfile
1 parent 90f3dad commit 8a9b6e5

File tree

5 files changed

+52
-7
lines changed

5 files changed

+52
-7
lines changed

Cargo.lock

Lines changed: 31 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repository = "https://github.com/init4tech/bin-base"
1616
# Tracing
1717
tracing = "0.1.40"
1818
tracing-core = "0.1.33"
19-
tracing-subscriber = { version = "0.3.18", features = ["registry"] }
19+
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "registry"] }
2020

2121
# OTLP
2222
opentelemetry_sdk = "0.28.0"

Dockerfile.otlp-export

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM rust:1.81
2+
3+
COPY ./ ./
4+
5+
RUN cargo run --example otlp-export --manifest-path ./Cargo.toml

src/utils/metrics.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ pub struct MetricsConfig {
1717
pub port: u16,
1818
}
1919

20+
impl Default for MetricsConfig {
21+
fn default() -> Self {
22+
Self { port: 9000 }
23+
}
24+
}
25+
2026
impl From<Option<u16>> for MetricsConfig {
2127
fn from(port: Option<u16>) -> Self {
2228
Self {
@@ -35,7 +41,10 @@ impl FromEnv for MetricsConfig {
3541
type Error = std::num::ParseIntError;
3642

3743
fn from_env() -> Result<Self, FromEnvErr<Self::Error>> {
38-
u16::from_env_var(METRICS_PORT).map(Self::from)
44+
match u16::from_env_var(METRICS_PORT).map(Self::from) {
45+
Ok(cfg) => Ok(cfg),
46+
Err(_) => Ok(Self::default()),
47+
}
3948
}
4049
}
4150

src/utils/tracing.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::utils::otlp::{OtelConfig, OtelGuard};
2-
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
2+
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, Layer};
33

44
/// Init tracing, returning an optional guard for the OTEL provider.
55
///
@@ -16,7 +16,10 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
1616
///
1717
/// [`OtelConfig`]: crate::utils::otlp::OtelConfig
1818
pub fn init_tracing() -> Option<OtelGuard> {
19-
let registry = tracing_subscriber::registry().with(tracing_subscriber::fmt::layer());
19+
let registry = tracing_subscriber::registry().with(
20+
tracing_subscriber::fmt::layer()
21+
.with_filter(tracing_subscriber::filter::EnvFilter::from_default_env()),
22+
);
2023

2124
if let Some(cfg) = OtelConfig::load() {
2225
let guard = cfg.provider();

0 commit comments

Comments
 (0)