### Install Gems via Bundle Source: https://docs.sentry.io/platforms/ruby/guides/delayed_job/integrations/otlp Run the bundle command to install the added dependencies. ```bash bundle install ``` -------------------------------- ### Install Sentry Rails SDK Source: https://docs.sentry.io/platforms/ruby/guides/rails/logs Install the required gem via command line or Gemfile. ```bash gem install sentry-rails ``` ```ruby gem "sentry-rails" ``` -------------------------------- ### Install OTLP Dependencies Source: https://docs.sentry.io/platforms/ruby/guides/delayed_job/integrations/otlp Add the necessary Sentry and OpenTelemetry gems to your Gemfile. ```ruby gem "sentry-ruby" gem "sentry-opentelemetry" gem "opentelemetry-sdk" gem "opentelemetry-exporter-otlp" # Add any OpenTelemetry instrumentation gems you need, for example: gem "opentelemetry-instrumentation-all" ``` -------------------------------- ### Install Sentry Ruby SDK Source: https://docs.sentry.io/platforms/ruby/guides/delayed_job/metrics Install the required gem via command line or add it to your Gemfile. ```bash gem install sentry-ruby ``` ```ruby gem "sentry-ruby" ``` -------------------------------- ### Execute Tool Span Example Source: https://docs.sentry.io/platforms/ruby/guides/delayed_job/tracing/instrumentation/custom-instrumentation/ai-agents-module Demonstrates how to manually create a child span for tracking AI tool execution with relevant metadata. ```ruby require 'json' Sentry.with_child_span(op: 'gen_ai.execute_tool', description: 'execute_tool get_weather') do |span| span.set_data('gen_ai.operation.name', 'execute_tool') span.set_data('gen_ai.tool.name', 'get_weather') span.set_data('gen_ai.tool.call.arguments', { location: 'Paris' }.to_json) result = get_weather(location: 'Paris') span.set_data('gen_ai.tool.call.result', result.to_json) end ``` -------------------------------- ### Install sentry-yabeda dependencies Source: https://docs.sentry.io/platforms/ruby/guides/delayed_job/integrations/yabeda Add the required gems to your Gemfile. ```ruby gem "sentry-ruby" gem "sentry-yabeda" ``` -------------------------------- ### Verify Sentry Setup Source: https://docs.sentry.io/platforms/ruby/guides/delayed_job Send a test message to confirm that Sentry is correctly configured and communicating with your project. ```ruby Sentry.capture_message("test message") ``` -------------------------------- ### Install Sentry Gems Source: https://docs.sentry.io/platforms/ruby/guides/delayed_job Add the required gems to your Gemfile. Use the version with stackprof if you intend to use profiling. ```ruby gem "sentry-ruby" gem "sentry-delayed_job" ``` ```ruby gem "stackprof" gem "sentry-ruby" gem "sentry-delayed_job" ``` -------------------------------- ### Install Sentry and Profiling Gems Source: https://docs.sentry.io/platforms/ruby/guides/rack Include the stackprof gem alongside sentry-ruby to enable profiling features. ```ruby gem "stackprof" gem "sentry-ruby" ``` -------------------------------- ### Install Sentry Sidekiq Gems Source: https://docs.sentry.io/platforms/ruby/guides/sidekiq Add the required gems to your Gemfile. Use the version including stackprof if you intend to use profiling. ```ruby gem "sentry-ruby" gem "sentry-sidekiq" ``` ```ruby gem "stackprof" gem "sentry-ruby" gem "sentry-sidekiq" ``` -------------------------------- ### Install Sentry OpenTelemetry Gems Source: https://docs.sentry.io/platforms/ruby/guides/delayed_job/tracing/instrumentation/opentelemetry Add the required Sentry and OpenTelemetry gems to your Gemfile. ```ruby gem "sentry-ruby" gem "sentry-rails" gem "sentry-opentelemetry" gem "opentelemetry-sdk" gem "opentelemetry-instrumentation-all" ``` -------------------------------- ### Install Sentry Gem Source: https://docs.sentry.io/platforms/ruby/guides/rack Add the required gem to your Gemfile for basic error monitoring. ```ruby gem "sentry-ruby" ``` -------------------------------- ### Install Sentry Gems Source: https://docs.sentry.io/platforms/ruby/guides/rails Add the required gems to your Gemfile for basic error monitoring or with profiling support. ```ruby gem "sentry-ruby" gem "sentry-rails" ``` ```ruby gem "stackprof" gem "sentry-ruby" gem "sentry-rails" ``` -------------------------------- ### Install Sentry Gems Source: https://docs.sentry.io/platforms/ruby/guides/resque Add the required gems to your Gemfile for Resque integration. ```ruby gem "sentry-ruby" gem "sentry-resque" ``` ```ruby gem "stackprof" gem "sentry-ruby" gem "sentry-resque" ``` -------------------------------- ### Create a custom transaction Source: https://docs.sentry.io/platforms/ruby/guides/delayed_job/tracing/instrumentation/custom-instrumentation Manually start a transaction, set it on the current scope, and finish it to send data to Sentry. ```ruby # start a transaction transaction = Sentry.start_transaction(op: "process_item") # set the transaction on the scope so children span are attached to this transaction Sentry.get_current_scope.set_span(transaction) # perform the operation process_item(args) # finish the transaction, which will send it to Sentry automatically transaction.finish ``` -------------------------------- ### Instrumenting Jobs with Check-Ins Source: https://docs.sentry.io/platforms/ruby/crons Use two-step check-ins to track job progress, start times, and runtime failures. ```ruby check_in_id = Sentry.capture_check_in('', :in_progress) # Execute your scheduled task here... Sentry.capture_check_in('', :ok, check_in_id: check_in_id) ``` ```ruby Sentry.capture_check_in('', :error, check_in_id: check_in_id) ``` -------------------------------- ### Configure CORS headers for Sentry trace propagation Source: https://docs.sentry.io/platforms/ruby/guides/resque/tracing/trace-propagation/dealing-with-cors-issues Example of the required response header configuration to allow Sentry headers. ```http Access-Control-Allow-Headers: sentry-trace, baggage ``` -------------------------------- ### Sentry.with_child_span Source: https://docs.sentry.io/platforms/ruby/guides/resque/tracing/instrumentation/custom-instrumentation/ai-agents-module Example of instrumenting an AI agent invocation by creating a child span and setting relevant AI-specific data attributes. ```APIDOC ## Sentry.with_child_span ### Description Creates a child span to track an AI agent operation. Use this to record metadata about the model, agent name, and token usage. ### Parameters - **op** (string) - Required - The operation name, typically 'gen_ai.invoke_agent'. - **description** (string) - Required - A description of the agent being invoked. ### Data Attributes - **gen_ai.operation.name** (string) - The name of the operation. - **gen_ai.request.model** (string) - The model name used. - **gen_ai.agent.name** (string) - The name of the agent. - **gen_ai.output.messages** (string) - JSON stringified array of messages. - **gen_ai.usage.input_tokens** (int) - Total input tokens. - **gen_ai.usage.output_tokens** (int) - Total output tokens. ### Example ```ruby Sentry.with_child_span(op: 'gen_ai.invoke_agent', description: 'invoke_agent Weather Agent') do |span| span.set_data('gen_ai.operation.name', 'invoke_agent') span.set_data('gen_ai.request.model', 'o3-mini') span.set_data('gen_ai.agent.name', 'Weather Agent') result = my_agent.run span.set_data('gen_ai.output.messages', [ { role: 'assistant', parts: [{ type: 'text', content: result.to_s }] } ].to_json) span.set_data('gen_ai.usage.input_tokens', result.usage.input_tokens) span.set_data('gen_ai.usage.output_tokens', result.usage.output_tokens) end ``` ``` -------------------------------- ### Initialize Sentry with Configuration Options Source: https://docs.sentry.io/platforms/ruby/configuration/options Configure the SDK by passing attributes to the config object inside the Sentry.init block. ```ruby Sentry.init do |config| config.dsn = 'https://@o.ingest.sentry.io/' config.max_breadcrumbs = 5 config.debug = true # Add data like request headers and IP for users, if applicable; # see https://docs.sentry.io/platforms/ruby/data-management/data-collected/ for more info config.send_default_pii = true # enable tracing # we recommend adjusting this value in production config.traces_sample_rate = 1.0 end ``` -------------------------------- ### Retrieve or Start a Transaction Source: https://docs.sentry.io/platforms/ruby/guides/delayed_job/tracing/instrumentation/custom-instrumentation Use this to attach spans to an existing transaction or start a new one if none is currently running. ```ruby transaction = Sentry.get_current_scope.get_transaction || Sentry.start_transaction(name: 'task') span = transaction.start_child(op: 'operation') # perform the operation span.finish if span ``` -------------------------------- ### Update SDK Configuration Source: https://docs.sentry.io/platforms/ruby/guides/delayed_job/migration Transition from Raven.configure to Sentry.init for initializing the SDK. ```ruby Raven.configure do |config| config.dsn = "DSN" end ``` ```ruby Sentry.init do |config| config.dsn = "DSN" # Add data like request headers and IP for users, if applicable; # see https://docs.sentry.io/platforms/ruby/data-management/data-collected/ for more info config.send_default_pii = true end ``` -------------------------------- ### Configure Sentry with Rackup Source: https://docs.sentry.io/platforms/ruby/guides/rack Initialize Sentry and add the CaptureExceptions middleware to your rackup file. ```ruby require 'sentry-ruby' Sentry.init do |config| config.dsn = 'https://@o.ingest.sentry.io/' # get breadcrumbs from logs config.breadcrumbs_logger = [:sentry_logger, :http_logger] # Add data like request headers and IP for users, if applicable; # see https://docs.sentry.io/platforms/ruby/data-management/data-collected/ for more info config.send_default_pii = true # ___PRODUCT_OPTION_START___ performance # enable tracing # we recommend adjusting this value in production config.traces_sample_rate = 1.0 # ___PRODUCT_OPTION_END___ performance # ___PRODUCT_OPTION_START___ profiling # enable profiling # this is relative to traces_sample_rate config.profiles_sample_rate = 1.0 # ___PRODUCT_OPTION_END___ profiling end use Sentry::Rack::CaptureExceptions ``` -------------------------------- ### Initialize Sentry with Logs Source: https://docs.sentry.io/platforms/ruby/guides/rails/logs Enable structured logging by setting enable_logs to true during SDK initialization. ```ruby Sentry.init do |config| config.dsn = "https://@o.ingest.sentry.io/" config.enable_logs = true end ``` -------------------------------- ### Initialize Sentry with metrics Source: https://docs.sentry.io/platforms/ruby/guides/delayed_job/integrations/yabeda Enable metrics in the Sentry configuration to allow the Yabeda adapter to automatically register and forward metrics. ```ruby Sentry.init do |config| config.dsn = ENV["SENTRY_DSN"] config.enable_metrics = true end ``` -------------------------------- ### Configure Sentry SDK for OTLP Source: https://docs.sentry.io/platforms/ruby/guides/delayed_job/integrations/otlp Enable the OTLP integration within the Sentry initialization block. ```ruby Sentry.init do |config| config.dsn = "https://@o.ingest.sentry.io/" # Add data like request headers and IP for users, if applicable; # see https://docs.sentry.io/platforms/ruby/data-management/data-collected/ for more info config.send_default_pii = true config.otlp.enabled = true end ``` -------------------------------- ### Initialize Sentry with OpenTelemetry Source: https://docs.sentry.io/platforms/ruby/guides/delayed_job/tracing/instrumentation/opentelemetry Configure Sentry to use OpenTelemetry as the instrumenter. ```ruby Sentry.init do |config| config.dsn = "https://@o.ingest.sentry.io/" config.traces_sample_rate = 1.0 # set the instrumenter to use OpenTelemetry instead of Sentry config.instrumenter = :otel end ``` -------------------------------- ### Configure Sentry Source: https://docs.sentry.io/platforms/ruby/guides/delayed_job Initialize Sentry as early as possible in your application lifecycle. Adjust sample rates and feature flags based on your requirements. ```ruby require 'sentry-ruby' Sentry.init do |config| config.dsn = 'https://@o.ingest.sentry.io/' # get breadcrumbs from logs config.breadcrumbs_logger = [:sentry_logger, :http_logger] # Add data like request headers and IP for users, if applicable; # see https://docs.sentry.io/platforms/ruby/data-management/data-collected/ for more info config.send_default_pii = true # ___PRODUCT_OPTION_START___ performance # enable tracing # we recommend adjusting this value in production config.traces_sample_rate = 1.0 # ___PRODUCT_OPTION_END___ performance # ___PRODUCT_OPTION_START___ profiling # enable profiling # this is relative to traces_sample_rate config.profiles_sample_rate = 1.0 # ___PRODUCT_OPTION_END___ profiling # ___PRODUCT_OPTION_START___ logs # Enable logs to be sent to Sentry config.enable_logs = true # ___PRODUCT_OPTION_END___ logs end ``` -------------------------------- ### Instrument Cache Get Operation Source: https://docs.sentry.io/platforms/ruby/guides/delayed_job/tracing/instrumentation/custom-instrumentation/caches-module Wraps cache read operations with a 'cache.get' span, tracking hit status and item size. ```ruby key = 'myCacheKey123' value = nil Sentry.with_child_span(op: 'cache.get') do |span| # Get a key from your caching solution value = my_cache.get(key) # Describe the cache server you are accessing span.set_data('network.peer.address', 'cache.example.com/supercache') span.set_data('network.peer.port', 9000) # Add the key(s) you just retrieved from the cache span.set_data('cache.key', [key]) if value # If you retrieved a value, the cache was hit span.set_data('cache.hit', True) # Optionally also add the size of the value you retrieved span.set_data('cache.item_size', value.size) else # If you could not retrieve a value, it was a miss span.set_data('cache.hit', False) end end ``` -------------------------------- ### Configure Reverse Proxy for Queue Time Source: https://docs.sentry.io/platforms/ruby/guides/delayed_job/tracing/instrumentation/performance-metrics Set the X-Request-Start header in your reverse proxy to enable queue time tracking. ```nginx location / { proxy_pass http://your-app; proxy_set_header X-Request-Start "t=${msec}"; } ``` ```haproxy frontend http-in http-request set-header X-Request-Start t=%Ts%ms ``` -------------------------------- ### Configure OpenTelemetry SDK Source: https://docs.sentry.io/platforms/ruby/guides/delayed_job/integrations/otlp Configure the OpenTelemetry SDK to use desired instrumentations. ```ruby OpenTelemetry::SDK.configure do |c| c.use_all # or configure specific instrumentations end ``` -------------------------------- ### Instrumenting Jobs with Heartbeats Source: https://docs.sentry.io/platforms/ruby/crons Use a single check-in to notify Sentry of a job's status, primarily for tracking missed start times. ```ruby Sentry.capture_check_in('', :ok) ``` ```ruby Sentry.capture_check_in('', :error) ``` -------------------------------- ### Creating Monitor Configurations Source: https://docs.sentry.io/platforms/ruby/crons Define monitor schedules programmatically using crontab strings or intervals. ```ruby # Create a config from a crontab schedule (every 10 minutes) monitor_config = Sentry::Cron::MonitorConfig.from_crontab( '5 * * * *', checkin_margin: 5, # Optional check-in margin in minutes max_runtime: 15, # Optional max runtime in minutes timezone: 'Europe/Vienna', # Optional timezone ) # Create a config from an interval schedule (every 10 minutes) monitor_config = Sentry::Cron::MonitorConfig.from_interval( 10, :minute, checkin_margin: 5, # Optional check-in margin in minutes max_runtime: 15, # Optional max runtime in minutes timezone: 'Europe/Vienna', # Optional timezone ) ``` -------------------------------- ### Added Configuration Options Source: https://docs.sentry.io/platforms/ruby/guides/delayed_job/migration New configuration options available for transport customization and background worker management. ```ruby # this behaves similar to the old config.scheme option config.transport.transport_class = MyTransportClass # sentry-ruby sends events asynchronously with its own background workers # the default number of workers equals to your machine's processor count # you can adjust the number with config.background_worker_threads = 10 # to send events synchronously like sentry-raven does, set it to 0 config.background_worker_threads = 0 ```