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

process method strict arity check causes incompatibility with NewRelic Elastic APM gem #362

Open
airdrummingfool opened this issue Jan 11, 2024 · 1 comment

Comments

@airdrummingfool
Copy link

A strict arity check was added to the process method in Racecar in 2.3.0. I believe this check conflicts with the way the NewRelic's Elastic APM gem sets up method spanning.

Due to this method signature check, my consumer crashes on start with Racecar 2.3.0 and newer:

=> Starting Racecar consumer DataConsumer...
=> Detected Rails, booting application...
=> Ctrl-C to shutdown consumer
=> Wrooooom!
=> Crashed: Racecar::Error: Invalid method signature for `process`. The method must take exactly 1 argument.

Using Racecar 2.2.0 or below works perfectly.

Would it be possible to loosen the arity check, make it optional, or add some kind of workaround so that newer versions of Racecar can be used with the Elastic APM gem?

@rohitnand10
Copy link

rohitnand10 commented Oct 16, 2024

Here is the patch that worked well for us, by removing the Arity check:

# frozen_string_literal: true

# Racecar
# RaceCar has introduced an arity check for the produce & produce_batch methods and enforced it to be = 1.
# This, when used along with ElasticAPM::SpanHelper's span_method, is resulting in the arity of -1, which is causing the Racecar Consumers to crash.
# This has been logged with Zendesk and until they become lenient with this arity check, the following patch is applied,
# to keep our Racecar gem version up to date and use it with Elastic APM.
# link for this issue logged with the creators of Racecar: https://github.com/zendesk/racecar/issues/362
module Patches
  module RacecarPatch
    module RacecarAritySkipPatch
      Racecar::Runner.module_eval do
        private

        def process_method
          @process_method ||= if processor.respond_to?(:process_batch)
                                :batch
                              elsif processor.respond_to?(:process)
                                :single
                              else
                                raise NotImplementedError.new("Consumer class `#{processor.class}` \
                                                              must implement a `process` or `process_batch` method")
                              end
        end
      end
    end
  end
end
Racecar::Consumer.include(::Patches::RacecarPatch::RacecarAritySkipPatch)

Make sure to require this Patch before the execution of Racecar::Consumer. The better place would be either one of config/initializers/load_patches*.rb or config/application.rb (Just a suggestion)

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

No branches or pull requests

2 participants