Skip to content

Commit 6f2a0b1

Browse files
ErvalhouSpicandocodigo
authored andcommitted
Style guidelines applied
1 parent f9f7e86 commit 6f2a0b1

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

CHANGELOG.asciidoc

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ endif::[]
2222
[float]
2323
===== Changed
2424
- Change {pull}2526[#2526]
25+
- Racecar consumer instrumentation improvements {pull}
2526

2627
[float]
2728
===== Fixed

lib/elastic_apm/spies/racecar.rb

+14-10
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,24 @@
1616
# under the License.
1717

1818
begin
19-
require 'active_support/notifications'
20-
require 'active_support/subscriber'
19+
require 'active_support/notifications'
20+
require 'active_support/subscriber'
2121

2222
# frozen_string_literal: true
2323
module ElasticAPM
2424
# @api private
2525
module Spies
2626
# @api private
2727
class RacecarSpy
28-
TYPE = 'kafka'
29-
SUBTYPE = 'racecar'
28+
TYPE = 'kafka'.freeze
29+
SUBTYPE = 'racecar'.freeze
3030

3131
# @api private
3232
class ConsumerSubscriber < ActiveSupport::Subscriber
3333
def start_process_message(event)
3434
start_process_transaction(event: event, kind: 'process_message')
3535
end
36+
3637
def process_message(event)
3738
record_outcome(event: event)
3839
ElasticAPM.end_transaction
@@ -41,6 +42,7 @@ def process_message(event)
4142
def start_process_batch(event)
4243
start_process_transaction(event: event, kind: 'process_batch')
4344
end
45+
4446
def process_batch(event)
4547
record_outcome(event: event)
4648
ElasticAPM.end_transaction
@@ -50,7 +52,8 @@ def process_batch(event)
5052

5153
def start_process_transaction(event:, kind:)
5254
ElasticAPM.start_transaction("#{event.payload[:consumer_class]}##{kind}", TYPE)
53-
ElasticAPM.current_transaction.context.set_service(framework_name: 'racecar', framework_version: Racecar::VERSION)
55+
ElasticAPM.current_transaction.context.set_service(framework_name: 'racecar',
56+
framework_version: Racecar::VERSION)
5457
end
5558

5659
def record_outcome(event:)
@@ -61,10 +64,12 @@ def record_outcome(event:)
6164
end
6265
end
6366

67+
# @api private
6468
class ProducerSubscriber < ActiveSupport::Subscriber
65-
def start_deliver_message(event)
66-
ElasticAPM.start_transaction('deliver_message',TYPE)
67-
ElasticAPM.current_transaction.context.set_service(framework_name: 'racecar', framework_version: Racecar::VERSION)
69+
def start_deliver_message(_event)
70+
ElasticAPM.start_transaction('deliver_message', TYPE)
71+
ElasticAPM.current_transaction.context.set_service(framework_name: 'racecar',
72+
framework_version: Racecar::VERSION)
6873
end
6974

7075
def deliver_message(_event)
@@ -80,8 +85,7 @@ def install
8085
register 'Racecar', 'racecar', RacecarSpy.new
8186
end
8287
end
83-
8488
rescue LoadError
8589
# no active support available
86-
STDERR.puts "ActiveSupport not found."
90+
warn "ActiveSupport not found."
8791
end

spec/elastic_apm/spies/racecar_spec.rb

+10-11
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
require 'racecar'
2525
module ElasticAPM
2626
RSpec.describe 'Spy: Racecar', :intercept do
27-
let(:instrumentation_payload) {
27+
let(:instrumentation_payload) do
2828
{ consumer_class: 'SpecConsumer',
29-
topic: 'spec_topic',
30-
partition: '0',
31-
offset: '1',
32-
create_time: Time.now,
33-
key: '1',
34-
value: {key: 'value'},
35-
headers: {key: 'value'} }
36-
}
29+
topic: 'spec_topic',
30+
partition: '0',
31+
offset: '1',
32+
create_time: Time.now,
33+
key: '1',
34+
value: { key: 'value' },
35+
headers: { key: 'value' } }
36+
end
3737
it 'captures the instrumentation' do
3838
with_agent do
3939
ActiveSupport::Notifications.instrument('start_process_message.racecar', instrumentation_payload)
@@ -84,7 +84,6 @@ module ElasticAPM
8484
end
8585
end
8686
end
87-
8887
rescue LoadError # in case we don't have ActiveSupport
89-
STDERR.puts "ActiveSupport not found, skipping."
88+
warn "ActiveSupport not found, skipping."
9089
end

0 commit comments

Comments
 (0)