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: setup tracing with opentelemetry for TestApp #10122

Merged

Conversation

hamz2a
Copy link
Contributor

@hamz2a hamz2a commented Dec 18, 2024

closes #10123

I added the OpenTelemetry layer in TestApp to capture the trace_id set in the header, so we can test the endpoint we'll add in the ticket.

  • Refactored init_tracing to accept a custom SpanExporter for better flexibility, including support for testing scenarios.
  • Updated main.rs to configure and initialize tracing.
  • Modified setup tracing in test_app.rs to use opentelemetry layer.

@hamz2a hamz2a requested a review from a team as a code owner December 18, 2024 12:00
@github-actions github-actions bot added the area:editoast Work on Editoast Service label Dec 18, 2024
@hamz2a hamz2a requested a review from woshilapin December 18, 2024 12:01
@hamz2a hamz2a changed the title editoast: setup tracing with opentelemetry for TestApp editoast: setup tracing with opentelemetry for TestApp Dec 18, 2024
@codecov-commenter
Copy link

codecov-commenter commented Dec 18, 2024

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

Codecov Report

Attention: Patch coverage is 86.66667% with 8 lines in your changes missing coverage. Please review.

Project coverage is 81.44%. Comparing base (6a105bf) to head (52acc68).
Report is 1 commits behind head on dev.

Files with missing lines Patch % Lines
editoast/src/client/telemetry_config.rs 0.00% 6 Missing ⚠️
editoast/editoast_common/src/tracing.rs 95.34% 2 Missing ⚠️

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

Additional details and impacted files
@@            Coverage Diff             @@
##              dev   #10122      +/-   ##
==========================================
+ Coverage   79.93%   81.44%   +1.50%     
==========================================
  Files        1057     1058       +1     
  Lines      106302   104318    -1984     
  Branches      724      724              
==========================================
- Hits        84977    84966      -11     
+ Misses      21283    19310    -1973     
  Partials       42       42              
Flag Coverage Δ
editoast 73.58% <86.66%> (-0.34%) ⬇️
front 89.19% <ø> (ø)
gateway 2.18% <ø> (ø)
osrdyne 3.28% <ø> (ø)
railjson_generator 87.50% <ø> (ø)
tests 87.00% <ø> (ø)

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.

@hamz2a hamz2a force-pushed the hai/editoast-setup-tracing-with-opentelemetry-for-test-app branch from c5b5f96 to 8a7a2ad Compare December 18, 2024 12:14
Copy link
Contributor

@woshilapin woshilapin left a comment

Choose a reason for hiding this comment

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

Thank you for the PR. Let's see if we can improve it.

editoast/src/main.rs Outdated Show resolved Hide resolved
editoast/Cargo.toml Outdated Show resolved Hide resolved
@hamz2a hamz2a force-pushed the hai/editoast-setup-tracing-with-opentelemetry-for-test-app branch from 8a7a2ad to c361ea8 Compare December 18, 2024 14:32
@hamz2a hamz2a requested a review from woshilapin December 18, 2024 14:34
editoast/src/main.rs Outdated Show resolved Hide resolved
editoast/src/main.rs Outdated Show resolved Hide resolved
@hamz2a hamz2a force-pushed the hai/editoast-setup-tracing-with-opentelemetry-for-test-app branch from c361ea8 to b5ff13b Compare December 18, 2024 16:31
Copy link
Contributor

@leovalais leovalais 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 this PR. A few comments about architecture and test isolation. Besides, with the context of what you're working on I suppose this is about collecting logs for unit testing, but it's not clear to me how that would work. Why does printing logs on stdout help? Do you plan to capture the stream? A bit more context in the PR description or in the related issue would help.

editoast/Cargo.toml Outdated Show resolved Hide resolved
editoast/src/views/test_app.rs Outdated Show resolved Hide resolved
editoast/src/views/test_app.rs Outdated Show resolved Hide resolved
editoast/src/views/test_app.rs Outdated Show resolved Hide resolved
@hamz2a
Copy link
Contributor Author

hamz2a commented Dec 19, 2024

Thanks for this PR. A few comments about architecture and test isolation. Besides, with the context of what you're working on I suppose this is about collecting logs for unit testing, but it's not clear to me how that would work. Why does printing logs on stdout help? Do you plan to capture the stream? A bit more context in the PR description or in the related issue would help.

Apologies for that. I've added more details in the description, and I hope it helps clarify things.

@leovalais
Copy link
Contributor

I added the OpenTelemetry layer in TestApp to capture the trace_id set in the header, so we can test the endpoint we'll add in the #9724.

Thanks for adding some context. So if I get it right, the point is not to necessarily print on stdout, but rather to setup OpenTelemetry so that the request header can be read. The fact that it prints on stdout is irrelevant, or am I missing smth?

I'm surely lacking OpenTelemetry and tracing knowledge, but I still don't understand what setting up a span exporter has to do with reading the HTTP request headers? Especially since the middleware OtelAxumLayer::default() is set in the TestApp.

@hamz2a
Copy link
Contributor Author

hamz2a commented Dec 19, 2024

Thanks for adding some context. So if I get it right, the point is not to necessarily print on stdout, but rather to setup OpenTelemetry so that the request header can be read. The fact that it prints on stdout is irrelevant, or am I missing smth?

I'm surely lacking OpenTelemetry and tracing knowledge, but I still don't understand what setting up a span exporter has to do with reading the HTTP request headers? Especially since the middleware OtelAxumLayer::default() is set in the TestApp.

You're right, printing to stdout is irrelevant.
The goal is to have the same init_tracing setup for both editoast webservice and TestApp. That's why I kept the same configuration. @woshilapin, do you confirm?

@woshilapin
Copy link
Contributor

woshilapin commented Dec 20, 2024

I'm surely lacking OpenTelemetry and tracing knowledge, but I still don't understand what setting up a span exporter has to do with reading the HTTP request headers? Especially since the middleware OtelAxumLayer::default() is set in the TestApp.

@leovalais From what I understand, OtelAxumLayer emits span events, the SpanExporter is used in the subscriber to these events and will consume these span events to export them somewhere (to Datadog, to stdout, etc.). But you're right, we shouldn't need opentelemetry_stdout since we already have the tracing::layer::fmt() configured, which prints to the terminal.

But as said by @hamz2a, one of the main idea of this PR is to have a similar setup of the subscriber for tests and for production code. We had a hard time debugging what was not working and part of it was that it was working well with a cargo run -- runserver but not with cargo test, and some of the problems came from this difference between production code and tests.

@hamz2a hamz2a force-pushed the hai/editoast-setup-tracing-with-opentelemetry-for-test-app branch from b5ff13b to 4492eb8 Compare December 20, 2024 14:56
@hamz2a hamz2a requested a review from leovalais December 20, 2024 15:02
editoast/src/views/test_app.rs Outdated Show resolved Hide resolved
editoast/src/views/test_app.rs Outdated Show resolved Hide resolved
@hamz2a hamz2a force-pushed the hai/editoast-setup-tracing-with-opentelemetry-for-test-app branch from 4492eb8 to 112a5c5 Compare December 20, 2024 16:22
@hamz2a hamz2a requested a review from woshilapin December 20, 2024 16:23
editoast/Cargo.toml Outdated Show resolved Hide resolved
Copy link
Contributor

@woshilapin woshilapin left a comment

Choose a reason for hiding this comment

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

I believe it's in a much better state now 🚀. Thank you 🎉

@hamz2a hamz2a force-pushed the hai/editoast-setup-tracing-with-opentelemetry-for-test-app branch 2 times, most recently from 9d9e553 to 373cf12 Compare December 23, 2024 10:36
editoast/Cargo.toml Outdated Show resolved Hide resolved
editoast/src/main.rs Outdated Show resolved Hide resolved
@hamz2a hamz2a force-pushed the hai/editoast-setup-tracing-with-opentelemetry-for-test-app branch from 373cf12 to 45217d4 Compare December 23, 2024 14:42
@hamz2a hamz2a requested a review from leovalais December 23, 2024 14:45
@hamz2a hamz2a force-pushed the hai/editoast-setup-tracing-with-opentelemetry-for-test-app branch 2 times, most recently from 033cbc3 to 5c49d18 Compare December 24, 2024 10:24
Copy link
Contributor

@leovalais leovalais left a comment

Choose a reason for hiding this comment

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

Almost there, thanks for the changes! There's still a dependency order issue, but apart from that, lgtm.

editoast/src/views/test_app.rs Outdated Show resolved Hide resolved
@leovalais
Copy link
Contributor

si je bouge create_tracing_subscriber je dois bouger aussi

   mode: EditoastMode,
   telemetry_config: TelemetryConfig,

Yes, but TelemetryConfig is a clap definition and EditoastMode doesn't make sense outside of the CLI. I'd suggest making a new struct for configuration:

struct TracingConfig {
   stream: enum { Stderr, Stdout },
   telemetry: Option<struct {
		service_name: String,
		telemetry_endpoint: Url
	}>
}

Wdyt?

@hamz2a hamz2a force-pushed the hai/editoast-setup-tracing-with-opentelemetry-for-test-app branch from 5c49d18 to 4418d21 Compare December 26, 2024 17:42
@hamz2a hamz2a requested a review from leovalais December 26, 2024 17:42
@hamz2a hamz2a force-pushed the hai/editoast-setup-tracing-with-opentelemetry-for-test-app branch from 4418d21 to 72ae856 Compare December 26, 2024 17:52
Copy link
Contributor

@leovalais leovalais left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for all the modifications!

editoast/src/main.rs Outdated Show resolved Hide resolved
editoast/src/views/mod.rs Outdated Show resolved Hide resolved
editoast/src/views/test_app.rs Outdated Show resolved Hide resolved
@hamz2a hamz2a force-pushed the hai/editoast-setup-tracing-with-opentelemetry-for-test-app branch from 72ae856 to 52acc68 Compare December 30, 2024 10:42
@hamz2a hamz2a enabled auto-merge December 30, 2024 10:54
@hamz2a hamz2a added this pull request to the merge queue Dec 30, 2024
Merged via the queue into dev with commit 8ac5276 Dec 30, 2024
27 checks passed
@hamz2a hamz2a deleted the hai/editoast-setup-tracing-with-opentelemetry-for-test-app branch December 30, 2024 11:53
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.

Editoast: setup tracing with opentelemetry for TestApp
4 participants