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

Fix: Runner adds exceptions to instrumentation payload #340

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/racecar/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ def process(message)
consumer.store_offset(message)
end
rescue => e
instrumentation_payload[:exception] = e
instrumentation_payload[:unrecoverable_delivery_error] = reset_producer_on_unrecoverable_delivery_errors(e)
instrumentation_payload[:retries_count] = pause.pauses_count
config.error_handler.call(e, instrumentation_payload)
Expand Down Expand Up @@ -232,6 +233,7 @@ def process_batch(messages)
processor.deliver!
consumer.store_offset(messages.last)
rescue => e
instrumentation_payload[:exception] = e
instrumentation_payload[:unrecoverable_delivery_error] = reset_producer_on_unrecoverable_delivery_errors(e)
instrumentation_payload[:retries_count] = pause.pauses_count
config.error_handler.call(e, instrumentation_payload)
Expand Down
27 changes: 24 additions & 3 deletions spec/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,14 @@ def consumer_rebalance_listener=(_listenr)
end

class FakeInstrumenter < Racecar::Instrumenter
def initialize(*)
def initialize(received = [])
super(backend: Racecar::NullInstrumenter)
@received = received
end

def instrument(event_name, payload = {}, &block)
@received << [event_name, payload]
super
end
end

Expand Down Expand Up @@ -375,7 +381,8 @@ def initialize(*)
let(:config) { Racecar::Config.new }
let(:logger) { Logger.new(StringIO.new) }
let(:kafka) { FakeRdkafka.new(runner: runner) }
let(:instrumenter) { FakeInstrumenter.new }
let(:instrumenter) { FakeInstrumenter.new(instrumented_events) }
let(:instrumented_events) { [] }

let(:runner) do
Racecar::Runner.new(processor, config: config, logger: logger, instrumenter: instrumenter)
Expand Down Expand Up @@ -419,8 +426,9 @@ def initialize(*)
create_time: nil,
key: nil,
value: error,
exception: error,
headers: nil,
retries_count: anything,
retries_count: instance_of(Integer),
unrecoverable_delivery_error: false,
}

Expand All @@ -431,6 +439,18 @@ def initialize(*)
runner.run
end

it "adds the exception to the instrumentation payload" do
error = StandardError.new("surprise")

kafka.deliver_message(error, topic: "greetings")

runner.run

expect(instrumented_events).to include(
["process_message", hash_including(exception: error) ]
)
end

it "keeps track of the number of retries when a message causes an exception" do
error = StandardError.new("surprise")

Expand Down Expand Up @@ -555,6 +575,7 @@ def initialize(*)
message_count: 1,
retries_count: anything,
unrecoverable_delivery_error: false,
exception: error,
}

expect(config.error_handler).to receive(:call).at_least(:once).with(error, info)
Expand Down