Configuring Blackfire Continuous Profiler for Ruby
Requires Production Plan

The Ruby continuous profiling is currently made across 3 dimensions:

  • CPU Time: Time spent running on the CPU
  • Wall-time: elapsed time per function call
  • Allocations: Number of objects allocated
  • Ruby >= 2.5
  • Blackfire Agent >= 2.13.0
  1. Add the datadog gem to your Gemfile or gems.rb file:

    1
    gem 'datadog', '~> 2.0'

    Blackfire utilizes the open source Datadog profiler to collect continuous profiling traces and, via its agent, sends it directly to Blackfire's ingesters where we process and analyze the data for your observability needs.

  2. Install the gems running the bundle install command.
  3. Enable the Ruby Continuous Profiler by defining these environment variables:

    • DD_PROFILING_ENABLED=true: controls the activation of the continuous profiler.
    • DD_SERVICE=my-ruby-app: sets the application name.
    • DD_PROFILING_ALLOCATION_ENABLED=1: enables allocation profiling
    • DD_TRACE_AGENT_URL=unix:///var/run/blackfire/agent.sock: has Blackfire
      Agent collect traces.
  4. Add the ddprofrb exec command to your Ruby application start command:

    1
    2
    3
    4
    bundle exec ddprofrb exec ruby myrubyapp.rb
    
    # Rails example
    bundle exec ddprofrb exec bin/rails s

Alternatively, start the profiler by adding the following code in your application's entry point if you can't start it using ddprofrb exec:

1
require 'datadog/profiling/preload'

There is also some additional configuration that can be done using environment variables:

  • BLACKFIRE_LOG_FILE: Sets the log file. The default is logging to stderr.
  • BLACKFIRE_LOG_LEVEL: Sets the log level. The default is logging only errors.