Sentry for DelayedJob

Learn how to set up Sentry in your Ruby app, capture your first errors and traces, and view them in Sentry.

Agent-Assisted Setup
Use curl to download, read and follow https://skills.sentry.dev/instrument to set up the Sentry Ruby SDK.
Your agent will set up Sentry in your Ruby app automatically. Works with Cursor, Claude Code, Codex, and more.View docs ↗
Install the full plugin

Install the Sentry plugin to give your assistant every skill. See the installation docs for more details.

Copied
npx @sentry/agent-plugin install

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:

Want to learn more about these features?
  • Issues (always enabled): Sentry's core error monitoring product that automatically reports errors, uncaught exceptions, and unhandled rejections. If you have something that looks like an exception, Sentry can capture it.
  • Tracing: Track software performance while seeing the impact of errors across multiple systems. For example, distributed tracing allows you to follow a request from the frontend to the backend and back.
  • Profiling: Gain deeper insight than traditional tracing without custom instrumentation, letting you discover slow-to-execute or resource-intensive functions in your app.
  • Application Metrics (always enabled): Track and analyze custom application metrics, such as response times and database query durations, to understand trends and patterns in your application's performance and behavior over time.

Add the sentry-ruby, sentry-delayed_job and stackprof gems to your Gemfile:

Gemfile
Copied
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:

Copied
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.

Copied
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:

Copied

begin
  1 / 0
rescue ZeroDivisionError => exception
  Sentry.capture_exception(exception)
end

To test your tracing configuration, create a custom transaction and span:

Copied

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.

Copied

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).

Need help locating the captured errors in your Sentry project?
  • Open the Issues page and select an error from the issues list to view the full details and context of this error. For more details, see the Issue Details documentation.
  • Open the Traces page and select a trace to reveal more information about each span, its duration, and any errors. For an interactive UI walkthrough, click here.
  • Open the Profiles page, select a transaction, and then a profile ID to view its flame graph. For more information, click here.
  • Open the Application Metrics page to view and analyze your metrics. For more details, see this interactive walkthrough.

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:

Are you having problems setting up the SDK?
Was this helpful?
Help improve this content
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").