Skip to content

Add trace::ServerTiming #203

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

Merged
merged 13 commits into from
Jul 24, 2020
Merged

Add trace::ServerTiming #203

merged 13 commits into from
Jul 24, 2020

Conversation

yoshuawuyts
Copy link
Member

This PR adds a first pass of the Server-Timing headers spec, introducing it as "unstable" under http_types::trace::ServerTiming. This also moves some code around in the trace submodule to accommodate more APIs being added.

Screenshot

Screenshot_2020-07-22 http_types trace server_timing - Rust
Screenshot_2020-07-22 http_types trace - Rust(1)

@yoshuawuyts yoshuawuyts mentioned this pull request Jul 23, 2020
@yoshuawuyts
Copy link
Member Author

yoshuawuyts commented Jul 24, 2020

Seems to be working well!

Example code

use tide::http::trace::{ServerTiming, Metric};
use std::time::Duration;

#[async_std::main]
async fn main() -> Result<(), std::io::Error> {
    tide::log::start();
    let mut app = tide::new();
    app.middleware(tide::utils::After(|mut res: tide::Response| async move {
        let mut timings = ServerTiming::new();
        timings.push(Metric::new("mongodb".to_owned(), Some(Duration::from_millis(5)), None)?);
        timings.push(Metric::new("tide".to_owned(), Some(Duration::from_millis(10)), None)?);
        timings.push(Metric::new("db-query".to_owned(), Some(Duration::from_millis(2)), None)?);
        timings.apply(&mut res);
        Ok(res)
    }));
    app.at("/").get(|_| async { Ok("Hello, world!") });
    app.listen("127.0.0.1:8080").await?;
    Ok(())
}

Screenshot

Screenshot 2020-07-24 10 41 40

@yoshuawuyts
Copy link
Member Author

Oki, this is about the way it should be now. As this is still behind an "unstable" flag this should be good to merge. Thanks!

@yoshuawuyts yoshuawuyts merged commit 963aa81 into master Jul 24, 2020
@delete-merged-branch delete-merged-branch bot deleted the server-timings branch July 24, 2020 11:52
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.

1 participant