Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gateway otlp config #10529

Merged
merged 2 commits into from
Feb 4, 2025
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
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ services:
OSRDYNE_API_URL: "http://osrd-osrdyne:4242/"
TELEMETRY_KIND: "opentelemetry"
TELEMETRY_ENDPOINT: "http://jaeger:4317"
OTEL_SERVICE_NAME: "osrd-editoast"
OSRD_MQ_URL: "amqp://osrd:password@osrd-rabbitmq:5672/%2f"
command:
- /bin/sh
Expand Down Expand Up @@ -186,7 +185,6 @@ services:
environment:
RUST_LOG: "info"
OSRDYNE__OPENTELEMETRY__ENDPOINT: "http://osrd-jaeger:4317"
OSRDYNE__OPENTELEMETRY__SERVICE_NAME: "osrdyne"

jaeger:
image: jaegertracing/jaeger:latest
Expand Down
2 changes: 1 addition & 1 deletion docker/gateway.dev.host.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ secret_key = "NOT+A+SECRET++NOT+A+SECRET++NOT+A+SECRET++NOT+A+SECRET++NOT+A+SECR
listen_addr = "0.0.0.0"

[telemetry.tracing]
enable = true
type = "Otlp"
endpoint = "http://localhost:4317"

[[targets]]
Expand Down
2 changes: 0 additions & 2 deletions docker/gateway.dev.simple.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ listen_addr = "0.0.0.0"
allowed_origins = ["http://127.0.0.1:3000", "http://localhost:3000"]

[telemetry.tracing]
enable = true
type = "Otlp"
service_name = "gateway"
endpoint = "http://osrd-jaeger:4317"

[[targets]]
Expand Down
2 changes: 0 additions & 2 deletions docker/gateway.pr-tests.simple.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ listen_addr = "0.0.0.0"
port = 4001

[telemetry.tracing]
enable = true
type = "Otlp"
service_name = "gateway"
endpoint = "http://osrd-jaeger-pr-tests:4319"


Expand Down
1 change: 1 addition & 0 deletions editoast/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ COPY --from=run_builder /editoast/assets /assets

ARG OSRD_GIT_DESCRIBE
ENV OSRD_GIT_DESCRIBE=${OSRD_GIT_DESCRIBE}
ENV OTEL_SERVICE_NAME="osrd-editoast"
ENV DYNAMIC_ASSETS_PATH=/assets

# We use jemalloc to reduce allocation fragmentation
Expand Down
1 change: 1 addition & 0 deletions gateway/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ COPY --from=run_builder /usr/local/cargo/bin/osrd_gateway /usr/local/bin/osrd_ga

ARG OSRD_GIT_DESCRIBE
ENV OSRD_GIT_DESCRIBE=${OSRD_GIT_DESCRIBE}
ENV OTEL_SERVICE_NAME="osrd-gateway"

CMD ["/usr/local/bin/osrd_gateway"]
2 changes: 0 additions & 2 deletions gateway/gateway.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ secret_key = "NOT+A+SECRET++NOT+A+SECRET++NOT+A+SECRET++NOT+A+SECRET++NOT+A+SECR

[telemetry.tracing]
type = "Otlp"
enable = true
service_name = "gateway"
endpoint = "http://localhost:4317"

[[targets]]
Expand Down
27 changes: 5 additions & 22 deletions gateway/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ impl Telemetry {
#[serde(tag = "type")]
pub enum TracingTelemetry {
None,
Otlp {
endpoint: String,
service_name: Option<String>,
},
Otlp { endpoint: String },
}

#[derive(Deserialize, Serialize, Clone)]
Expand All @@ -47,7 +44,7 @@ pub enum Endpoint {
}

impl TracingTelemetry {
fn enable_otlp(&self, endpoint: &String, service_name: String) {
fn enable_otlp(&self, endpoint: &String) {
let exporter = opentelemetry_otlp::new_exporter()
.tonic()
.with_endpoint(endpoint)
Expand All @@ -56,18 +53,14 @@ impl TracingTelemetry {

info!("Tracing enabled with otlp");

let resource = opentelemetry_sdk::Resource::new(vec![opentelemetry::KeyValue::new(
"service.name",
service_name,
)])
.merge(&opentelemetry_sdk::Resource::from_detectors(
let resource = opentelemetry_sdk::Resource::from_detectors(
Duration::from_secs(10),
vec![
Box::new(SdkProvidedResourceDetector),
Box::new(TelemetryResourceDetector),
Box::new(EnvResourceDetector::new()),
],
));
);
let provider = TracerProvider::builder()
.with_config(opentelemetry_sdk::trace::Config::default().with_resource(resource))
.with_batch_exporter(exporter, TokioCurrentThread)
Expand All @@ -78,18 +71,8 @@ impl TracingTelemetry {
}

pub fn enable_providers(&self) {
let service_name = match self {
TracingTelemetry::None => {
info!("Tracing disabled");
return;
}
TracingTelemetry::Otlp { service_name, .. } => {
service_name.clone().unwrap_or("osrd-gateway".to_string())
}
};

if let TracingTelemetry::Otlp { endpoint, .. } = self {
self.enable_otlp(endpoint, service_name);
self.enable_otlp(endpoint);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions osrdyne/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ COPY --from=run_builder /usr/local/cargo/bin/osrdyne /usr/local/bin/osrdyne

ARG OSRD_GIT_DESCRIBE
ENV OSRD_GIT_DESCRIBE=${OSRD_GIT_DESCRIBE}
ENV OTEL_SERVICE_NAME="osrd-osrdyne"

CMD ["/usr/local/bin/osrdyne"]
2 changes: 0 additions & 2 deletions osrdyne/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ pub struct OsrdyneConfig {

#[derive(Debug, Deserialize, Serialize)]
pub struct OpentelemetryConfig {
pub service_name: Option<String>,
pub endpoint: Url,
}

impl Default for OpentelemetryConfig {
fn default() -> Self {
Self {
service_name: None,
endpoint: "http://jaeger:4317".parse().unwrap(),
}
}
Expand Down
14 changes: 5 additions & 9 deletions osrdyne/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,14 @@ fn init_tracing(config: &OsrdyneConfig) {
.tonic()
.with_endpoint(otel.endpoint.as_str());

let svc_name = otel.service_name.clone().unwrap_or("osrdyne".to_string());

let resource = opentelemetry_sdk::Resource::new(vec![opentelemetry::KeyValue::new(
opentelemetry_semantic_conventions::resource::SERVICE_NAME,
svc_name.clone(),
)])
.merge(&opentelemetry_sdk::Resource::from_detectors(
let resource = opentelemetry_sdk::Resource::from_detectors(
Duration::from_secs(10),
vec![
Box::new(SdkProvidedResourceDetector),
Box::new(TelemetryResourceDetector),
Box::new(EnvResourceDetector::new()),
],
));
);
let trace_config = opentelemetry_sdk::trace::Config::default().with_resource(resource);

let otlp_tracer_provider = opentelemetry_otlp::new_pipeline()
Expand All @@ -254,7 +248,9 @@ fn init_tracing(config: &OsrdyneConfig) {
.install_batch(opentelemetry_sdk::runtime::Tokio)
.expect("Failed to initialize Opentelemetry tracer");

let otlp_tracer = otlp_tracer_provider.tracer(svc_name.clone());
let otlp_tracer = otlp_tracer_provider.tracer(
std::env::var("OTEL_SERVICE_NAME").unwrap_or_else(|_| String::from("osrd-osrdyne")),
);

let layer = tracing_opentelemetry::layer()
.with_tracer(otlp_tracer)
Expand Down
Loading