Skip to content

Sentry.with_child_span incompatible with concurrency ruby? #2593

Closed
@lcmen

Description

@lcmen

Issue Description

Hey!

Here is a snippet of what we're trying to accomplish:

# requests is an array of procs that makes API calls
results = requests.map do |request|
  ConcurrentRails::Promises.future do
    request.call
  end
end.map(&:value)

Where each request.call makes a single API call wrapped with:

Sentry.with_child_span(op: 'api.request', description: path) do |span|
   ...
end

Reproduction Steps

As described above.

Expected Behavior

All child spans appear with correct operation and description span in Sentry UI.

Actual Behavior

All child spans appear as a single "No Instrumentation" span in Sentry UI.

Ruby Version

3.3.0

SDK Version

5.23.0

Integration and Its Version

Rails and Sidekiq

Sentry Config

# frozen_string_literal: true

require 'active_support/parameter_filter'

Sentry.init do |config|
  config.dsn = ENV.fetch('SENTRY_DSN', nil)
  config.breadcrumbs_logger = %i[active_support_logger http_logger]
  config.logger = Logger.new($stdout)
  config.logger.level = Logger::WARN

  # Filter out sensitive information from Sentry events
  filter = ActiveSupport::ParameterFilter.new(Rails.application.config.filter_parameters)

  # Exclude certain exceptions from Sentry
  config.excluded_exceptions += [
    'ActionController::RoutingError',
    'ActiveRecord::RecordNotFound',
  ]

  # Customize sampling rate based on transaction context
  config.traces_sampler = lambda do |sampling_context|
    transaction_context = sampling_context[:transaction_context]

    # transaction_context helps you sample transactions with more sophistication
    # for example, you can provide different sample rates based on the operation or name
    op = transaction_context[:op]
    transaction_name = transaction_context[:name]

    case op
    when /http/
      0.5
    when /sidekiq/
      0.4
    else
      0.0
    end
  end

  # Set the sample rate for performance monitoring
  config.traces_sample_rate = 0.5
  config.profiles_sample_rate = 0.5

  # Track cron jobs via Sidekiq Scheduler
  config.enabled_patches += [:sidekiq_scheduler]
end

Metadata

Metadata

Assignees

Type

Projects

Status

Waiting for: Community

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions