Skip to content

Instantly share code, notes, and snippets.

@nlopes
Last active October 29, 2023 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nlopes/30296f28d87c407219c075be1ad4835c to your computer and use it in GitHub Desktop.
Save nlopes/30296f28d87c407219c075be1ad4835c to your computer and use it in GitHub Desktop.
rust tracing setup
// 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