{"id":49855383,"url":"https://github.com/bmista/ruby-test-tracer","last_synced_at":"2026-05-14T20:01:02.484Z","repository":{"id":59157688,"uuid":"100188042","full_name":"bmista/ruby-test-tracer","owner":"bmista","description":"OpenTracing compatible Tracer implementation to be used in tests in Ruby  ","archived":false,"fork":false,"pushed_at":"2019-06-06T06:03:09.000Z","size":32,"stargazers_count":1,"open_issues_count":3,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-04-08T23:14:38.802Z","etag":null,"topics":["opentracing","rspec","ruby","tests","tracer"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/bmista.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":"2017-08-13T15:59:41.000Z","updated_at":"2023-07-25T14:10:49.000Z","dependencies_parsed_at":"2022-09-13T17:50:55.328Z","dependency_job_id":null,"html_url":"https://github.com/bmista/ruby-test-tracer","commit_stats":null,"previous_names":["bmista/ruby-test-tracer","iaintshine/ruby-test-tracer"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/bmista/ruby-test-tracer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmista%2Fruby-test-tracer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmista%2Fruby-test-tracer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmista%2Fruby-test-tracer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmista%2Fruby-test-tracer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bmista","download_url":"https://codeload.github.com/bmista/ruby-test-tracer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmista%2Fruby-test-tracer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33041204,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-14T02:00:06.663Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["opentracing","rspec","ruby","tests","tracer"],"created_at":"2026-05-14T20:00:24.543Z","updated_at":"2026-05-14T20:01:02.470Z","avatar_url":"https://github.com/bmista.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/iaintshine/ruby-test-tracer.svg?branch=master)](https://travis-ci.org/iaintshine/ruby-test-tracer)\n# Test::Tracer\n\nFully OpenTracing compatible in-memory Tracer implementation which records all the spans, and includes methods which you might find helpful during testing. The tracer is fully agnostic to any testing framework.\n\nThe framework came to alive, because I had a constant need of some kind of \"recording\" tracer that I could use during tests of new instrumentation libraries for OpenTracing like rails-tracer, tracing-logger etc.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'test-tracer'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install test-tracer\n\n## Test::Tracer\n\nIn addition to OT compatible methods `Test::Tracer` provides the following methods:\n\n1. `spans` returns all spans, including those in progress.\n2. `finished_spans` returns only finished spans.\n\nThe tracer plays nicely with other wrapping tracers until your wrapped span, and span context implements `wrapped`\nmethod. The method must return the wrapped item. You can customize the behaviour by implementing `Test::Wrapped::Extractor` and setting `wrapped_span_extractor` and/or `wrapped_span_context_extractor`.\n\n### Usage\n\n```ruby\nrequire \"test-tracer\"\n\ndescribe \"Test::Tracer examples\" do\n  let(:tracer) { Test::Tracer.new }\n\n  context \"when we expect no traces\" do\n    it \"does not have any traces started\" do\n      expect(tracer.spans).to be_empty\n    end\n\n    it \"does not have any traces recorded\" do\n      expect(tracer.finished_spans).to be_empty\n    end\n  end\n\n  context \"when we expect traces to be present\" do\n    it \"does have some traces started\" do\n      expect(tracer.spans).not_to be_empty\n    end\n\n    it \"does have some traces recorded\" do\n      expect(tracer.finished_spans).not_to be_empty\n    end\n  end\n\n  context \"when we expect exactly N traces\" do\n    it \"has N traces started\" do\n      expect(tracer.spans.size).to eq(N)\n    end\n\n    it \"has N traces recorded\" do\n      expect(tracer.finished_spans.size).to eq(N)\n    end\n  end\nend\n```\n\n## Test::Span\n\nIn addition to OT compatible methods `Test::Span` provides the following methods:\n\n1. `tracer` returns the tracer the span was created by.\n1. `in_progress?`, `started?`, `finished?` informs whether the span is in progress, or it's finished.\n2. `start_time` returns when the span was started.\n2. `end_time` returns when the span was finished, or nil if still in progress.\n2. `tags` returns the span's tags.\n2. `logs` returns the span's logs, an array of `Test::Span::LogEntry`s.\n\nThe modification operations e.g. `operation_name=`, `set_tag`, `set_baggage_item` on a span are not allowed after it's finished. It throws `Test::Span::SpanAlreadyFinished` exception. The same with `finish`. The span can be finished only once.\n\n### Usage\n\n```ruby\nrequire \"test-tracer\"\n\ndescribe \"Test::Span examples\" do\n  let(:tracer) { Test::Tracer.new }\n\n  context \"when a new span was started\" do\n    let(:span) { tracer.start_span(\"operation name\", tags: {'component' =\u003e 'ActiveRecord'}) }\n\n    it \"is in progress\" do\n      expect(span.in_progress?).to eq(true) \n    end\n\n    it \"does have the proper name\" do\n      expect(span.operation_name).to eq(\"operation name\")\n    end\n\n    it \"does include standard OT tags\" do\n      expect(span.tags).to include('component' =\u003e 'ActiveRecord')\n    end\n\n    it \"does not have any log entries\" do\n      expect(span.logs).to be_empty\n    end\n  end\n\n  context \"when an event was logged\" do\n    let(:span) do \n      current_span = tracer.start_span(\"operation name\")\n      current_span.log(event: \"exceptional message\", severity: Logger::ERROR, pid: $1)\n      current_span\n    end\n\n    it \"does have some log entries recorded\" do\n      expect(span.logs).not_to be_empty\n    end\n\n    it \"includes all the event attributes\" do\n      log = span.logs.first\n      expect(log.event).to eq(\"exceptional message\")\n      expect(log.fields).to include(severity: Logger::ERROR)\n    end\n  end\n\n  context \"when a span was finished\" do\n    let(:span) { tracer.start_span(\"operation name\").finish }\n\n    it \"is not in progress\" do\n      expect(span.in_progress?).to eq(false)\n    end\n\n    it \"can't be finished twice\" do\n      expect { span.finish }.to raise_error(Test::Span::SpanAlreadyFinished)\n    end\n  end\nend\n```\n\n## Test::SpanContext\n\nContext propagation is fully implemented by the tracer, and is inspired by [Jaeger](http://jaeger.readthedocs.io/en/latest/) and [TraceContext](https://github.com/TraceContext/tracecontext-spec/pull/1/files). In addition to OT compatible methods `Test::SpanContext` provides the following methods:\n\n1. `trace_id` returns the ID of the whole trace forest.\n1. `span_id` returns the ID of the current span.\n2. `parent_span_id` returns the ID of the parent span.\n\n\n### Usage\n\n```ruby\nrequire \"test-tracer\"\n\ndescribe \"Test::SpanContext examples\" do\n  let(:tracer) { Test::Tracer.new }\n\n  context \"when a new span was started as child of root\" do\n    let(:root_context) { tracer.start_span(\"root span\").context } \n    let(:child_context) { tracer.start_span(\"child span\", child_of: root_context).context }\n\n    it \"all have the same trace_id\" do\n      expect(child_context.trace_id).to eq(root_context.trace_id)\n    end\n\n    it \"propagates parent child relationship\" do\n      expect(child_context.parent_span_id).to eq(root_context.span_id)\n    end\n  end\nend\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/iaintshine/ruby-test-tracer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbmista%2Fruby-test-tracer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbmista%2Fruby-test-tracer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbmista%2Fruby-test-tracer/lists"}