Skip to content

feat: setup logging with tracing #291

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 4 commits into from
May 18, 2023
Merged

feat: setup logging with tracing #291

merged 4 commits into from
May 18, 2023

Conversation

FMFigueroa
Copy link
Contributor

No description provided.

Copy link
Member

@LeoBorai LeoBorai left a comment

Choose a reason for hiding this comment

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

Nice work setting up tracing!
Lets clean up a bit test code and take back trailing newlines please.

#[arg(long, default_value = "7878")]
#[arg(long, default_value = "3000")]
Copy link
Member

Choose a reason for hiding this comment

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

Can we keep this as 7878? Which is the one used in The Rust Programming Language Book?

Using TcpListener, we can listen for TCP connections at the address 127.0.0.1:7878. In the address, the section before the colon is an IP address representing your computer (this is the same on every computer and doesn’t represent the authors’ computer specifically), and 7878 is the port. We’ve chosen this port for two reasons: HTTP isn’t normally accepted on this port so our server is unlikely to conflict with any other web server you might have running on your machine, and 7878 is rust typed on a telephone.

}
}
Copy link
Member

Choose a reason for hiding this comment

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

Please keep the trailing newline

Comment on lines 25 to 26
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Please keep the trailing newline

async fn handler_custom() -> impl IntoResponse {
info!("A request has been received on a custom route");
Html("Hello <strong>Rust!!!</strong>")
}
Copy link
Member

Choose a reason for hiding this comment

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

Please keep the trailing newline

Comment on lines 36 to 44

async fn handler_default() -> impl IntoResponse{
debug!("A request has been received on the default route");
Html("Hello <strong>Rust!!!</strong>")
}

async fn handler_custom() -> impl IntoResponse {
info!("A request has been received on a custom route");
Html("Hello <strong>Rust!!!</strong>")
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove this as not related to tracing?

@LeoBorai LeoBorai changed the title feat: ✨ Add Tracing for Axum feat: add Tracing for Axum May 17, 2023
@FMFigueroa
Copy link
Contributor Author

FMFigueroa commented May 17, 2023

It's something very simple... it could be improved later...
at least it's well formatted !

@LeoBorai
Copy link
Member

Thanks @FMFigueroa! Can you run cargo fmt please?

@FMFigueroa
Copy link
Contributor Author

Thanks @FMFigueroa! Can you run cargo fmt please?

Sure.. Apology man..!

Copy link
Member

@LeoBorai LeoBorai left a comment

Choose a reason for hiding this comment

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

Lets merge tracing first and then move into file explorer pls

Comment on lines -5 to +6
pub struct Server(Router);
pub struct Server(pub Router);
Copy link
Member

Choose a reason for hiding this comment

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

Lets keep the Router encapsulated and use the getter we have as a method instead

Comment on lines 15 to +18
fn from(value: Cli) -> Self {
let filter = EnvFilter::from_default_env().add_directive(Level::INFO.into());

tracing_subscriber::fmt().with_env_filter(filter).init();
Copy link
Member

Choose a reason for hiding this comment

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

Taking advantage of the Cli I think we could have a log argument we could use to pass it to the tracing_subscriber. This way we could do:

http-server --log debug

This would set the Level::DEBUG in L16.

Comment on lines 17 to 19
/// Directory to serve files from
#[arg(long, default_value = "./")]
pub root_dir: PathBuf,
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this into its own PR? Given that is out of scope of tracing?

Copy link
Member

@LeoBorai LeoBorai left a comment

Choose a reason for hiding this comment

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

LGTM!

@LeoBorai LeoBorai changed the title feat: add Tracing for Axum feat: setup logging with tracing May 18, 2023
@LeoBorai LeoBorai merged commit a236e26 into http-server-rs:main May 18, 2023
This was referenced Jul 2, 2023
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.

2 participants