feat: Native axum executor integration#152
Conversation
Now that axum supports Serve::with_executor(), implement axum::serve::Executor directly on TelemetryHandle behind an "axum" feature flag.
341bf00 to
471fc4e
Compare
✅ Deploy Preview for dial9-tokio-telemetry canceled.
|
| axum::serve(listener, app.into_make_service()) | ||
| .with_executor(handle.clone()) | ||
| .with_graceful_shutdown(async move { shutdown.cancelled().await }) | ||
| .await |
There was a problem hiding this comment.
this unwrap diff is unrelated, unwrap no longer needed due to API change upstream
| /// Implement `axum::serve::Executor` for `TelemetryHandle` to allow it to be | ||
| /// used as an executor for axum's serve. | ||
| #[cfg(feature = "axum")] | ||
| impl axum::serve::Executor for TelemetryHandle { |
There was a problem hiding this comment.
Alternatively we could newtype this or have a struct that has the handle as field and impl axum::serve::Executor for it. This seemed the simplest for users.
There was a problem hiding this comment.
I'd probably rather have this as the 10 lines of code we need in application crates rather than putting it in core for now.
e.g. if we have multiple versions of axum etc. etc. this just becomes kind a headache.
|
Is this still needed given tokio-rs/axum#3704 ? And should we update our example to use that new feature? I guess we are still waiting on the axum release? |
@jlizen yup this PR already updates the example to pass in an executor with our telemetry into axum, I haven't opened the PR for merge until axum lands a release with this. (sorry I forgot to share update with a comment here) |
Summary
Closes #62
Implements the new
axum::serve::ExecutoronTelemetryHandlebehindfeatures = ["axum"]Deletes
axum_traced.rs(previous hand-rolled serve loop) and simplifies metrics-service example to useaxum::servedirectly.Depends on this being released: tokio-rs/axum#3704
Before
Users had to reimplement axum's serve loop to inject traced task spawning:
After