Sentry for DelayedJob
Learn how to set up Sentry in your Ruby app, capture your first errors and traces, and view them in Sentry.
Use curl to download, read and follow https://skills.sentry.dev/instrument to set up the Sentry Ruby SDK.Using a framework?
Check out the other SDKs we support in the left-hand dropdown.
You need:
- A Sentry account and project
- Your application up and running
- Ruby
2.4+or any of the most recent JRuby versions
Installing the Sentry SDK enables core features such as Error Monitoring and Application Metrics by default. We'll show you how to send metrics in Verify Your Setup.
Choose additional features you want to configure, and this guide will show you how to get set up:
Add the sentry-ruby and sentry-delayed_job gems to your Gemfile:
Gemfilegem "sentry-ruby"
gem "sentry-delayed_job"
gem "sentry-ruby"
gem "sentry-delayed_job"
Add the sentry-ruby, sentry-delayed_job and stackprof gems to your Gemfile:
Gemfilegem "stackprof"
gem "sentry-ruby"
gem "sentry-delayed_job"
gem "stackprof"
gem "sentry-ruby"
gem "sentry-delayed_job"
Configuration should happen as early as possible in your application's lifecycle.
Import and initialize the SDK in your app's entry point:
require 'sentry-ruby'
Sentry.init do |config|
config.dsn = '___PUBLIC_DSN___'
# Get breadcrumbs from logs
# Learn more at
# https://docs.sentry.io/platforms/ruby/configuration/options/#breadcrumbs_logger
config.breadcrumbs_logger = [:sentry_logger, :http_logger]
# ___PRODUCT_OPTION_START___ performance
# Set tracesSampleRate to 1.0 to capture 100%
# of transactions for tracing.
# We recommend adjusting this value in production
# Learn more at
# https://docs.sentry.io/platforms/ruby/configuration/options/#traces_sample_rate
config.traces_sample_rate = 1.0
# ___PRODUCT_OPTION_END___ performance
# ___PRODUCT_OPTION_START___ profiling
# Enable profiling for a percentage of sessions relative to traces_sample_rate.
# Learn more at
# https://docs.sentry.io/platforms/ruby/configuration/options/#profiles_sample_rate
config.profiles_sample_rate = 1.0
# ___PRODUCT_OPTION_END___ profiling
end
require 'sentry-ruby'
Sentry.init do |config|
config.dsn = '___PUBLIC_DSN___'
# Get breadcrumbs from logs
# Learn more at
# https://docs.sentry.io/platforms/ruby/configuration/options/#breadcrumbs_logger
config.breadcrumbs_logger = [:sentry_logger, :http_logger]
# ___PRODUCT_OPTION_START___ performance
# Set tracesSampleRate to 1.0 to capture 100%
# of transactions for tracing.
# We recommend adjusting this value in production
# Learn more at
# https://docs.sentry.io/platforms/ruby/configuration/options/#traces_sample_rate
config.traces_sample_rate = 1.0
# ___PRODUCT_OPTION_END___ performance
# ___PRODUCT_OPTION_START___ profiling
# Enable profiling for a percentage of sessions relative to traces_sample_rate.
# Learn more at
# https://docs.sentry.io/platforms/ruby/configuration/options/#profiles_sample_rate
config.profiles_sample_rate = 1.0
# ___PRODUCT_OPTION_END___ profiling
end
By default, the SDK does not send user identity data (IP address, ID, and similar) or other data like HTTP bodies and URL query parameters.
To opt in and get richer debugging context, turn on individual categories using the data_collection option. For the full list of categories and their defaults, see the data_collection options.
require 'sentry-ruby'
Sentry.init do |config|
config.dsn = '___PUBLIC_DSN___'
config.data_collection.user_info = true
config.data_collection.http_bodies = [:incoming_request, :outgoing_request]
# other categories
end
require 'sentry-ruby'
Sentry.init do |config|
config.dsn = '___PUBLIC_DSN___'
config.data_collection.user_info = true
config.data_collection.http_bodies = [:incoming_request, :outgoing_request]
# other categories
end
Let's test your setup and confirm that data reaches your Sentry project.
To verify that Sentry captures errors and creates issues in your Sentry project, add this intentional error to your application:
begin
1 / 0
rescue ZeroDivisionError => exception
Sentry.capture_exception(exception)
end
begin
1 / 0
rescue ZeroDivisionError => exception
Sentry.capture_exception(exception)
end
To test your tracing configuration, create a custom transaction and span:
Sentry.start_transaction(op: "task", name: "Transaction Name") do |transaction|
Sentry.get_current_scope.set_span(transaction)
Sentry.with_child_span(description: "Custom Span Name") do |span|
# your instrumented code here
end
end
Sentry.start_transaction(op: "task", name: "Transaction Name") do |transaction|
Sentry.get_current_scope.set_span(transaction)
Sentry.with_child_span(description: "Custom Span Name") do |span|
# your instrumented code here
end
end
Send test metrics from your app to verify that metrics are arriving in Sentry using the Sentry.metrics APIs.
You can also send Yabeda metrics to Sentry automatically using our Yabeda integration.
Sentry.metrics.count("checkout.failed", 1)
Sentry.metrics.gauge("queue.depth", 42)
Sentry.metrics.distribution("cart.amount_usd", 187.5)
Sentry.metrics.count("checkout.failed", 1)
Sentry.metrics.gauge("queue.depth", 42)
Sentry.metrics.distribution("cart.amount_usd", 187.5)
Now, head over to your project on Sentry.io to view the collected data (it takes a couple of moments for the data to appear).
At this point, you should have integrated Sentry into your application and should already be sending data to your Sentry project.
Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are:
- Explore practical guides on what to monitor, log, track, and investigate after setup
- Continue to customize your configuration
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").