Last active
October 29, 2023 13:34
-
-
Save nlopes/30296f28d87c407219c075be1ad4835c to your computer and use it in GitHub Desktop.
rust tracing setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// main.rs | |
use tracing_subscriber::prelude::*; | |
fn main() { | |
// set up the subscriber | |
tracing_subscriber::registry() | |
.with(tracing_subscriber::EnvFilter::from_default_env()) | |
.with( | |
tracing_subscriber::fmt::layer() | |
.with_span_events(tracing_subscriber::fmt::format::FmtSpan::CLOSE), | |
) | |
.init(); | |
} | |
// Annotating functions | |
#[tracing::instrument] | |
pub fn load(path: String) -> Result<Self, Error> { | |
tracing::info!("bla"); | |
tracing::debug!(?path, "could not load"); | |
} | |
// How I annotate API endpoints | |
#[tracing::instrument(name = "/bases/:id", fields(http.method = "POST"), skip(data))] | |
pub(crate) async fn update( | |
data: Data<AppState>, | |
user: ReqData<User>, | |
id: Path<BaseId>, | |
req: Form<HashMap<String, String>>, | |
) -> Result<HttpResponse, ApiError> { | |
tracing::info!("bla"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment