{"id":28589632,"url":"https://github.com/fast/fastrace-axum","last_synced_at":"2025-06-11T08:10:48.208Z","repository":{"id":284748641,"uuid":"955891344","full_name":"fast/fastrace-axum","owner":"fast","description":"A axum instrument for propagating trace context for fastrace.","archived":false,"fork":false,"pushed_at":"2025-03-31T11:00:02.000Z","size":29,"stargazers_count":6,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-11T04:11:13.100Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fast.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-27T11:11:28.000Z","updated_at":"2025-04-22T19:49:19.000Z","dependencies_parsed_at":"2025-03-27T13:51:09.172Z","dependency_job_id":null,"html_url":"https://github.com/fast/fastrace-axum","commit_stats":null,"previous_names":["fast/fastrace-axum"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Ffastrace-axum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Ffastrace-axum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Ffastrace-axum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Ffastrace-axum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fast","download_url":"https://codeload.github.com/fast/fastrace-axum/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Ffastrace-axum/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259227958,"owners_count":22824904,"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-06-11T08:10:43.823Z","updated_at":"2025-06-11T08:10:48.200Z","avatar_url":"https://github.com/fast.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastrace-axum\n\n[![Crates.io](https://img.shields.io/crates/v/fastrace-axum.svg?style=flat-square\u0026logo=rust)](https://crates.io/crates/fastrace-axum)\n[![Documentation](https://img.shields.io/docsrs/fastrace-axum?style=flat-square\u0026logo=rust)](https://docs.rs/fastrace-axum/)\n[![MSRV 1.80.0](https://img.shields.io/badge/MSRV-1.80.0-green?style=flat-square\u0026logo=rust)](https://www.whatrustisit.com)\n[![CI Status](https://img.shields.io/github/actions/workflow/status/fast/fastrace-axum/ci.yml?style=flat-square\u0026logo=github)](https://github.com/fast/fastrace-axum/actions)\n[![License](https://img.shields.io/crates/l/fastrace-axum?style=flat-square)](https://github.com/fast/fastrace-axum/blob/main/LICENSE)\n\n`fastrace-axum` is a middleware library that connects [fastrace](https://crates.io/crates/fastrace), a distributed tracing library, with [axum](https://crates.io/crates/axum), a gRPC framework for Rust. This integration enables seamless trace context propagation across microservice boundaries in gRPC-based applications.\n\n## What is Context Propagation?\n\nContext propagation is a fundamental concept in distributed tracing that enables the correlation of operations spanning multiple services. When a request moves from one service to another, trace context information needs to be passed along, ensuring that all operations are recorded as part of the same trace.\n\n`fastrace-axum` implements the [W3C Trace Context](https://www.w3.org/TR/trace-context/) standard for propagating trace information between services. This ensures compatibility with other tracing systems that follow the same standard.\n\n## Features\n\n- 🔄 **Automatic Context Propagation**: Automatically extract trace context from HTTP requests.\n- 🌉 **Seamless Integration**: Works seamlessly with the `fastrace` library for complete distributed tracing.\n- 📊 **Full Compatibility**: Works with fastrace's collection and reporting capabilities.\n\n## Usage\n\n### Server Integration\n\nAdd `fastrace-axum` to your Cargo.toml:\n\n```toml\n[dependencies]\nfastrace = \"0.7\"\nfastrace-axum = \"0.1\"\n```\n\nApply the `FastraceLayer` to your axum server:\n\n```rust\nuse fastrace::collector::Config;\nuse fastrace::collector::ConsoleReporter;\n\n#[tokio::main]\nasync fn main() {\n    // Configurate fastrace reporter.\n    fastrace::set_reporter(ConsoleReporter, Config::default());\n\n    let app = axum::Router::new()\n        .route(\"/ping\", axum::routing::get(ping))\n        // Add a the FastraceLayer to routes.\n        // The layer extracts trace context from incoming requests.\n        .layer(fastrace_axum::FastraceLayer);\n\n    let listener = tokio::net::TcpListener::bind(\"0.0.0.0:8080\").await.unwrap();\n    axum::serve(listener, app).await.unwrap();\n}\n\n#[fastrace::trace] // Trace individual handlers.\nasync fn ping() -\u003e \u0026'static str {\n    \"pong\"\n}\n\n```\n\n### Client Usage with fastrace-reqwest\n\nTo propagate trace context from clients to your axum service:\n\n```rust\nuse fastrace::prelude::*;\nuse reqwest::Client;\n\n#[fastrace::trace]\nasync fn send_request() {\n    let client = Client::new();\n    let response = client\n        .get(\"http://your-axum-service/endpoint\")\n        .headers(fastrace_reqwest::traceparent_headers()) // Adds traceparent header.\n        .send()\n        .await\n        .unwrap();\n    \n    // Process response...\n}\n```\n\n## Example\n\nCheck out the [examples directory](https://github.com/fast/fastrace-axum/tree/main/example) for a complete ping/pong service example that demonstrates both client and server tracing.\n\nTo run the example:\n\n1. Start the server:\n   ```\n   cargo run --example server\n   ```\n\n3. In another terminal, run the client:\n   ```\n   cargo run --example client\n   ```\n\nBoth applications will output trace information showing the request flow, including the propagated context.\n\n## How It Works\n\n2. When a server receives the request, `FastraceLayer` extracts the trace context from the `traceparent` header and creates a new span as a child of the received context.\n3. If no trace context is provided, the server creates a new root span.\n\nThis process ensures that all operations across services are properly connected in the resulting trace, providing visibility into the entire request lifecycle.\n\n## License\n\nThis project is licensed under the [Apache-2.0](./LICENSE) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffast%2Ffastrace-axum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffast%2Ffastrace-axum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffast%2Ffastrace-axum/lists"}