{"id":15554171,"url":"https://github.com/ajitsing/rails_distributed_tracing","last_synced_at":"2025-10-08T18:19:20.279Z","repository":{"id":56890511,"uuid":"145069546","full_name":"ajitsing/rails_distributed_tracing","owner":"ajitsing","description":"Distributed tracing for rails microservices","archived":false,"fork":false,"pushed_at":"2019-05-05T10:59:39.000Z","size":24,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-07T13:05:22.746Z","etag":null,"topics":["distributed-tracing","microservices","ruby","ruby-on-rails","rubygem"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/ajitsing.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":"2018-08-17T03:56:10.000Z","updated_at":"2020-11-20T14:11:40.000Z","dependencies_parsed_at":"2022-08-21T00:50:35.884Z","dependency_job_id":null,"html_url":"https://github.com/ajitsing/rails_distributed_tracing","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajitsing%2Frails_distributed_tracing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajitsing%2Frails_distributed_tracing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajitsing%2Frails_distributed_tracing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajitsing%2Frails_distributed_tracing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajitsing","download_url":"https://codeload.github.com/ajitsing/rails_distributed_tracing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252883213,"owners_count":21819160,"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":["distributed-tracing","microservices","ruby","ruby-on-rails","rubygem"],"created_at":"2024-10-02T14:51:06.620Z","updated_at":"2025-10-08T18:19:15.223Z","avatar_url":"https://github.com/ajitsing.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rails_distributed_tracing\nDistributed tracing for rails microservices\n\n[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/ajitsing/rails_distributed_tracing/graphs/commit-activity)\n[![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=102)](https://opensource.org/licenses/MIT)\n[![Gem Version](https://badge.fury.io/rb/rails_distributed_tracing.svg)](https://badge.fury.io/rb/rails_distributed_tracing)\n[![HitCount](http://hits.dwyl.io/ajitsing/rails_distributed_tracing.svg)](http://hits.dwyl.io/ajitsing/rails_distributed_tracing)\n![Gem Downloads](http://ruby-gem-downloads-badge.herokuapp.com/rails_distributed_tracing?type=total)\n[![Build Status](https://travis-ci.org/ajitsing/rails_distributed_tracing.svg?branch=master)](https://travis-ci.org/ajitsing/rails_distributed_tracing)\n[![Twitter Follow](https://img.shields.io/twitter/follow/Ajit5ingh.svg?style=social)](https://twitter.com/Ajit5ingh)\n\n## Installation\nAdd this line to Gemfile of your microservice:\n```ruby\ngem 'rails_distributed_tracing'\n```\n\n## Configuration\nAdd request id tag to log tags in `application.rb`. This config will make sure that the logs are tagged with a request id.\nIf the service is origin service, `DistributedTracing.request_id_tag` will create a new request id else it will reuse the request id passed from the origin service.\n\n```ruby\nrequire 'rails_distributed_tracing'\n\nclass Application \u003c Rails::Application\n  config.log_tags = [DistributedTracing.log_tag]\nend\n```\n\n## Passing request id tag to downstream services\nTo make the distributed tracing work every service has to the request id to all its downstream services. \nFor example lets assume that we have 3 services:   \n`OriginService`, `SecondService` and `ThirdService` .  \n\nNow a request comes to `OriginService`, the above config will create a new request_id for that request.\nWhen `OriginService` makes a request to `SecondService` it should pass the same requst_id to it,\nso that the request can be traced. The same should happen when `SecondService` calls the `ThirdService`.   \n\nThe bottomline is whenever there is a communication between two services, \nsource service should always pass the request id to the destination service.\n\n## How to pass request id tag to downstream services\nWhen a request id is generated `rails_distributed_tracing` holds that request id till the request returns the response. You can access that request_id anywhere in your application code with the help of below APIs.\n\n```ruby\nDistributedTracing.trace_id\n#=\u003e '8ed7e37b-94e8-4875-afb4-6b4cf1783817'\n```\n\n## Sidekiq\n```ruby\nSidekiq.configure_server do |config|\n  config.server_middleware do |chain|\n    chain.add DistributedTracing::SidekiqMiddleware::Server\n  end\nend\n\nSidekiq.configure_client do |config|\n  config.client_middleware do |chain|\n    chain.add DistributedTracing::SidekiqMiddleware::Client\n  end\nend\n```\n\n## Faraday\n```ruby\nconnection = Faraday.new(\"http://google.com/\") do |conn|\n  conn.use DistributedTracing::FaradayMiddleware\nend\n```\n\n## Important Note\nMake sure that faraday and sidekiq gems are loaded before `rails_distributed_tracing`. Otherwise rails_distributed_tracing will not load the faraday and sidekiq related classes.   \n\nTo ensure that `sidekiq` and `faraday` are loaded before `rails_distributed_tracing`, add sidekiq and faraday gem before rails_distributed_tracing in Gemfile. So that when rails load the Gemfile, sidekiq and faraday loaded before rails_distributed_tracing gem.\n\n## Other\nAdd below headers to the outgoing request headers.\n```ruby\n{DistributedTracing::TRACE_ID =\u003e DistributedTracing.trace_id}\n```\n\n## Contributing\n\n1. Fork it ( https://github.com/ajitsing/rails_distributed_tracing/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n\n## License\n```LICENSE\nMIT License\n\nCopyright (c) 2018 Ajit Singh\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajitsing%2Frails_distributed_tracing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajitsing%2Frails_distributed_tracing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajitsing%2Frails_distributed_tracing/lists"}