Skip to main content

Ruby

Supported platforms#

LinuxmacOSWindowsDocker
โœ…โœ…โœ…

Profiling Ruby applications#

Add the pyroscope gem to your Gemfile:

bundle add pyroscope

Basic Configuration#

Add the following code to your application. If you're using rails, put this into config/initializers directory. This code will initialize pyroscope profiler and start profiling:

require 'pyroscope'
Pyroscope.configure do |config|  config.app_name = "my.ruby.app" # replace this with some name for your application  config.server_address = "http://my-pyroscope-server:4040" # replace this with the address of your pyroscope server# config.auth_token = "{YOUR_API_KEY}" # optionally, if authentication is enabled, specify the API keyend

Tags#

Pyroscope ruby integration provides a number of ways to tag profiling data. For example, you can provide tags when you're initializing the profiler:

require 'pyroscope'
Pyroscope.configure do |config|  config.app_name = "my.ruby.app"  config.server_address   = "http://my-pyroscope-server:4040"
  config.tags = {    "hostname" => ENV["HOSTNAME"],  }end

or you can dynamically tag certain parts of your code:

# You can use a wrapper:Pyroscope.tag_wrapper({ "controller": "slow_controller_i_want_to_profile" }) do  slow_codeend
# Or you can add / remove tags manually:Pyroscope.tag({ "controller": "slow_controller_i_want_to_profile" })slow_codePyroscope.remove_tags("controller")

Example#

Check out this example ruby project in our repository for examples of how you can use these features.