Set Up Profiling

Learn how to enable profiling in your app if it is not already set up.

Ruby Profiling is currently in beta. Beta features are still in progress and may have bugs. We recognize the irony.

通过性能分析,Sentry 通过在各种环境中采样程序的调用栈来跟踪软件的性能。此功能收集关于代码的功能级信息,使你能够微调程序的性能。Sentry 的性能分析器捕获函数调用及其确切位置,对它们进行聚合,并显示程序中最常见的代码路径。这突出了你可以优化的区域,以帮助提高代码性能和用户满意度,同时降低成本。

StackProf profiling beta is available starting in SDK version 5.9.0.

We use the stackprof gem to collect profiles for Ruby.

First add stackprof to your Gemfile and make sure it is loaded before sentry-ruby.

Copied
# Gemfile

gem 'stackprof'
gem 'sentry-ruby'

Then, make sure both traces_sample_rate and profiles_sample_rate are set and non-zero in your Sentry initializer.

Copied
# config/initializers/sentry.rb

Sentry.init do |config|
  config.dsn = "https://examplePublicKey@o0.ingest.sentry.io/0"
  config.traces_sample_rate = 1.0
  config.profiles_sample_rate = 1.0
end

The profiles_sample_rate setting is relative to the traces_sample_rate setting.

For Profiling to work, you have to first enable Sentry’s tracing via traces_sample_rate (like in the example above). Read our tracing setup documentation to learn how to configure sampling. If you set your sample rate to 1.0, all transactions will be captured.

Vernier profiling beta is available starting in SDK version 5.21.0.

Vernier requires Ruby 3.2.1+

You can have much better profiles if you're using multi-threaded servers like Puma now by leveraging Vernier.

First, add vernier to your Gemfile and make sure it is loaded before sentry-ruby.

Copied
# Gemfile

gem 'vernier'
gem 'sentry-ruby'

Then, set a profiles_sample_rate and the new profiler_class configuration in your sentry initializer to use the new profiler.

Copied
# config/initializers/sentry.rb

Sentry.init do |config|
  config.dsn = "https://examplePublicKey@o0.ingest.sentry.io/0"
  config.profiles_sample_rate = 1.0
  config.traces_sample_rate = 1.0
  config.profiler_class = Sentry::Vernier::Profiler
end