Ruby OpenTracing

OpenTracing provides "Vendor-neutral APIs and instrumentation for distributed tracing". If you're not familiar with OpenTracing, see the OpenTracing portal for more details.

The Instana Ruby gem implements these APIs and allows you to use the Instana gem with your OpenTracing calls.

Existing applications that utilize the OpenTracing API or those who wish to add support can easily integrate with this Ruby gem.

For best results when utilizing OpenTracing, also take note of our best practices outlined in this OpenTracing page.

To start, simply set the Instana tracer as the global tracer for OpenTracing:

require 'opentracing'
OpenTracing.global_tracer = ::Instana.tracer

Then OpenTracing code can be run normally:

  span = OpenTracing.start_span('job')
  # The code to be instrumented
  @id = User.find_by_name('john.smith')
  span.set_tag(:job_id, @id)
rescue => e
  span.set_tag(:error, e.message)


The following is an over-simplified example of some code that calls the OpenTracing APIs.

# Note:  The instana gem automatically sets the Instana tracer
# to `OpenTracing.global_tracer`.  Once the gem is loaded, you can
# immediately start making OpenTracing calls.
require "opentracing"

entry_span = OpenTracing.start_span("HandMadeRackServer")

entry_span.set_tag(:'http.method', :get)
entry_span.set_tag(:'http.url', "/users")
entry_span.set_tag(:'span.kind', "entry")

intermediate_span = OpenTracing.start_span("myintermediate", :child_of => entry_span)

db_span = OpenTracing.start_span('mydbspan', :child_of => entry_span)
db_span.set_tag(:'db.instance', "users")
db_span.set_tag(:'db.statement', "SELECT * FROM user_table")
db_span.set_tag(:'db.type', "mysql")
db_span.set_tag(:'db.user', "mysql_login")
db_span.set_tag(:'span.kind', "exit")

intermediate_span = OpenTracing.start_span("myintermediate", :child_of => entry_span)
intermediate_span.log("ALLOK", :message => "All seems ok")

entry_span.set_tag(:'http.status_code', 200)

See Also