https://github.com/opentracing/opentracing-ruby
OpenTracing API for Ruby
https://github.com/opentracing/opentracing-ruby
Keywords from Contributors
activejob activerecord mvc
Last synced: about 5 hours ago
JSON representation
Repository metadata
OpenTracing API for Ruby
- Host: GitHub
- URL: https://github.com/opentracing/opentracing-ruby
- Owner: opentracing
- License: apache-2.0
- Archived: true
- Created: 2016-11-18T18:21:10.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-09-23T20:40:19.000Z (about 4 years ago)
- Last Synced: 2025-12-05T10:39:43.544Z (7 days ago)
- Language: Ruby
- Homepage: http://opentracing.io
- Size: 101 KB
- Stars: 173
- Watchers: 7
- Forks: 14
- Open Issues: 2
- Releases: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
README.md
OpenTracing API for Ruby
This package is a Ruby platform API for OpenTracing.
Required Reading
In order to understand the Ruby platform API, one must first be familiar with the
OpenTracing project and
terminology more specifically.
Installation
Add this line to your application's Gemfile:
gem 'opentracing'
And then execute:
$ bundle
Or install it yourself as:
$ gem install opentracing
opentracing supports Ruby 2.0+.
Usage
Everyday consumers of this opentracing gem really only need to worry
about a couple of key abstractions: the start_active_span and start_span
methods, the Span and ScopeManager interfaces, and binding a Tracer
at runtime. Here are code snippets demonstrating some important use cases.
Singleton initialization
As early as possible, call
require 'opentracing'
OpenTracing.global_tracer = MyTracerImplementation.new(...)
Where MyTracerImplementation is your tracer. For testing, you can use
the provided OpenTracing::Tracer
Non-Singleton initialization
If you prefer direct control to singletons, manage ownership of the
Tracer implementation explicitly.
Scopes and within-process propagation
For any thread, at most one Span may be "active". Of course there may be many
other Spans involved with the thread which are (a) started, (b) not finished,
and yet (c) not "active": perhaps they are waiting for I/O, blocked on a child
Span, or otherwise off of the critical path.
It's inconvenient to pass an active Span from function to function manually,
so OpenTracing requires that every Tracer contains a ScopeManager that
grants access to the active Span through a Scope. Any Span may be
transferred to another callback or thread, but not Scope.
Accessing the active Span through Scope
# Access to the active span is straightforward.
span = OpenTracing.active_span
if span
span.set_tag('...', '...')
end
# or
scope = OpenTracing.scope_manager.active
if scope
scope.span.set_tag('...', '...')
end
Starting a new Span
The common case starts a Scope that's automatically registered for
intra-process propagation via ScopeManager.
Note that start_active_span('...') automatically finishes the span on
Scope#close (start_active_span('...', finish_on_close: false) does not
finish it, in contrast).
# Automatic activation of the Span.
# By default the active span will be finished when the returned scope is closed.
# This can be controlled by passing finish_on_close parameter to
# start_active_span
scope = OpenTracing.start_active_span('operation_name')
# Do things.
# Block form of start_active_span
# start_active_span optionally accepts a block. If a block is passed to
# start_active_span it will yield the newly created scope. The scope will
# be closed and its associated span will be finished unless
# finish_on_close: false is passed to start_active_span.
OpenTracing.start_active_span('operation_name') do |scope|
# Do things.
end
# Manual activation of the Span.
# Spans can be managed manually. This is equivalent to the more concise examples
# above.
span = OpenTracing.start_span('operation_name')
OpenTracing.scope_manager.activate(span)
scope = OpenTracing.scope_manager.active
# Do things.
# If there is an active Scope, it will act as the parent to any newly started
# Span unless ignore_active_scope: true is passed to start_span or
# start_active_span.
# create a root span, ignoring the currently active scope (if it's set)
scope = OpenTracing.start_active_span('operation_name', ignore_active_scope: true)
# or
span = OpenTracing.start_span('operation_name', ignore_active_scope: true)
# It's possible to create a child Span given an existing parent Span by
# using the child_of option.
parent_scope = OpenTracing.start_active_span('parent_operation, ignore_active_scope: true)
child_scope = OpenTracing.start_active_span('child_operation', child_of: parent_scope.span)
# or
parent_span = OpenTracing.start_span('parent_operation', ignore_active_scope: true)
child_span = OpenTracing.start_span('child_operation', child_of: parent_span)
Serializing to the wire
Using Net::HTTP:
client = Net::HTTP.new("myservice.com")
req = Net::HTTP::Post.new("/")
span = OpenTracing.start_span("my_span")
OpenTracing.inject(span.context, OpenTracing::FORMAT_RACK, req)
res = client.request(req)
#...
Using Faraday middleware:
class TraceMiddleware < Faraday::Middleware
def call(env)
span = OpenTracing.start_span("my_span")
OpenTracing.inject(span.context, OpenTracing::FORMAT_RACK, env)
@app.call(env).on_complete do
span.finish
end
end
end
Deserializing from the wire
The OpenTracing Ruby gem provides a specific Rack header extraction format,
since most Ruby web servers get their HTTP Headers from Rack. Keep in mind that
Rack automatically uppercases all headers and replaces dashes with underscores.
This means that if you use dashes and underscores and case-sensitive baggage,
it will not be possible to discern once Rack has processed it.
class MyRackApp
def call(env)
extracted_ctx = @tracer.extract(OpenTracing::FORMAT_RACK, env)
span = @tracer.start_span("my_app", child_of: extracted_ctx)
span.finish
[200, {}, ["hello"]]
end
end
Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To 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.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/opentracing/opentracing-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
Licensing
Owner metadata
- Name: OpenTracing API
- Login: opentracing
- Email:
- Kind: organization
- Description: Consistent, expressive, vendor-neutral APIs for distributed tracing and context propagation
- Website: http://opentracing.io/
- Location: Earth
- Twitter:
- Company:
- Icon url: https://avatars.githubusercontent.com/u/15482765?v=4
- Repositories: 24
- Last ynced at: 2024-03-25T20:24:55.637Z
- Profile URL: https://github.com/opentracing
GitHub Events
Total
Last Year
Committers metadata
Last synced: 7 days ago
Total Commits: 90
Total Committers: 13
Avg Commits per committer: 6.923
Development Distribution Score (DDS): 0.711
Commits in past year: 0
Committers in past year: 0
Avg Commits per committer in past year: 0.0
Development Distribution Score (DDS) in past year: 0.0
| Name | Commits | |
|---|---|---|
| Matthew Wear | m****r@g****m | 26 |
| Indrek Juhkam | i****k@u****u | 19 |
| Nick Gauthier | n****r@g****m | 12 |
| Derek Haynes | d****s@g****m | 10 |
| Ben Sigelman | b****s@l****m | 9 |
| Peter Giacomo Lombardo | p****o@g****m | 3 |
| EA | e****u@g****m | 3 |
| Alberto Almagro | a****o@g****m | 2 |
| Fabian Franz | f****z@s****t | 2 |
| bhs | b****n | 1 |
| Mehmet Emin INAC | m****c@g****m | 1 |
| Mahito OGURA | e****7@g****m | 1 |
| Andrea Kao | e****s@g****m | 1 |
Committer domains:
Issue and Pull Request metadata
Last synced: 3 months ago
Total issues: 12
Total pull requests: 36
Average time to close issues: 5 months
Average time to close pull requests: 18 days
Total issue authors: 9
Total pull request authors: 15
Average comments per issue: 4.5
Average comments per pull request: 2.33
Merged pull request: 30
Bot issues: 0
Bot pull requests: 0
Past year issues: 0
Past year pull requests: 0
Past year average time to close issues: N/A
Past year average time to close pull requests: N/A
Past year issue authors: 0
Past year pull request authors: 0
Past year average comments per issue: 0
Past year average comments per pull request: 0
Past year merged pull request: 0
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- mwear (2)
- itsderek23 (2)
- ethanjcohen-underarmour (2)
- geo-opensource (1)
- iaintshine (1)
- bhs (1)
- tim37021 (1)
- nightscape (1)
- fabianfrz (1)
Top Pull Request Authors
- mwear (9)
- indrekj (9)
- pglombardo (3)
- itsderek23 (3)
- edithau (2)
- achandras (1)
- albertoalmagro (1)
- eirinikos (1)
- jwarner112 (1)
- bhs (1)
- meinac (1)
- fabianfrz (1)
- inbalg (1)
- ngauthier (1)
- Mahito (1)
Top Issue Labels
- enhancement (2)
- bug (1)
Top Pull Request Labels
- bug (1)
Package metadata
- Total packages: 2
-
Total downloads:
- rubygems: 119,995,978 total
- Total docker downloads: 868,405,892
- Total dependent packages: 73 (may contain duplicates)
- Total dependent repositories: 876 (may contain duplicates)
- Total versions: 24
- Total maintainers: 5
gem.coop: opentracing
OpenTracing Ruby Platform API
- Homepage: https://github.com/opentracing/opentracing-ruby
- Documentation: http://www.rubydoc.info/gems/opentracing/
- Licenses: Apache-2.0
- Latest release: 0.5.0 (published almost 7 years ago)
- Last Synced: 2025-12-09T18:32:34.059Z (2 days ago)
- Versions: 12
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 60,006,551 Total
- Docker Downloads: 434,202,946
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.194%
- Docker downloads count: 0.325%
- Downloads: 0.451%
- Maintainers (5)
rubygems.org: opentracing
OpenTracing Ruby Platform API
- Homepage: https://github.com/opentracing/opentracing-ruby
- Documentation: http://www.rubydoc.info/gems/opentracing/
- Licenses: Apache-2.0
- Latest release: 0.5.0 (published almost 7 years ago)
- Last Synced: 2025-12-07T18:01:06.641Z (4 days ago)
- Versions: 12
- Dependent Packages: 73
- Dependent Repositories: 876
- Downloads: 59,989,427 Total
- Docker Downloads: 434,202,946
-
Rankings:
- Docker downloads count: 0.391%
- Dependent packages count: 0.396%
- Downloads: 0.446%
- Dependent repos count: 1.115%
- Average: 2.203%
- Stargazers count: 4.273%
- Forks count: 6.595%
- Maintainers (5)
Dependencies
- minitest ~> 5.0 development
- rake ~> 10.0 development
- rubocop ~> 0.54.0 development
- simplecov ~> 0.16.0 development
- simplecov-console ~> 0.4.0 development
Score: 28.44133654031021