Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

capture: make otel service name configurable, will use deploy name #22

Merged
merged 1 commit into from
Apr 22, 2024
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
14 changes: 10 additions & 4 deletions capture-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Duration;

use envconfig::Envconfig;
use opentelemetry::KeyValue;
use opentelemetry::{KeyValue, Value};
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::trace::{BatchConfig, RandomIdGenerator, Sampler, Tracer};
use opentelemetry_sdk::{runtime, Resource};
Expand Down Expand Up @@ -31,7 +31,7 @@ async fn shutdown() {
tracing::info!("Shutting down gracefully...");
}

fn init_tracer(sink_url: &str, sampling_rate: f64) -> Tracer {
fn init_tracer(sink_url: &str, sampling_rate: f64, service_name: &str) -> Tracer {
opentelemetry_otlp::new_pipeline()
.tracing()
.with_trace_config(
Expand All @@ -42,7 +42,7 @@ fn init_tracer(sink_url: &str, sampling_rate: f64) -> Tracer {
.with_id_generator(RandomIdGenerator::default())
.with_resource(Resource::new(vec![KeyValue::new(
"service.name",
"capture",
Value::from(service_name.to_string()),
)])),
)
.with_batch_config(BatchConfig::default())
Expand All @@ -67,7 +67,13 @@ async fn main() {
let otel_layer = config
.otel_url
.clone()
.map(|url| OpenTelemetryLayer::new(init_tracer(&url, config.otel_sampling_rate)))
.map(|url| {
OpenTelemetryLayer::new(init_tracer(
&url,
config.otel_sampling_rate,
&config.otel_service_name,
))
})
.with_filter(LevelFilter::from_level(Level::INFO));
tracing_subscriber::registry()
.with(log_layer)
Expand Down
1 change: 1 addition & 0 deletions capture-server/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub static DEFAULT_CONFIG: Lazy<Config> = Lazy::new(|| Config {
},
otel_url: None,
otel_sampling_rate: 0.0,
otel_service_name: "capture-testing".to_string(),
export_prometheus: false,
});

Expand Down
3 changes: 3 additions & 0 deletions capture/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub struct Config {
#[envconfig(default = "1.0")]
pub otel_sampling_rate: f64,

#[envconfig(default = "capture")]
pub otel_service_name: String,

#[envconfig(default = "true")]
pub export_prometheus: bool,
}
Expand Down
Loading