Grape::Instrumentation
This gem provides OpenTracing instrumentation for Grape by hooking into ActiveSupport notifications.
The following events are instrumented:
endpoint_run.grapeendpoint_run_filters.grapeendpoint_run_validators.grapeendpoint_render.grapeformat_response.grape
Installation
Add this line to your application's Gemfile:
gem 'signalfx-grape-instrumentation'And then execute:
$ bundle
Or install it yourself as:
$ gem install signalfx-grape-instrumentation
Usage
require `grape/instrumentation`
Grape::Instrumentation.instrument(tracer: OpenTracing.global_tracer, parent_span: ->(payload) { some_parent_span })Grape::Instrumentation.instrument optionally takes these arguments:
-
tracer: OpenTracing tracer to be used for this instrumentation.- Default:
OpenTracing.global_tracer
- Default:
-
parent_span: this can be a parent span, or a block that takes an argument,payload, which is the notification event payload, and returns the that should be used as the parent span.- Example:
->(payload) { ::Grape::Instrumentation.tracer.active_span } - Default:
nil
- Example:
The tracer is made available through Grape::Instrumentation.tracer.
This instrumentation can be used in conjunction with Rack::Tracer to group spans by request.
Development
After checking out the repo, run bin/setup to install dependencies. 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/signalfx/ruby-grape-instrumentation.