Skip to content

feat: Native axum executor integration#152

Draft
yulnr wants to merge 4 commits into
dial9-rs:mainfrom
yulnr:feat/axum-executor-integration
Draft

feat: Native axum executor integration#152
yulnr wants to merge 4 commits into
dial9-rs:mainfrom
yulnr:feat/axum-executor-integration

Conversation

@yulnr

@yulnr yulnr commented Apr 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes #62

Implements the new axum::serve::Executor on TelemetryHandle behind features = ["axum"]
Deletes axum_traced.rs (previous hand-rolled serve loop) and simplifies metrics-service example to use axum::serve directly.

Depends on this being released: tokio-rs/axum#3704

Before

Users had to reimplement axum's serve loop to inject traced task spawning:

// axum_traced.rs: custom Serve, WithGracefulShutdown,
// TracedExecutor, IncomingStream, accept loop, graceful shutdown...
axum_traced::serve(listener, app, handle.clone())
    .with_graceful_shutdown(signal)
    .await;

After

#[derive(Clone)]                                                                                                                                                                                      
struct TelemetryExecutor(TelemetryHandle);                       
                                            
impl axum::serve::Executor for TelemetryExecutor {
    fn execute<Fut>(&self, fut: Fut)
    where                                                                                                                                                                                             
        Fut: Future<Output = ()> + Send + 'static,
    {                                                                                                                                                                                                 
        self.0.spawn(fut);                                       
    }
}                                                                                                                                                                                                     
 
axum::serve(listener, app)                                                                                                                                                                            
    .with_executor(TelemetryExecutor(handle))                    
    .with_graceful_shutdown(signal)
    .await;

Now that axum supports Serve::with_executor(), implement axum::serve::Executor directly on TelemetryHandle behind an "axum" feature flag.
@yulnr
yulnr force-pushed the feat/axum-executor-integration branch from 341bf00 to 471fc4e Compare April 1, 2026 13:59
@netlify

netlify Bot commented Apr 1, 2026

Copy link
Copy Markdown

Deploy Preview for dial9-tokio-telemetry canceled.

Name Link
🔨 Latest commit 8c7ccda
🔍 Latest deploy log https://app.netlify.com/projects/dial9-tokio-telemetry/deploys/69d3908ef7138c000807c931

axum::serve(listener, app.into_make_service())
.with_executor(handle.clone())
.with_graceful_shutdown(async move { shutdown.cancelled().await })
.await

@yulnr yulnr Apr 1, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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 {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good idea, done

@yulnr yulnr changed the title feat: Native axum executor integration via feature flag feat: Native axum executor integration Apr 13, 2026
@yulnr yulnr self-assigned this Apr 21, 2026
@jlizen

jlizen commented May 31, 2026

Copy link
Copy Markdown
Member

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?

@yulnr

yulnr commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bridge to hyper-util executor for the dial9 spawn hook

3 participants