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

editoast: force 'otel::tracing=info' for some tests #10531

Merged
merged 2 commits into from
Feb 7, 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
8 changes: 8 additions & 0 deletions editoast/editoast_common/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct Telemetry {
pub struct TracingConfig {
pub stream: Stream,
pub telemetry: Option<Telemetry>,
pub directives: Vec<tracing_subscriber::filter::Directive>,
}

pub fn create_tracing_subscriber<T: SpanExporter + 'static>(
Expand All @@ -38,6 +39,13 @@ pub fn create_tracing_subscriber<T: SpanExporter + 'static>(
// Set the default log level to 'info'
.with_default_directive(log_level.into())
.from_env_lossy();
let env_filter_layer = tracing_config
.directives
.clone()
.into_iter()
.fold(env_filter_layer, |env_filter_layer, directive| {
env_filter_layer.add_directive(directive)
});
let fmt_layer = tracing_subscriber::fmt::layer()
.pretty()
.with_file(true)
Expand Down
1 change: 1 addition & 0 deletions editoast/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ async fn run() -> Result<(), Box<dyn Error + Send + Sync>> {
let tracing_config = TracingConfig {
stream: EditoastMode::from_client(&client).into(),
telemetry,
directives: vec![],
};
create_tracing_subscriber(
tracing_config,
Expand Down
1 change: 1 addition & 0 deletions editoast/src/views/stdcm_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ mod tests {
.enable_authorization(config.enable_authorization)
.enable_stdcm_logging(config.enable_stdcm_logging)
.enable_telemetry(config.enable_telemetry)
.with_rust_log_directive("otel::tracing=info".parse().unwrap())
.user(user.clone())
.roles(roles)
.build();
Expand Down
9 changes: 9 additions & 0 deletions editoast/src/views/test_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use opentelemetry_sdk::export::trace::SpanData;
use opentelemetry_sdk::export::trace::SpanExporter;
use serde::de::DeserializeOwned;
use tower_http::trace::TraceLayer;
use tracing_subscriber::filter::Directive;
use url::Url;

use crate::{
Expand Down Expand Up @@ -65,6 +66,7 @@ pub(crate) struct TestAppBuilder {
enable_authorization: bool,
enable_stdcm_logging: bool,
enable_telemetry: bool,
telemetry_directives: Vec<Directive>,
user: Option<UserInfo>,
roles: HashSet<BuiltinRole>,
}
Expand All @@ -78,6 +80,7 @@ impl TestAppBuilder {
enable_authorization: false,
enable_stdcm_logging: false,
enable_telemetry: true,
telemetry_directives: vec![],
user: None,
roles: HashSet::new(),
}
Expand Down Expand Up @@ -116,6 +119,11 @@ impl TestAppBuilder {
self
}

pub fn with_rust_log_directive(mut self, directive: Directive) -> Self {
self.telemetry_directives.push(directive);
self
}

pub fn user(mut self, user: UserInfo) -> Self {
assert!(self.user.is_none());
self.user = Some(user);
Expand Down Expand Up @@ -177,6 +185,7 @@ impl TestAppBuilder {
let tracing_config = TracingConfig {
stream: Stream::Stdout,
telemetry,
directives: self.telemetry_directives,
};
let sub = create_tracing_subscriber(
tracing_config,
Expand Down
Loading