{"id":22124110,"url":"https://github.com/let4be/tracing-tools","last_synced_at":"2025-03-24T07:40:28.758Z","repository":{"id":57670489,"uuid":"368828526","full_name":"let4be/tracing-tools","owner":"let4be","description":null,"archived":false,"fork":false,"pushed_at":"2021-12-04T16:05:46.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-01T23:41:26.844Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/let4be.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-19T10:22:16.000Z","updated_at":"2021-12-04T16:05:49.000Z","dependencies_parsed_at":"2022-09-26T20:41:05.627Z","dependency_job_id":null,"html_url":"https://github.com/let4be/tracing-tools","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/let4be%2Ftracing-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/let4be%2Ftracing-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/let4be%2Ftracing-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/let4be%2Ftracing-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/let4be","download_url":"https://codeload.github.com/let4be/tracing-tools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245230343,"owners_count":20581454,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-01T15:46:34.444Z","updated_at":"2025-03-24T07:40:28.708Z","avatar_url":"https://github.com/let4be.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tracing-tools - tiny lib for easier integration with tracing\n\nRight now [tracing](https://github.com/tokio-rs/tracing) is a bit unusable with async code, because recommended way to instrument `async` code is by using `#instrument` macro which\n - does not support error formatting(very painful when using together with crates such as anyhow as it will swallow error chain)\n - has very tiresome syntax for skipping fields and by default tries to expose all of them which is completely pointless in 95% of my use cases\n\nSo this tiny crate tries to resolve those issues by switching to direct code instrumentation, example:\n\n![example](./img/ex.png)\n\n```rust\nuse anyhow::{anyhow, Context};\nuse tracing::{Level};\nuse tracing_tools::{span, TracingTask, PinnedFut};\nuse tokio::time::{sleep, Duration};\n\ntype Result\u003cT\u003e = anyhow::Result\u003cT\u003e;\n\nstruct Test {\n}\n\nimpl Test {\n    fn drink_coffee(\u0026self, ) -\u003e Result\u003c()\u003e {\n        Err(anyhow!(\"out of coffee\"))\n    }\n\n    fn fn1(\u0026self, n: usize) -\u003e PinnedFut\u003c'_\u003e {\n        TracingTask::new(span!(Level::INFO, n=n, another_field=\"bow wow!\"), async move {\n            sleep(Duration::from_secs(1)).await;\n            Ok(())\n        }).instrument()\n    }\n    fn fn2(\u0026self, n: usize) -\u003e PinnedFut\u003c'_\u003e {\n        TracingTask::new(span!(Level::INFO, n=n, another_field=\"bow wow!\"), async move {\n            Ok(self.drink_coffee().context(\"cannot drink coffee\")?)\n        }).instrument()\n    }\n    fn fn3(\u0026 self, n: usize) -\u003e PinnedFut\u003c'_\u003e {\n        TracingTask::new_short_lived(span!(Level::INFO, n=n, another_field=\"bow wow!\"), async move {\n            Ok(self.drink_coffee().context(\"cannot drink coffee\")?)\n        }).instrument()\n    }\n}\n\nfn configure_tracing() -\u003e Result\u003c()\u003e{\n    let collector = tracing_subscriber::fmt()\n        .with_target(false)\n        .with_max_level(Level::INFO)\n        .finish();\n    tracing::subscriber::set_global_default(collector)?;\n    Ok(())\n}\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c()\u003e {\n    configure_tracing()?;\n    let s = Test {};\n    let _ = s.fn1(1).await;\n    let _ = s.fn2(2).await;\n    let _ = s.fn3(3).await;\n    Ok(())\n}\n```\n\nFeel free to fork ;)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flet4be%2Ftracing-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flet4be%2Ftracing-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flet4be%2Ftracing-tools/lists"}