Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support enable/disable sidekiq spy #1496

Open
saiqulhaq opened this issue Oct 21, 2024 · 0 comments
Open

Support enable/disable sidekiq spy #1496

saiqulhaq opened this issue Oct 21, 2024 · 0 comments

Comments

@saiqulhaq
Copy link

saiqulhaq commented Oct 21, 2024

Is your feature request related to a problem? Please describe.

this gem causing a random error in my code that use mongodb. such as:

NameError: undefined local variable or method `type' for #<BSON::Document:0x00007f28841f58e8>

I found an old issue in apm-agent-ruby, mentioned that it is because RubyVM issue.
Currently I use Ruby v2.7

Describe the solution you'd like

Add functionality in Spy Sidekiq middleware, to be something like this:

class Middleware
  def call(worker, job, queue)
    worker_class = worker.class
    
    if worker_class.respond_to?(:apm_tracking_disabled?) && worker_class.apm_tracking_disabled?
      yield
    else
      name = SidekiqSpy.name_for(job)
      transaction = ElasticAPM.start_transaction(name, 'Sidekiq')
      ElasticAPM.set_label(:queue, queue)

      begin
        yield
        transaction&.done :success
        transaction&.outcome = Transaction::Outcome::SUCCESS
      rescue ::Exception => e
        ElasticAPM.report(e, handled: false)
        transaction&.done :error
        transaction&.outcome = Transaction::Outcome::FAILURE
        raise
      ensure
        ElasticAPM.end_transaction
      end
    end
  end
end

the above code is from AI. the main concept is to add additional config in my sidekiq worker class, such as self.apm_tracking_disabled = true

it's ok if you can't accept this idea, I could override the Spy Middleware class in my app instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant