• /
  • EnglishEspañol日本語한국어Português
  • ログイン今すぐ開始

Sidekiq instrumentation

In addition to your web application itself, the New Relic Ruby agent (version 3.6.0 or higher) can automatically instrument your Sidekiq jobs. You do not need to include an instrumentation library in your worker.

The Ruby agent will instrument the perform method on all Sidekiq workers. Data for background jobs appears in APM's Transactions page, complete with transaction traces and errors, by selecting Non-web transactions as the transaction type.

Capture job arguments

Starting with Ruby agent version 3.6.9, you can optionally configure the Ruby agent to capture Sidekiq job arguments in transaction traces and traced errors. This can be especially useful in attempting to reproduce failed jobs.

By default this feature is off in case your job arguments contain sensitive information. To enable this feature, edit your newrelic.yml as appropriate for your agent version:

  • newrelic_rpm 3.12.0 or higher: attributes.include: job.sidekiq.args.*
  • newrelic_rpm 3.6.9 to 3.11.x: sidekiq.capture_params: true

ヒント

This feature is distinct from the generic capture_params top-level setting, which controls whether HTTP request parameters are captured on transaction traces and traced errors for web requests. You can configure these two settings independently.

Include or exclude certain job arguments

Starting with Ruby agent version 9.5.0, an instance of the agent configured to capture Sidekiq job arguments as described above can additionally be configured to include or exclude certain arguments for fine grained control over which arguments are reported to New Relic.

The :'sidekiq.args.include' configuration option can be set to an array of strings that will collectively serve as an allowlist. Each of those strings will be passed to Regexp.new for full regular expression support. For job arguments that are hashes, if a hash's key matches one of the include patterns, then both the key and its corresponding value will be included. For scalar arguments, the string representation of the scalar will need to match one of the include patterns to be captured.

The :'sidekiq.args.exclude' option works similarly. It can be set to an array of strings that will each be passed to Regexp.new to create patterns. These patterns will collectively serve as a denylist for unwanted job args. Any hash key, hash value, or scalar that matches an exclude pattern will be excluded (not sent to New Relic).

Configure sidekiq.args.include and sidekiq.args.exclude(newrelic_rpm 9.5.0 or higher):

newrelic.yml examples:

Any string in the :'sidekiq.args.include' or :'sidekiq.args.exclude' arrays will be turned into a regular expression. Knowledge of Ruby regular expression support can be leveraged but is not required. If regular expression syntax is not used, inexact matches will be performed and the string "Fortune" will match both "Fortune 500" and "Fortune and Glory". For exact matches, use regular expression anchors.

# Include any argument whose string representation matches either "apple" or "banana"
# The "apple" pattern will match both "green apple" and "red apple"
sidekiq.args.include:
- apple
- banana
# Exclude any arguments that match either "grape", "orange", or "pear"
sidekiq.args.exclude:
- grape
- orange
- pear
# Exclude any argument that is a 9 digit number
sidekiq.args.exclude:
- '\d{9}'
# Include anything that starts with "blue" but exclude anything that ends in "green"
sidekiq.args.include:
- '^blue'
sidekiq.args.exclude:
- 'green$'

Troubleshoot Sidekiq jobs

If it appears that jobs are not being monitored, review your newrelic_agent.log file generated when the worker starts. It should indicate whether the agent detects Sidekiq and communicates with the server. If you need support, note the exact command line that you used to start Sidekiq.

Copyright © 2024 New Relic株式会社。

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.