{"id":28589611,"url":"https://github.com/fast/fastrace-tonic","last_synced_at":"2025-06-11T08:10:40.464Z","repository":{"id":283100844,"uuid":"950688796","full_name":"fast/fastrace-tonic","owner":"fast","description":"A tonic instrument for propagating trace context for fastrace.","archived":false,"fork":false,"pushed_at":"2025-03-27T10:20:35.000Z","size":47,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-04T05:10:52.039Z","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-18T14:40:24.000Z","updated_at":"2025-03-27T10:20:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"a43125f9-3ffc-42c5-8fbf-c4384ed928bc","html_url":"https://github.com/fast/fastrace-tonic","commit_stats":null,"previous_names":["fast/fastrace-tonic"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Ffastrace-tonic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Ffastrace-tonic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Ffastrace-tonic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Ffastrace-tonic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fast","download_url":"https://codeload.github.com/fast/fastrace-tonic/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Ffastrace-tonic/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:38.454Z","updated_at":"2025-06-11T08:10:40.445Z","avatar_url":"https://github.com/fast.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastrace-tonic\n\n[![Crates.io](https://img.shields.io/crates/v/fastrace-tonic.svg?style=flat-square\u0026logo=rust)](https://crates.io/crates/fastrace-tonic)\n[![Documentation](https://img.shields.io/docsrs/fastrace-tonic?style=flat-square\u0026logo=rust)](https://docs.rs/fastrace-tonic/)\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-tonic/ci.yml?style=flat-square\u0026logo=github)](https://github.com/fast/fastrace-tonic/actions)\n[![License](https://img.shields.io/crates/l/fastrace-tonic?style=flat-square)](https://github.com/fast/fastrace-tonic/blob/main/LICENSE)\n\n`fastrace-tonic` is a middleware library that connects [fastrace](https://crates.io/crates/fastrace), a distributed tracing library, with [tonic](https://crates.io/crates/tonic), 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-tonic` 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 inject trace context into outgoing gRPC 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## Installation\n\nAdd `fastrace-tonic` to your Cargo.toml:\n\n```toml\n[dependencies]\nfastrace = \"0.7\"\nfastrace-tonic = \"0.1\"\n```\n\n### Server Integration\n\nApply the `FastraceServerLayer` to your tonic server:\n\n```rust\nuse fastrace_tonic::FastraceServerLayer;\nuse tonic::transport::Server;\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    // Initialize fastrace reporter.\n    fastrace::set_reporter(ConsoleReporter, Config::default());\n    \n    // Add FastraceServerLayer to your tonic server.\n    Server::builder()\n        .layer(FastraceServerLayer)\n        .add_service(YourServiceServer::new(YourService::default()))\n        .serve(\"[::1]:50051\".parse()?)\n        .await?;\n    \n    fastrace::flush();\n\n    Ok(())\n}\n```\n\n### Client Integration\n\nApply the `FastraceClientLayer` to your tonic client:\n\n```rust\nuse fastrace_tonic::FastraceClientLayer;\nuse tower::ServiceBuilder;\n\nasync fn make_client_call() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    // Create channel with FastraceClientLayer.\n    let channel = tonic::transport::Channel::from_static(\"http://[::1]:50051\")\n        .connect()\n        .await?;\n        \n    let channel = ServiceBuilder::new()\n        .layer(FastraceClientLayer)\n        .service(channel);\n        \n    // Create client with the enhanced channel.\n    let mut client = YourServiceClient::new(channel);\n    \n    // Make calls as usual.\n    let response = client.your_method(Request::new(YourRequest {})).await?;\n    \n    Ok(())\n}\n```\n\n## Example\n\nCheck out the [examples directory](https://github.com/fast/fastrace-tonic/tree/main/example) for a complete ping/pong service example that demonstrates both client and server tracing.\n\nTo run the example:\n\n1. Navigate to the example directory:\n    ```\n    cd example\n    ```\n\n2. Start the server:\n   ```\n   cargo run --bin server\n   ```\n\n3. In another terminal, run the client:\n   ```\n   cargo run --bin client\n   ```\n\nBoth applications will output trace information showing the request flow, including the propagated context.\n\n## How It Works\n\n1. When a client makes a request, `FastraceClientLayer` detects if there's an active trace and adds a `traceparent` HTTP header with the trace context.\n2. When a server receives the request, `FastraceServerLayer` 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-tonic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffast%2Ffastrace-tonic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffast%2Ffastrace-tonic/lists"}