{"id":23952489,"url":"https://github.com/akesson/tracing-collector","last_synced_at":"2025-07-24T22:05:54.591Z","repository":{"id":65705816,"uuid":"597484384","full_name":"akesson/tracing-collector","owner":"akesson","description":"A tracing subscriber that collects a copy of the traces for use in tests with insta snapshots","archived":false,"fork":false,"pushed_at":"2023-02-06T08:50:22.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-13T00:43:57.013Z","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/akesson.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":"2023-02-04T17:38:48.000Z","updated_at":"2024-07-02T05:26:43.000Z","dependencies_parsed_at":"2023-02-19T05:46:22.137Z","dependency_job_id":null,"html_url":"https://github.com/akesson/tracing-collector","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akesson%2Ftracing-collector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akesson%2Ftracing-collector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akesson%2Ftracing-collector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akesson%2Ftracing-collector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akesson","download_url":"https://codeload.github.com/akesson/tracing-collector/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650419,"owners_count":21139672,"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":"2025-01-06T13:58:51.323Z","updated_at":"2025-04-13T00:44:03.034Z","avatar_url":"https://github.com/akesson.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![crates.io](https://img.shields.io/crates/v/tracing-collector)](https://crates.io/crates/tracing-collector)\n\n# TracingCollector\n\n`TracingCollector` creates a tracing subscriber that collects a copy of all traces into a buffer.\nThese traces can be retrieved by calling its Display implementation, i.e. calling `log.to_string()` or `format!(\"{log}\")`.\nThis is useful for testing with [insta](https://crates.io/crates/insta) snapshots.\n\nIMPORTANT! `TracingCollector` is meant for use when testing. It collects logs into a memory buffer\nwhich keeps growing until it is read, the program exits or it is dropped. This means that if you are using `TracingCollector`\nin production the program will eventually run out of memory.\n\nWhen the `TracingCollector` is dropped, the buffer is emptied and the tracing subscriber is released but\nthe memory equivalent of a Mutex and an empty Vec\u003cu8\u003e is leaked.\n\nWhen reading the traces, they are stripped of ANSI escape codes and prefixed with a `㏒` character. The former allows\nthe use of colored \u0026 formatted terminal output when the test fails or is run with `--nocapture` and the latter\nmakes the insta inline snapshots work since rust's `r###` raw string literals strips leading whitespace. The prefix can be\nchanged or removed using the `set_prefix` and `remove_prefix` methods.\n\n## Example\n\n```rust\n#[test]\nfn test_logs() {\n    let log = TracingCollector::init_debug_level();\n    tracing::info!(\"First log\");\n\n    insta::assert_display_snapshot!(log, @r###\"\n    ㏒   INFO  First log\n        at tests/test.rs:6\n\n    \"###);\n\n    tracing::debug!(\"Second log\");\n    tracing::info!(\"Third log\");\n\n    insta::assert_display_snapshot!(log, @r###\"\n    ㏒  DEBUG  Second log\n        at tests/test.rs:14\n\n      INFO  Third log\n       at tests/test.rs:15\n\n   \"###);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakesson%2Ftracing-collector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakesson%2Ftracing-collector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakesson%2Ftracing-collector/lists"}