Skip to content

Conversation

@eckter
Copy link
Contributor

@eckter eckter commented Dec 3, 2025

Part of #11478, front excluded

When opentelemetry is set, responses now contain a header such as

traceparent: 00-e535ebd1df21be08aabe3f85f8dd8d4f-c8d72478e4619cf8-01

What we call the "trace id" is what's contained between the first and second -. I assume the rest can still be relevant for some tooling, and it doesn't hurt to include a little more context.

I haven't looked into the front-end side yet.

Tested manually by looking through response headers.

@github-actions github-actions bot added area:front Work on Standard OSRD Interface modules area:editoast Work on Editoast Service kind:api-change labels Dec 3, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2025

⚠️ API changes

This Pull Request introduces some changes in the API:

  • please own it: notify or even prepare dedicated PR(s) to consumer projects

@eckter eckter force-pushed the ech/add-trace-id-to-response branch 3 times, most recently from f6ee1f7 to 3384540 Compare December 3, 2025 10:34
@eckter eckter requested a review from woshilapin December 3, 2025 10:39
@eckter eckter marked this pull request as ready for review December 3, 2025 10:39
@eckter eckter requested a review from a team as a code owner December 3, 2025 10:39
@eckter eckter force-pushed the ech/add-trace-id-to-response branch from 3384540 to 54dc143 Compare December 3, 2025 11:05
@eckter eckter requested a review from a team as a code owner December 3, 2025 11:05
@eckter eckter requested a review from shenriotpro December 3, 2025 11:05
@github-actions github-actions bot added the area:integration-tests Work on Integration test, by nature related to different services label Dec 3, 2025
Copy link
Contributor

@shenriotpro shenriotpro left a comment

Choose a reason for hiding this comment

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

nice

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.

Only a general comment on the proposed solution. In OpenTelemetry, the TraceID is usually forwarded in headers, not in the main payload. It seems that this also applies for returning information to a frontend (I’ve found this discussion about the topic). So that would mean:

  • modifying the gateway so it returns the correct header in responses to the client
  • probably modify editoast so it returns the correct header to the gateway

Maybe Devops will have an opinion about this? (cc @Khoyo @gaetan-osrd)

@woshilapin
Copy link
Contributor

woshilapin commented Dec 3, 2025

On the front side, it seems to be possible to do with RTK on a per-endpoint granularity (which is exactly what we want here) with the help of transformResponse (thank you @emersion)

@eckter
Copy link
Contributor Author

eckter commented Dec 3, 2025

Only a general comment on the proposed solution. In OpenTelemetry, the TraceID is usually forwarded in headers, not in the main payload. It seems that this also applies for returning information to a frontend (I’ve found this discussion about the topic). So that would mean:

I don't have a strong preference. Headers feel more "clean". But the goal here isn't just correlating telemetry, it's an actual data to be included in the final response (generated PDF file).

(btw I didn't plan for this ticket to take more than a few hours)

@flomonster
Copy link
Member

Only a general comment on the proposed solution. In OpenTelemetry, the TraceID is usually forwarded in headers, not in the main payload. It seems that this also applies for returning information to a frontend (I’ve found this discussion about the topic). So that would mean:

* modifying the gateway so it returns the correct header in responses to the client

* probably modify editoast so it returns the correct header to the gateway

Maybe Devops will have an opinion about this? (cc @Khoyo @gaetan-osrd)

I don't think the gateway changes the headers of the response. I agree that having the information in the header is a better option.

It is possible to handle otel in the frontend so the trace_id is defined by the frontend and not the backend so it can retrieve it directly (without having to add it manually in the response).

@Khoyo
Copy link
Contributor

Khoyo commented Dec 3, 2025

I agree, we should follow opentelemetry semantics, but as long as the frontend is not actually sending telemetry data, we probably can go either way.

@eckter
Copy link
Contributor Author

eckter commented Dec 3, 2025

Sounds good to me.

But I might need somme help with editoast tooling, I still struggle to navigate the libraries and traits. I don't think there's any example in the code base where we add response headers, and it doesn't seem to fit easily into the -> Result<Json<Response>> pattern.

edit, self notes for later: apparently if we return a (Headers, Json) it just somehow works. Tuples of IntoResponse do implement IntoResponse

@woshilapin
Copy link
Contributor

woshilapin commented Dec 4, 2025

@eckter For editoast, I believe it’s only about adding the right middleware from axum-tracing-opentelemetry. If you look here, the middleware is the one that read headers for incoming request, and populate correctly the OpenTelemetry context. In the documentation of axum-tracing-opentelemetry (in the first code example), they mention the following that should be exactly what we need.

        // include trace context as header into the response
        .layer(OtelInResponseLayer::default())

@eckter eckter closed this Dec 4, 2025
@eckter eckter force-pushed the ech/add-trace-id-to-response branch from 54dc143 to ae4a975 Compare December 4, 2025 14:52
@eckter eckter reopened this Dec 4, 2025
@github-actions github-actions bot removed area:front Work on Standard OSRD Interface modules area:integration-tests Work on Integration test, by nature related to different services kind:api-change labels Dec 4, 2025
@eckter eckter changed the title editoast: add trace_id to stdcm responses editoast: add trace_id to all responses Dec 4, 2025
@eckter
Copy link
Contributor Author

eckter commented Dec 4, 2025

It's now returned in the header.

It is indeed as simple as @woshilapin said, it's now a tiny PR! I still somehow lost a lot of time there because I was testing it without enabling opentelemetry...

Note: this change affects every endpoint, not just stdcm.

(and today I learned that github automatically closes a PR if one accidentally force pushes with no commit on the branch)

@eckter eckter requested a review from woshilapin December 4, 2025 15:00
@eckter eckter force-pushed the ech/add-trace-id-to-response branch from d810df7 to 7478d34 Compare December 4, 2025 15:40
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.

6 participants