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: ensure spans are created in tests regardless of log level #10526

Closed
wants to merge 1 commit into from

Conversation

hamz2a
Copy link
Contributor

@hamz2a hamz2a commented Jan 24, 2025

Problem:

When running tests with RUST_LOG=warn or RUST_LOG=error, the axum-tracing-opentelemetry crate doesn't create spans if the log level is below info. This causes tests of views::stdcm_logs to fail because there is no trace_id (span) generated.

Solution:

To fix this, we modified the create_tracing_subscriber function to ignore the RUST_LOG environment variable during tests. This ensures that spans (trace_id) are always created, even when the log level is set to warn or error, allowing the tests to run correctly.

@hamz2a hamz2a requested a review from a team as a code owner January 24, 2025 17:07
@github-actions github-actions bot added the area:editoast Work on Editoast Service label Jan 24, 2025
@hamz2a hamz2a self-assigned this Jan 24, 2025
@codecov-commenter
Copy link

codecov-commenter commented Jan 24, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.

Project coverage is 81.82%. Comparing base (4302966) to head (a3ed539).
Report is 31 commits behind head on dev.

Files with missing lines Patch % Lines
editoast/src/client/runserver.rs 0.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev   #10526      +/-   ##
==========================================
+ Coverage   81.81%   81.82%   +0.01%     
==========================================
  Files        1073     1073              
  Lines      106718   106840     +122     
  Branches      730      730              
==========================================
+ Hits        87306    87423     +117     
- Misses      19373    19378       +5     
  Partials       39       39              
Flag Coverage Δ
editoast 74.29% <93.33%> (+<0.01%) ⬆️
front 89.34% <ø> (ø)
gateway 2.18% <ø> (ø)
osrdyne 3.28% <ø> (ø)
railjson_generator 87.50% <ø> (ø)
tests 88.14% <ø> (+1.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@woshilapin
Copy link
Contributor

To give more precisions, we evaluated another solution with forcing the directive otel::tracing=info when configuring the tracer. It's not ideal because doing so is not deactivable afterwards (it takes higher precedence than RUST_LOG).

The rational for choosing this solution was: this is not an application problem, this is a "test" problem since we do not control enough the test environment (configuring RUST_LOG may break the tests). That the reason why we chose to give the test, the power to not take RUST_LOG into account.

Copy link
Contributor

@bougue-pe bougue-pe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Thanks for digging on this, after test it works for me (not approving as I'm not confident on how it interfaces with the feature, didn't dig on this).

@@ -46,7 +46,7 @@ pub struct RunserverArgs {
/// If this option is set, logging for the STDCM will be enabled.
/// When enabled, relevant logs will be captured to aid in debugging and monitoring.
#[clap(long, env = "ENABLE_STDCM_LOGGING", default_value_t = true)]
enable_stdcm_logging: bool,
pub(crate) enable_stdcm_logging: bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this pub?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a left over from previous modifications when we experimented different solutions, we don't need that anymore I believe.

.with_default_directive(log_level.into());

let env_filter_layer = if ignore_rust_log {
env_filter_builder.parse_lossy("")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussing with @woshilapin, Opening a non-mandatory conversation after comparing RUST_LOG=warn,otel::tracing=info cargo test on dev with RUST_LOG=warn cargo test on this branch: both are working as for tests.
The "current branch case" still logs a lot more on affected tests.

So here are a few ideas (non-blocking, can be ignored because "not worth the time"):

  1. just add otel::tracing=info instead of ignoring RUST_LOG for tests?
  2. maybe really always force otel::tracing=info (except explicit, which is probably a pain to parse)
  3. use INFO log level for effected tests (instead of current DEBUG)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One solution we explored was to always have otel::tracing=info enabled. But this makes it not possible to deactivate through configuration. The only place where we want it activated is for tests where we want to control our test environment. This is something we didn't explore with @hamz2a and I made #10531 as an alternative proposition.

@hamz2a
Copy link
Contributor Author

hamz2a commented Jan 29, 2025

#10531

@hamz2a hamz2a closed this Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:editoast Work on Editoast Service
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants