{"id":13475082,"url":"https://github.com/tokio-rs/tracing","last_synced_at":"2026-03-13T12:00:51.579Z","repository":{"id":37390910,"uuid":"165289175","full_name":"tokio-rs/tracing","owner":"tokio-rs","description":"Application level tracing for Rust.","archived":false,"fork":false,"pushed_at":"2026-02-13T11:44:12.000Z","size":9272,"stargazers_count":6563,"open_issues_count":813,"forks_count":885,"subscribers_count":50,"default_branch":"main","last_synced_at":"2026-03-08T03:36:07.851Z","etag":null,"topics":["diagnostics","logging","logging-and-metrics","logging-facade","logging-library","rust","rust-lang","tracing"],"latest_commit_sha":null,"homepage":"https://tracing.rs","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/tokio-rs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-01-11T18:17:15.000Z","updated_at":"2026-03-05T20:05:07.000Z","dependencies_parsed_at":"2025-12-24T00:00:58.780Z","dependency_job_id":null,"html_url":"https://github.com/tokio-rs/tracing","commit_stats":{"total_commits":1404,"total_committers":307,"mean_commits":"4.5732899022801305","dds":0.5128205128205128,"last_synced_commit":"91fedc1f45d0d4eaafb46917d57fe0e8b8b467cb"},"previous_names":[],"tags_count":243,"template":false,"template_full_name":null,"purl":"pkg:github/tokio-rs/tracing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokio-rs%2Ftracing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokio-rs%2Ftracing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokio-rs%2Ftracing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokio-rs%2Ftracing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tokio-rs","download_url":"https://codeload.github.com/tokio-rs/tracing/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokio-rs%2Ftracing/sbom","scorecard":{"id":891527,"data":{"date":"2025-08-11","repo":{"name":"github.com/tokio-rs/tracing","commit":"f71cebe41e4c12735b1d19ca804428d4ff7d905d"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":6.5,"checks":[{"name":"Maintained","score":10,"reason":"30 commit(s) and 5 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Security-Policy","score":9,"reason":"security policy file detected","details":["Info: security policy file detected: SECURITY.md:1","Info: Found linked content: SECURITY.md:1","Warn: One or no descriptive hints of disclosure, vulnerability, and/or timelines in security policy","Info: Found text in security policy: SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":10,"reason":"all changesets reviewed","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/CI.yml:1","Warn: no topLevel permission defined: .github/workflows/audit.yml:1","Warn: no topLevel permission defined: .github/workflows/release.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:271: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:273: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:278: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:255: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:256: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:288: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:289: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:49: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:50: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:61: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:62: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:66: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:91: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:92: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:94: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:149: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:151: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:153: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:157: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:159: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:213: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:215: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI.yml:219: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/CI.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/audit.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/audit.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/audit.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/audit.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/release.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/tokio-rs/tracing/release.yml/main?enable=pin","Info:   0 out of  11 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of  18 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 30 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-24T12:01:11.320Z","repository_id":37390910,"created_at":"2025-08-24T12:01:11.320Z","updated_at":"2025-08-24T12:01:11.320Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30248497,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T05:41:50.788Z","status":"ssl_error","status_checked_at":"2026-03-08T05:41:39.075Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["diagnostics","logging","logging-and-metrics","logging-facade","logging-library","rust","rust-lang","tracing"],"created_at":"2024-07-31T16:01:17.234Z","updated_at":"2026-03-13T12:00:51.572Z","avatar_url":"https://github.com/tokio-rs.png","language":"Rust","funding_links":[],"categories":["Rust","Libraries","库 Libraries","后端开发框架及项目","rust","虚拟化"],"sub_categories":["Logging","日志记录 Logging","管理面板","日志"],"readme":"![Tracing — Structured, application-level diagnostics][splash]\n\n[splash]: https://raw.githubusercontent.com/tokio-rs/tracing/main/assets/splash.svg\n\n[![Crates.io][crates-badge]][crates-url]\n[![Documentation][docs-badge]][docs-url]\n[![Documentation (v0.2.x)][docs-v0.2.x-badge]][docs-v0.2.x-url]\n[![MIT licensed][mit-badge]][mit-url]\n[![Build Status][actions-badge]][actions-url]\n[![Discord chat][discord-badge]][discord-url]\n\n[crates-badge]: https://img.shields.io/crates/v/tracing.svg\n[crates-url]: https://crates.io/crates/tracing\n[docs-badge]: https://docs.rs/tracing/badge.svg\n[docs-url]: https://docs.rs/tracing\n[docs-v0.2.x-badge]: https://img.shields.io/badge/docs-v0.2.x-blue\n[docs-v0.2.x-url]: https://tracing.rs\n[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg\n[mit-url]: LICENSE\n[actions-badge]: https://github.com/tokio-rs/tracing/workflows/CI/badge.svg\n[actions-url]: https://github.com/tokio-rs/tracing/actions?query=workflow%3ACI\n[discord-badge]: https://img.shields.io/discord/500028886025895936?logo=discord\u0026label=discord\u0026logoColor=white\n[discord-url]: https://discord.gg/EeF3cQw\n\n[Website](https://tokio.rs) |\n[Chat](https://discord.gg/EeF3cQw)\n\n## Overview\n\n`tracing` is a framework for instrumenting Rust programs to collect\nstructured, event-based diagnostic information. `tracing` is maintained by the\nTokio project, but does _not_ require the `tokio` runtime to be used.\n\n### Branch set-up\n\n- [`main`](https://github.com/tokio-rs/tracing/tree/main) - Default branch, crates.io releases are done from this branch. This was previously the\n  `v0.1.x` branch.\n- [`v0.2.x`](https://github.com/tokio-rs/tracing/tree/v0.2.x) - Branch containing the as-yet unreleased 0.2 version of `tracing-core`, `tracing`, and\n  all the other tracing crates that depend on these versions. This was previously the `master`\n  branch.\n\n## Usage\n\n### In Applications\n\nIn order to record trace events, executables have to use a `Subscriber`\nimplementation compatible with `tracing`. A `Subscriber` implements a way of\ncollecting trace data, such as by logging it to standard output.\n[`tracing-subscriber`][tracing-subscriber-docs]'s [`fmt` module][fmt] provides\na subscriber for logging traces with reasonable defaults. Additionally,\n`tracing-subscriber` is able to consume messages emitted by `log`-instrumented\nlibraries and modules.\n\nTo use `tracing-subscriber`, add the following to your `Cargo.toml`:\n\n```toml\n[dependencies]\ntracing = \"0.1\"\ntracing-subscriber = \"0.3\"\n```\n\nThen create and install a `Subscriber`, for example using [`init()`]:\n\n```rust\nuse tracing::info;\nuse tracing_subscriber;\n\nfn main() {\n    // install global subscriber configured based on RUST_LOG envvar.\n    tracing_subscriber::fmt::init();\n\n    let number_of_yaks = 3;\n    // this creates a new event, outside of any spans.\n    info!(number_of_yaks, \"preparing to shave yaks\");\n\n    let number_shaved = yak_shave::shave_all(number_of_yaks);\n    info!(\n        all_yaks_shaved = number_shaved == number_of_yaks,\n        \"yak shaving completed.\"\n    );\n}\n```\n\nUsing `init()` calls [`set_global_default()`] so this subscriber will be used\nas the default in all threads for the remainder of the duration of the\nprogram, similar to how loggers work in the `log` crate.\n\n[tracing-subscriber-docs]: https://docs.rs/tracing-subscriber/\n[fmt]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/index.html\n[`set_global_default`]: https://docs.rs/tracing/latest/tracing/subscriber/fn.set_global_default.html\n\n\nFor more control, a subscriber can be built in stages and not set globally,\nbut instead used to locally override the default subscriber. For example:\n\n```rust\nuse tracing::{info, Level};\nuse tracing_subscriber;\n\nfn main() {\n    let subscriber = tracing_subscriber::fmt()\n        // filter spans/events with level TRACE or higher.\n        .with_max_level(Level::TRACE)\n        // build but do not install the subscriber.\n        .finish();\n\n    tracing::subscriber::with_default(subscriber, || {\n        info!(\"This will be logged to stdout\");\n    });\n    info!(\"This will _not_ be logged to stdout\");\n}\n```\n\nAny trace events generated outside the context of a subscriber will not be collected.\n\nThis approach allows trace data to be collected by multiple subscribers\nwithin different contexts in the program. Note that the override only applies to the\ncurrently executing thread; other threads will not see the change from with_default.\n\nOnce a subscriber has been set, instrumentation points may be added to the\nexecutable using the `tracing` crate's macros.\n\n[`tracing-subscriber`]: https://docs.rs/tracing-subscriber/\n[fmt]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/index.html\n[`init()`]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/fn.init.html\n[`set_global_default()`]: https://docs.rs/tracing/latest/tracing/subscriber/fn.set_global_default.html\n\n### In Libraries\n\nLibraries should only rely on the `tracing` crate and use the provided macros\nand types to collect whatever information might be useful to downstream consumers.\n\n```rust\nuse std::{error::Error, io};\nuse tracing::{debug, error, info, span, warn, Level};\n\n// the `#[tracing::instrument]` attribute creates and enters a span\n// every time the instrumented function is called. The span is named after the\n// function or method. Parameters passed to the function are recorded as fields.\n#[tracing::instrument]\npub fn shave(yak: usize) -\u003e Result\u003c(), Box\u003cdyn Error + 'static\u003e\u003e {\n    // this creates an event at the DEBUG level with two fields:\n    // - `excitement`, with the key \"excitement\" and the value \"yay!\"\n    // - `message`, with the key \"message\" and the value \"hello! I'm gonna shave a yak.\"\n    //\n    // unlike other fields, `message`'s shorthand initialization is just the string itself.\n    debug!(excitement = \"yay!\", \"hello! I'm gonna shave a yak.\");\n    if yak == 3 {\n        warn!(\"could not locate yak!\");\n        // note that this is intended to demonstrate `tracing`'s features, not idiomatic\n        // error handling! in a library or application, you should consider returning\n        // a dedicated `YakError`. libraries like snafu or thiserror make this easy.\n        return Err(io::Error::new(io::ErrorKind::Other, \"shaving yak failed!\").into());\n    } else {\n        debug!(\"yak shaved successfully\");\n    }\n    Ok(())\n}\n\npub fn shave_all(yaks: usize) -\u003e usize {\n    // Constructs a new span named \"shaving_yaks\" at the TRACE level,\n    // and a field whose key is \"yaks\". This is equivalent to writing:\n    //\n    // let span = span!(Level::TRACE, \"shaving_yaks\", yaks = yaks);\n    //\n    // local variables (`yaks`) can be used as field values\n    // without an assignment, similar to struct initializers.\n    let span = span!(Level::TRACE, \"shaving_yaks\", yaks);\n    let _enter = span.enter();\n\n    info!(\"shaving yaks\");\n\n    let mut yaks_shaved = 0;\n    for yak in 1..=yaks {\n        let res = shave(yak);\n        debug!(yak, shaved = res.is_ok());\n\n        if let Err(ref error) = res {\n            // Like spans, events can also use the field initialization shorthand.\n            // In this instance, `yak` is the field being initialized.\n            error!(yak, error = error.as_ref(), \"failed to shave yak!\");\n        } else {\n            yaks_shaved += 1;\n        }\n        debug!(yaks_shaved);\n    }\n\n    yaks_shaved\n}\n```\n\n```toml\n[dependencies]\ntracing = \"0.1\"\n```\n\nNote: Libraries should *NOT* install a subscriber by using a method that calls\n[`set_global_default()`], as this will cause conflicts when executables try to\nset the default later.\n\n### In Asynchronous Code\n\nTo trace `async fn`s, the preferred method is using the [`#[instrument]`][instrument] attribute:\n\n```rust\nuse tracing::{info, instrument};\nuse tokio::{io::AsyncWriteExt, net::TcpStream};\nuse std::io;\n\n#[instrument]\nasync fn write(stream: \u0026mut TcpStream) -\u003e io::Result\u003cusize\u003e {\n    let result = stream.write(b\"hello world\\n\").await;\n    info!(\"wrote to stream; success={:?}\", result.is_ok());\n    result\n}\n```\n\nSpecial handling is needed for the general case of code using\n[`std::future::Future`][std-future] or blocks with `async`/`await`, as the\nfollowing example _will not_ work:\n\n```rust\nasync {\n    let _s = span.enter();\n    // ...\n}\n```\n\nThe span guard `_s` will not exit until the future generated by the `async` block is complete.\nSince futures and spans can be entered and exited _multiple_ times without them completing,\nthe span remains entered for as long as the future exists, rather than being entered only when\nit is polled, leading to very confusing and incorrect output.\nFor more details, see [the documentation on closing spans][closing].\n\nThis problem can be solved using the [`Future::instrument`] combinator:\n\n```rust\nuse tracing::Instrument;\n\nlet my_future = async {\n    // ...\n};\n\nmy_future\n    .instrument(tracing::info_span!(\"my_future\"))\n    .await\n```\n\n`Future::instrument` attaches a span to the future, ensuring that the span's lifetime\nis as long as the future's.\n\nUnder the hood, the [`#[instrument]`][instrument] macro performs the same explicit span\nattachment that `Future::instrument` does.\n\n[std-future]: https://doc.rust-lang.org/stable/std/future/trait.Future.html\n[closing]: https://docs.rs/tracing/latest/tracing/span/index.html#closing-spans\n[`Future::instrument`]: https://docs.rs/tracing/latest/tracing/trait.Instrument.html#method.instrument\n[instrument]: https://docs.rs/tracing/latest/tracing/attr.instrument.html\n\n## Supported Rust Versions\n\nTracing is built against the latest stable release. The minimum supported\nversion is 1.65. The current Tracing version is not guaranteed to build on Rust\nversions earlier than the minimum supported version.\n\nTracing follows the same compiler support policies as the rest of the Tokio\nproject. The current stable Rust compiler and the three most recent minor\nversions before it will always be supported. For example, if the current stable\ncompiler version is 1.69, the minimum supported version will not be increased\npast 1.66, three minor versions prior. Increasing the minimum supported compiler\nversion is not considered a semver breaking change as long as doing so complies\nwith this policy.\n\n## Getting Help\n\nFirst, see if the answer to your question can be found in the API documentation.\nIf the answer is not there, there is an active community in\nthe [Tracing Discord channel][chat]. We would be happy to try to answer your\nquestion. Last, if that doesn't work, try opening an [issue] with the question.\n\n[chat]: https://discord.gg/EeF3cQw\n[issue]: https://github.com/tokio-rs/tracing/issues/new\n\n## Contributing\n\n:balloon: Thanks for your help improving the project! We are so happy to have\nyou! We have a [contributing guide][guide] to help you get involved in the Tracing\nproject.\n\n[guide]: CONTRIBUTING.md\n\n## Project layout\n\nThe [`tracing`] crate contains the primary _instrumentation_ API, used for\ninstrumenting libraries and applications to emit trace data. The [`tracing-core`]\ncrate contains the _core_ API primitives on which the rest of `tracing` is\ninstrumented. Authors of trace subscribers may depend on `tracing-core`, which\nguarantees a higher level of stability.\n\nAdditionally, this repository contains several compatibility and utility\nlibraries built on top of `tracing`. Some of these crates are in a pre-release\nstate, and are less stable than the `tracing` and `tracing-core` crates.\n\nThe crates included as part of Tracing are:\n\n* [`tracing-futures`]: Utilities for instrumenting `futures`.\n  ([crates.io][fut-crates]|[docs][fut-docs])\n\n* [`tracing-macros`]: Experimental macros for emitting trace events (unstable).\n\n* [`tracing-attributes`]: Procedural macro attributes for automatically\n    instrumenting functions. ([crates.io][attr-crates]|[docs][attr-docs])\n\n* [`tracing-log`]: Compatibility with the `log` crate (unstable).\n\n* [`tracing-serde`]: A compatibility layer for serializing trace data with\n    `serde` (unstable).\n\n* [`tracing-subscriber`]: Subscriber implementations, and utilities for\n  implementing and composing `Subscriber`s.\n  ([crates.io][sub-crates]|[docs][sub-docs])\n\n* [`tracing-tower`]: Compatibility with the `tower` ecosystem (unstable).\n\n* [`tracing-appender`]: Utilities for outputting tracing data, including a file appender\n   and non-blocking writer. ([crates.io][app-crates]|[docs][app-docs])\n\n* [`tracing-error`]: Provides `SpanTrace`, a type for instrumenting errors with\n  tracing spans. ([crates.io][err-crates]|[docs][err-docs])\n\n* [`tracing-flame`]: Provides a layer for generating flame graphs based on\n  tracing span entry / exit events. ([crates.io][flame-crates]|[docs][flame-docs])\n\n* [`tracing-journald`]: Provides a layer for recording events to the\n  Linux `journald` service, preserving structured data. ([crates.io][jour-crates]|[docs][jour-docs])\n\n[`tracing`]: tracing\n[`tracing-core`]: tracing-core\n[`tracing-futures`]: tracing-futures\n[`tracing-macros`]: tracing-macros\n[`tracing-attributes`]: tracing-attributes\n[`tracing-log`]: tracing-log\n[`tracing-serde`]: tracing-serde\n[`tracing-subscriber`]: tracing-subscriber\n[`tracing-tower`]: tracing-tower\n[`tracing-appender`]: tracing-appender\n[`tracing-error`]: tracing-error\n[`tracing-flame`]: tracing-flame\n[`tracing-journald`]: tracing-journald\n\n[fut-crates]: https://crates.io/crates/tracing-futures\n[fut-docs]: https://docs.rs/tracing-futures\n\n[attr-crates]: https://crates.io/crates/tracing-attributes\n[attr-docs]: https://docs.rs/tracing-attributes\n\n[sub-crates]: https://crates.io/crates/tracing-subscriber\n[sub-docs]: https://docs.rs/tracing-subscriber\n\n[otel-crates]: https://crates.io/crates/tracing-opentelemetry\n[otel-docs]: https://docs.rs/tracing-opentelemetry\n[OpenTelemetry]: https://opentelemetry.io/\n\n[app-crates]: https://crates.io/crates/tracing-appender\n[app-docs]: https://docs.rs/tracing-appender\n\n[err-crates]: https://crates.io/crates/tracing-error\n[err-docs]: https://docs.rs/tracing-error\n\n[flame-crates]: https://crates.io/crates/tracing-flame\n[flame-docs]: https://docs.rs/tracing-flame\n\n[jour-crates]: https://crates.io/crates/tracing-journald\n[jour-docs]: https://docs.rs/tracing-journald\n\n## Related Crates\n\nIn addition to this repository, here are also several third-party crates which\nare not maintained by the `tokio` project. These include:\n\n- [`tracing-timing`] implements inter-event timing metrics on top of `tracing`.\n  It provides a subscriber that records the time elapsed between pairs of\n  `tracing` events and generates histograms.\n- [`tracing-honeycomb`] Provides a layer that reports traces spanning multiple machines to [honeycomb.io]. Backed by [`tracing-distributed`].\n- [`tracing-distributed`] Provides a generic implementation of a layer that reports traces spanning multiple machines to some backend.\n- [`tracing-actix-web`] provides `tracing` integration for the `actix-web` web framework.\n- [`tracing-actix`] provides `tracing` integration for the `actix` actor\n  framework.\n- [`axum-insights`] provides `tracing` integration and Application insights export for the `axum` web framework.\n- [`tracing-gelf`] implements a subscriber for exporting traces in Graylog\n  GELF format.\n- [`tracing-coz`] provides integration with the [coz] causal profiler\n  (Linux-only).\n- [`tracing-bunyan-formatter`] provides a layer implementation that reports events and spans in [bunyan] format, enriched with timing information.\n- [`tide-tracing`] provides a [tide] middleware to trace all incoming requests and responses.\n- [`color-spantrace`] provides a formatter for rendering span traces in the\n  style of `color-backtrace`\n- [`color-eyre`] provides customized panic and eyre report handlers for\n  `eyre::Report` for capturing span traces and backtraces with new errors and\n  pretty printing them.\n- [`spandoc`] provides a proc macro for constructing spans from doc comments\n  _inside_ of functions.\n- [`tracing-wasm`] provides a `Subscriber`/`Layer` implementation that reports\n  events and spans via browser `console.log` and [User Timing API (`window.performance`)].\n- [`tracing-web`] provides a layer implementation of level-aware logging of events\n  to web browsers' `console.*` and span events to the [User Timing API (`window.performance`)].\n- [`test-log`] takes care of initializing `tracing` for tests, based on\n  environment variables with an `env_logger` compatible syntax.\n- [`tracing-unwrap`] provides convenience methods to report failed unwraps on `Result` or `Option` types to a `Subscriber`.\n- [`diesel-tracing`] provides integration with [`diesel`] database connections.\n- [`tracing-tracy`] provides a way to collect [Tracy] profiles in instrumented\n  applications.\n- [`tracing-elastic-apm`] provides a layer for reporting traces to [Elastic APM].\n- [`tracing-etw`] provides a layer for emitting Windows [ETW] events.\n- [`sentry-tracing`] provides a layer for reporting events and traces to [Sentry].\n- [`tracing-forest`] provides a subscriber that preserves contextual coherence by\n  grouping together logs from the same spans during writing.\n- [`tracing-loki`] provides a layer for shipping logs to [Grafana Loki].\n- [`tracing-logfmt`] provides a layer that formats events and spans into the logfmt format.\n- [`tracing-chrome`] provides a layer that exports trace data that can be viewed in `chrome://tracing`.\n- [`reqwest-tracing`] provides a middleware to trace [`reqwest`] HTTP requests.\n- [`tracing-cloudwatch`] provides a layer that sends events to AWS CloudWatch Logs.\n- [`tracing-subscriber-reload-arcswap`] provides a lock-free alternative to `tracing_subscriber::reload::Layer` using `arc-swap`.\n- [`clippy-tracing`] provides a tool to add, remove and check for `tracing::instrument`.\n\n(if you're the maintainer of a `tracing` ecosystem crate not in this list,\nplease let us know!)\n\n[`tracing-timing`]: https://crates.io/crates/tracing-timing\n[`tracing-honeycomb`]: https://crates.io/crates/tracing-honeycomb\n[`tracing-distributed`]: https://crates.io/crates/tracing-distributed\n[honeycomb.io]: https://www.honeycomb.io/\n[`tracing-actix`]: https://crates.io/crates/tracing-actix\n[`tracing-actix-web`]: https://crates.io/crates/tracing-actix-web\n[`axum-insights`]: https://crates.io/crates/axum-insights\n[`tracing-gelf`]: https://crates.io/crates/tracing-gelf\n[`tracing-coz`]: https://crates.io/crates/tracing-coz\n[coz]: https://github.com/plasma-umass/coz\n[`tracing-bunyan-formatter`]: https://crates.io/crates/tracing-bunyan-formatter\n[`tide-tracing`]: https://crates.io/crates/tide-tracing\n[tide]: https://crates.io/crates/tide\n[bunyan]: https://github.com/trentm/node-bunyan\n[`color-spantrace`]: https://docs.rs/color-spantrace\n[`color-eyre`]: https://docs.rs/color-eyre\n[`spandoc`]: https://docs.rs/spandoc\n[`tracing-wasm`]: https://docs.rs/tracing-wasm\n[`tracing-web`]: https://crates.io/crates/tracing-web\n[`test-log`]: https://crates.io/crates/test-log\n[User Timing API (`window.performance`)]: https://developer.mozilla.org/en-US/docs/Web/API/User_Timing_API\n[`tracing-unwrap`]: https://docs.rs/tracing-unwrap\n[`diesel`]: https://crates.io/crates/diesel\n[`diesel-tracing`]: https://crates.io/crates/diesel-tracing\n[`tracing-tracy`]: https://crates.io/crates/tracing-tracy\n[Tracy]: https://github.com/wolfpld/tracy\n[`tracing-elastic-apm`]: https://crates.io/crates/tracing-elastic-apm\n[Elastic APM]: https://www.elastic.co/apm\n[`tracing-etw`]: https://github.com/microsoft/rust_win_etw/tree/main/win_etw_tracing\n[ETW]: https://docs.microsoft.com/en-us/windows/win32/etw/about-event-tracing\n[`sentry-tracing`]: https://crates.io/crates/sentry-tracing\n[Sentry]: https://sentry.io/welcome/\n[`tracing-forest`]: https://crates.io/crates/tracing-forest\n[`tracing-loki`]: https://crates.io/crates/tracing-loki\n[Grafana Loki]: https://grafana.com/oss/loki/\n[`tracing-logfmt`]: https://crates.io/crates/tracing-logfmt\n[`tracing-chrome`]: https://crates.io/crates/tracing-chrome\n[`reqwest-tracing`]: https://crates.io/crates/reqwest-tracing\n[`reqwest`]: https://crates.io/crates/reqwest\n[`tracing-cloudwatch`]: https://crates.io/crates/tracing-cloudwatch\n[`tracing-subscriber-reload-arcswap`]: https://crates.io/crates/tracing-subscriber-reload-arcswap\n[`clippy-tracing`]: https://crates.io/crates/clippy-tracing\n\n**Note:** that some of the ecosystem crates are currently unreleased and\nundergoing active development. They may be less stable than `tracing` and\n`tracing-core`.\n\n## External Resources\n\nThis is a list of links to blog posts, conference talks, and tutorials about\nTracing.\n\n#### Blog Posts\n\n* [Diagnostics with Tracing][tokio-blog-2019-08] on the Tokio blog, August 2019\n* [Production-Grade Logging in Rust Applications][production-logging-2020], November 2020\n* [Custom Logging in Rust using `tracing` and `tracing-subscriber`, part 1][custom-logging-part-1] and [part 2][custom-logging-part-2], October 2021\n* [Instrumenting Axum projects][detsys-blog-2023-08], August 2023\n\n[tokio-blog-2019-08]: https://tokio.rs/blog/2019-08-tracing/\n[detsys-blog-2023-08]: https://determinate.systems/posts/instrumenting-axum\n\n#### Talks\n\n* [Bay Area Rust Meetup talk and Q\u0026A][bay-rust-2019-03], March 2019\n* [RustConf 2019 talk][rust-conf-2019-08-video] and [slides][rust-conf-2019-08-slides], August 2019\n* [Are we observable yet? @ RustyDays talk][rusty-days-2020-08-video] and [slides][rusty-days-2020-08-slides], August 2020\n* [Crabs with instruments!][tremorcon-2021-09], September 2021\n* [Decrusting the tracing crate by Jon Gjengset][decrusting-tracing-2024-02], February 2024\n\n[bay-rust-2019-03]: https://www.youtube.com/watch?v=j_kXRg3zlec\n[rust-conf-2019-08-video]: https://www.youtube.com/watch?v=JjItsfqFIdo\n[rust-conf-2019-08-slides]: https://www.elizas.website/slides/rustconf-8-2019.pdf\n[rusty-days-2020-08-video]: https://youtu.be/HtKnLiFwHJM\n[rusty-days-2020-08-slides]: https://docs.google.com/presentation/d/1zrxJs7fJgQ29bKfnAll1bYTo9cYZxsCZUwDDtyp5Fak/edit?usp=sharing\n[production-logging-2020]: https://medium.com/better-programming/production-grade-logging-in-rust-applications-2c7fffd108a6\n[custom-logging-part-1]: https://burgers.io/custom-logging-in-rust-using-tracing\n[custom-logging-part-2]: https://burgers.io/custom-logging-in-rust-using-tracing-part-2\n[tremorcon-2021-09]: https://www.youtube.com/watch?v=ZC7fyqshun8\n[decrusting-tracing-2024-02]: https://www.youtube.com/watch?v=21rtHinFA40\n\nHelp us expand this list! If you've written or spoken about Tracing, or\nknow of resources that aren't listed, please open a pull request adding them.\n\n## License\n\nThis project is licensed under the [MIT license](LICENSE).\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in Tracing by you, shall be licensed as MIT, without any additional\nterms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftokio-rs%2Ftracing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftokio-rs%2Ftracing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftokio-rs%2Ftracing/lists"}