{"id":18728594,"url":"https://github.com/rubyonworld/traceview","last_synced_at":"2025-06-16T08:06:20.586Z","repository":{"id":174008177,"uuid":"542165242","full_name":"RubyOnWorld/traceview","owner":"RubyOnWorld","description":"The traceview gem provides TraceView performance instrumentation for Ruby.","archived":false,"fork":false,"pushed_at":"2022-09-27T18:29:59.000Z","size":2338,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-19T20:32:14.891Z","etag":null,"topics":["gem","performance","ruby","traceview"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RubyOnWorld.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null}},"created_at":"2022-09-27T15:45:20.000Z","updated_at":"2022-09-27T22:39:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"e345f7a6-e5f3-489c-853e-cd0f689bb504","html_url":"https://github.com/RubyOnWorld/traceview","commit_stats":null,"previous_names":["rubyonworld/traceview"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/RubyOnWorld/traceview","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Ftraceview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Ftraceview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Ftraceview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Ftraceview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RubyOnWorld","download_url":"https://codeload.github.com/RubyOnWorld/traceview/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Ftraceview/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260124034,"owners_count":22962200,"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":["gem","performance","ruby","traceview"],"created_at":"2024-11-07T14:22:06.742Z","updated_at":"2025-06-16T08:06:20.571Z","avatar_url":"https://github.com/RubyOnWorld.png","language":"Ruby","readme":"# Welcome to the TraceView Ruby Gem\n\nThe traceview gem provides [TraceView](https://traceview.solarwinds.com/) performance instrumentation for Ruby.\n\n![Ruby TraceView](http://docs.traceview.solarwinds.com/images/ruby_readme/oboe-ruby-header.png)\n\nIt has the ability to report performance metrics on an array of libraries, databases and frameworks such as Rails, Mongo, Memcache, ActiveRecord, Cassandra, Rack, Resque [and more](http://docs.traceview.solarwinds.com/Instrumentation/ruby.html#ruby-support-matrix).\n\nIt requires a [TraceView](https://traceview.solarwinds.com/) account to view metrics.  Get yours, [it's free](https://traceview.solarwinds.com/TraceView/Signup).\n\n[![Gem Version](https://badge.fury.io/rb/traceview.png)](https://badge.fury.io/rb/traceview)\n[![Build Status](https://travis-ci.org/tracelytics/ruby-traceview.png?branch=master)](https://travis-ci.org/tracelytics/ruby-traceview)\n[![Code Climate](https://codeclimate.com/github/tracelytics/ruby-traceview.png)](https://codeclimate.com/github/tracelytics/ruby-traceview)\n\n_Note: The repository name has been changed to ruby-traceview.  Please update your github remotes with `git remote set-url origin git@github.com:tracelytics/ruby-traceview.git`._\n\n# Installation\n\n_Before installing the gem below, make sure that you have the [base packages](http://docs.traceview.solarwinds.com/TraceView/install-instrumentation.html#install-base-packages) installed on your host first._\n\nThe traceview gem is [available on Rubygems](https://rubygems.org/gems/traceview) and can be installed with:\n\n```bash\ngem install traceview\n```\n\nor added to _the end_ of your bundle Gemfile and running `bundle install`:\n\n```ruby\ngem 'traceview'\n```\n\n# Running\n\n## Rails\n\n![Ruby on Rails](http://docs.traceview.solarwinds.com/images/ruby_readme/rails.png)\n\nNo special steps are needed to instrument Ruby on Rails.  Once part of the bundle, the traceview gem will automatically detect Rails and instrument on stack initialization.\n\n*Note: You will still need to decide on your `tracing_mode` depending on whether you are running with an instrumented Apache or nginx in front of your Rails stack.  See below for more details.*\n\n### The Install Generator\n\nThe traceview gem provides a Rails generator used to seed an initializer where you can configure and control `tracing_mode` and [other options](http://docs.traceview.solarwinds.com/Instrumentation/ruby.html#configuring-instrumentation).\n\nTo run the install generator run:\n\n```bash\nbundle exec rails generate traceview:install\n```\n\nAfter the prompts, this will create an initializer: `config/initializers/traceview.rb`.\n\n## Sinatra\n\n![Sinatra](http://docs.traceview.solarwinds.com/images/ruby_readme/sinatra.png)\n\nYou can instrument your Sinatra application by adding the following code to your `config.ru` Rackup file:\n\n```ruby\n# If you're not using Bundler.require.  Make sure this is done\n# after the Sinatra require directive.\nrequire 'traceview'\n\n# When traces should be initiated for incoming requests. Valid options are\n# \"always\", \"through\" (when the request is initiated with a tracing header\n# from upstream) and \"never\". You must set this directive to \"always\" in\n# order to initiate tracing.\nTraceView::Config[:tracing_mode] = 'through'\n\n# You may want to replace the TraceView.logger with whichever logger you are using\n# TraceView.logger = Sinatra.logger\n```\n\nMake sure that the traceview gem is loaded _after_ Sinatra either by listing `gem 'traceview'` after Sinatra in your Gemfile or calling the `require 'traceview'` directive after Sinatra is loaded.\n\nWith this, the traceview gem will automatically detect Sinatra on boot and instrument key components.\n\n## Padrino\n\n![Padrino](http://docs.traceview.solarwinds.com/images/ruby_readme/padrino.png)\n\nAs long as the traceview gem is in your `Gemfile` (inserted after the `gem 'padrino'` directive) and you are calling `Bundler.require`, the traceview gem will automatically instrument Padrino applications.\n\nIf you need to set `TraceView::Config` values on stack boot, you can do so by adding the following\nto your `config/boot.rb` file:\n\n```ruby\nPadrino.before_load do\n  # When traces should be initiated for incoming requests. Valid options are\n  # \"always\", \"through\" (when the request is initiated with a tracing header\n  # from upstream) and \"never\". You must set this directive to \"always\" in\n  # order to initiate tracing.\n  TraceView::Config[:tracing_mode] = 'always'\nend\n```\n\n## Grape\n\n![Grape](http://docs.traceview.solarwinds.com/images/ruby_readme/grape.png)\n\nYou can instrument your Grape application by adding the following code to your `config.ru` Rackup file:\n\n```ruby\n    # If you're not using Bundler.require.  Make sure this is done\n    # after the Grape require directive.\n    require 'traceview'\n\n    # When traces should be initiated for incoming requests. Valid options are\n    # \"always\", \"through\" (when the request is initiated with a tracing header\n    # from upstream) and \"never\". You must set this directive to \"always\" in\n    # order to initiate tracing.\n    TraceView::Config[:tracing_mode] = 'through'\n\n    ...\n\n    class App \u003c Grape::API\n      use TraceView::Rack\n    end\n```\n\nMake sure that the traceview gem is loaded _after_ Grape either by listing `gem 'traceview'` after Grape in your Gemfile or calling the `require 'traceview'` directive after Grape is loaded.\n\nYou must explicitly tell your Grape application to use TraceView::Rack for tracing to occur.\n\n## Custom Ruby Scripts \u0026 Applications\n\nThe traceview gem has the ability to instrument any arbitrary Ruby application or script.  Only the `tracing_mode` needs to be set to tell the traceview gem to initiate performance metric collection.\n\n```ruby\nrequire 'rubygems'\nrequire 'bundler'\n\nBundler.require\n\nrequire 'traceview'\n\n# Tracing mode can be 'never', 'through' (to follow upstream) or 'always'\nTraceView::Config[:tracing_mode] = 'always'\n```\n\nFrom here, you can use the Tracing API to instrument areas of code using `TraceView::API.start_trace` (see below).  If you prefer to instead dive directly into code, take a look at [this example](https://gist.github.com/pglombardo/8550713) of an instrumented Ruby script.\n\nOnce inside of the `TraceView::API.start_trace` block, performance metrics will be automatically collected for all supported libraries and gems (Redis, Mongo, ActiveRecord etc..).\n\n## Other\n\nYou can send deploy notifications to TraceView and have the events show up on your dashboard.  See: [Capistrano Deploy Notifications with tlog](http://docs.traceview.solarwinds.com/Instrumentation/ruby.html#report-deploy-notifications)\n\n# Custom Tracing\n\nYou can add even more visibility into any part of your application or scripts by adding custom instrumentation.  If you want to see the performance of an existing method see Method Profiling.  To trace blocks of code see the Tracing API.\n\n## The Tracing API\n\nYou can instrument any arbitrary block of code using `TraceView::API.trace`.  The code and any supported calls for libraries that we support, will automatically get traced and reported to your dashboard.\n\n```ruby\n# layer_name will show up in the TraceView app dashboard\nlayer_name = 'subsystemX'\n\n# report_kvs are a set of information Key/Value pairs that are sent to\n# TraceView dashboard along with the performance metrics.  These KV\n# pairs are used to report request, environment and/or client specific\n# information.\n\nreport_kvs = {}\nreport_kvs[:mykey] = @client.id\n\nTraceView::API.trace(layer_name, report_kvs) do\n  # the block of code to be traced\nend\n```\n\n`TraceView::API.trace` is used within the context of a request.  It will follow the upstream state of the request being traced.  i.e. the block of code will only be traced when the parent request is being traced.\n\nThis tracing state of a request can also be queried by using `TraceView.tracing?`.\n\nIf you need to instrument code outside the context of a request (such as a cron job, background job or an arbitrary ruby script), use `TraceView::API.start_trace` instead which will initiate new traces based on configuration and probability (based on the sample rate).\n\nFind more details in the [RubyDoc page](http://rdoc.info/gems/traceview/TraceView/API/Tracing) or in [this example](https://gist.github.com/pglombardo/8550713) on how to use the Tracing API in an independent Ruby script.\n\n## Tracing Methods\n\nWith TraceView, you can profile any method in your application or even in the Ruby language using `TraceView::API.profile_method`.\n\nIf, for example, you wanted to see the performance for the `Array::sort`, you could simply call the following in your startup code:\n\n```\nTraceView::API.profile_method(Array, :sort)\n```\n\nFor full documentation, options and reporting custom KVs, see our documentation on [method profiling](http://docs.traceview.solarwinds.com/Instrumentation/ruby.html#ruby-function-profiling).\n\n# Support\n\nIf you find a bug or would like to request an enhancement, feel free to file an issue.  For all other support requests, see our [support portal](https://tracelytics.freshdesk.com).\n\n# Contributing\n\nYou are obviously a person of great sense and intelligence.  We happily appreciate all contributions to the traceview gem whether it is documentation, a bug fix, new instrumentation for a library or framework or anything else we haven't thought of.\n\nWe welcome you to send us PRs.  We also humbly request that any new instrumentation submissions have corresponding tests that accompany them.  This way we don't break any of your additions when we (and others) make changes after the fact.\n\n## Developer Resources\n\nWe have made a large effort to expose as much technical information as possible to assist developers wishing to contribute to the traceview gem.  Below is a good source for information and help for developers:\n\n* The [TraceView Knowledge Base](http://docs.traceview.solarwinds.com/) has a large collection of technical articles or, if needed, you can submit a support request directly to the team.\n\nIf you have any questions or ideas, don't hesitate to contact us anytime.\n\n## Layout of the Gem\n\nThe traceview gem uses a standard gem layout.  Here are the notable directories.\n\n    lib/traceview/inst               # Auto load directory for various instrumented libraries\n    lib/traceview/frameworks         # Framework instrumentation directory\n    lib/traceview/frameworks/rails   # Files specific to Rails instrumentation\n    lib/rails                        # A Rails required directory for the Rails install generator\n    lib/api                          # The TraceView Tracing API: layers, logging, profiling and tracing\n    ext/oboe_metal                   # The Ruby c extension that links against the system liboboe library\n\n## Building the Gem\n\nThe traceview gem is built with the standard `gem build` command passing in the gemspec:\n\n```bash\ngem build traceview.gemspec\n```\n\n## Writing Custom Instrumentation\n\nCustom instrumentation for a library, database or other service can be authored fairly easily.  Generally, instrumentation of a library is done by wrapping select operations of that library and timing their execution using the TraceView Tracing API which then reports the metrics to the users' TraceView dashboard.\n\nHere, I'll use a stripped down version of the Dalli instrumentation (`lib/traceview/inst/dalli.rb`) as a quick example of how to instrument a client library (the dalli gem).\n\nThe Dalli gem nicely routes all memcache operations through a single `perform` operation.  Wrapping this method allows us to capture all Dalli operations called by an application.\n\nFirst, we define a module (TraceView::Inst::Dalli) and our own custom `perform_with_traceview` method that we will use as a wrapper around Dalli's `perform` method.  We also declare an `included` method which automatically gets called when this module is included by another.  See ['included' Ruby reference documentation](https://www.omniref.com/ruby/2.2.1/symbols/Module/included).\n\n```ruby\nmodule TraceView\n  module Inst\n    module Dalli\n      include TraceView::API::Memcache\n\n      def self.included(cls)\n        cls.class_eval do\n          if ::Dalli::Client.private_method_defined? :perform\n            alias perform_without_traceview perform\n            alias perform perform_with_traceview\n          end\n        end\n      end\n\n      def perform_with_traceview(*all_args, \u0026blk)\n        op, key, *args = *all_args\n\n        if TraceView.tracing?\n          opts = {}\n          opts[:KVOp] = op\n          opts[:KVKey] = key\n\n          TraceView::API.trace('memcache', opts || {}) do\n            result = perform_without_traceview(*all_args, \u0026blk)\n            if op == :get and key.class == String\n                TraceView::API.log('memcache', 'info', { :KVHit =\u003e memcache_hit?(result) })\n            end\n            result\n          end\n        else\n          perform_without_traceview(*all_args, \u0026blk)\n        end\n      end\n    end\n  end\nend\n```\n\nSecond, we tail onto the end of the instrumentation file a simple `::Dalli::Client.module_eval` call to tell the Dalli module to include our newly defined instrumentation module.  Doing this will invoke our previously defined `included` method.\n\n```ruby\nif defined?(Dalli) and TraceView::Config[:dalli][:enabled]\n  ::Dalli::Client.module_eval do\n    include TraceView::Inst::Dalli\n  end\nend\n```\n\nThird, in our wrapper method, we capture the arguments passed in, collect the operation and key information into a local hash and then invoke the `TraceView::API.trace` method to time the execution of the original operation.\n\nThe `TraceView::API.trace` method calls Dalli's native operation and reports the timing metrics and your custom `report_kvs` up to TraceView servers to be shown on the user's dashboard.\n\nSome other tips and guidelines:\n\n* You can point your Gemfile directly at your cloned traceview gem source by using `gem 'traceview', :path =\u003e '/path/to/ruby-traceview'`\n\n* If instrumenting a library, database or service, place your new instrumentation file into the `lib/traceview/inst/` directory.  From there, the traceview gem will detect it and automatically load the instrumentation file.\n\n* If instrumenting a new framework, place your instrumentation file in `lib/traceview/frameworks`.  Refer to the Rails instrumentation for on ideas on how to load the traceview gem correctly in your framework.\n\n* Review other existing instrumentation similar to the one you wish to author.  `lib/traceview/inst/` is a great place to start.\n\n* Depending on the configured `:sample_rate`, not all requests will be traced.  Use `TraceView.tracing?` to determine of this is a request that is being traced.\n\n* Performance is paramount.  Make sure that your wrapped methods don't slow down users applications.\n\n* Include tests with your instrumentation.  See `test/instrumentation/` for some examples of existing instrumentation tests.\n\n## Compiling the C extension\n\nThe traceview gem utilizes a C extension to interface with the system `liboboe.so` library.  This system library is installed with the TraceView host packages (tracelyzer, liboboe0, liboboe-dev) and is used to report host and performance metrics from multiple sources (Ruby, Apache, Python etc.) back to TraceView servers.\n\nC extensions are usually built on `gem install` but when working out of a local git repository, it's required that you manually build this C extension for the gem to function.\n\nTo make this simpler, we've included a few rake tasks to automate this process:\n\n```bash\nrake compile             # Build the gem's c extension\nrake distclean           # Remove all built files and extensions\nrake recompile           # Rebuild the gem's c extension\n```\n\nNote: Make sure you have the development package `liboboe0-dev` installed before attempting to compile the C extension.\n\n```bash\n\u003e\u003e$ dpkg -l | grep liboboe\nii  liboboe-dev  1.2.1-trusty1  TraceView common library -- development files\nii  liboboe0     1.2.1-trusty1  Traceview common library\n```\n\nSee [Installing Base Packages on Debian and Ubuntu](http://docs.traceview.solarwinds.com/TraceView/install-instrumentation.html#debian-and-ubuntu) in the Knowledge Base for details.\n\nTo see the code related to the C extension, take a look at `ext/oboe_metal/extconf.rb` for details.\n\nYou can read more about Ruby gems with C extensions in the [Rubygems Guides](http://guides.rubygems.org/gems-with-extensions/).\n\n## Running the Tests\n\n![TraceView Ruby Tests](http://docs.traceview.solarwinds.com/images/ruby_readme/tv_ruby_tests.png)\n\nThe tests bundled with the gem are implemented using [Minitest](https://github.com/seattlerb/minitest).  The tests are currently used to validate the sanity of the traces generated and basic gem functionality.\n\nAfter a bundle install, the tests can be run as:\n\n```bash\nbundle exec rake test\n```\n\nThis will run a full end-to-end test suite that covers all supported libraries and databases.  Note that this requires all of the supported software (Cassandra, Memcache, Mongo etc.) to be installed, configured and available.\n\nSince this is overly burdensome for casual users, you can run just the tests that you're interested in.\n\nTo run just the tests for the dalli gem trace validation:\n\n```bash\nbundle exec rake test TEST=test/instrumentation/dalli_test.rb\n```\n\nWe humbly request that any submitted instrumentation is delivered with corresponding test coverage.\n\n# License\n\nCopyright (c) 2016 SolarWinds, LLC\n\nReleased under the [Librato Open License](http://docs.traceview.solarwinds.com/Instrumentation/librato-open-license.html)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyonworld%2Ftraceview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubyonworld%2Ftraceview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyonworld%2Ftraceview/lists"}