Skip to content

Commit 03646cd

Browse files
ErvalhouSpicandocodigo
authored andcommitted
Adds consumer names to Racecar transactions
1 parent 7b47787 commit 03646cd

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

lib/elastic_apm/spies/racecar.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def process_batch(_event)
4747
private # only public methods will be subscribed
4848

4949
def start_process_transaction(event:, kind:)
50-
ElasticAPM.start_transaction(kind, TYPE)
50+
ElasticAPM.start_transaction("#{event.payload[:consumer_class]}##{kind}", TYPE)
5151
ElasticAPM.current_transaction.context.set_service(framework_name: 'racecar', framework_version: Racecar::VERSION)
5252
end
5353
end
@@ -74,4 +74,5 @@ def install
7474

7575
rescue LoadError
7676
# no active support available
77+
STDERR.puts "ActiveSupport not found."
7778
end

spec/elastic_apm/spies/racecar_spec.rb

+17-7
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,38 @@
1818
# frozen_string_literal: true
1919

2020
require 'spec_helper'
21-
2221
begin
2322
require 'active_support/notifications'
24-
require "active_support/subscriber"
23+
require 'active_support/subscriber'
2524
require 'racecar'
26-
2725
module ElasticAPM
2826
RSpec.describe 'Spy: Racecar', :intercept do
2927
it 'captures the instrumentation' do
3028
with_agent do
31-
ActiveSupport::Notifications.instrument('start_process_message.racecar')
32-
ActiveSupport::Notifications.instrument('process_message.racecar') do
29+
instrumentation_payload = {
30+
consumer_class: 'SpecConsumer',
31+
topic: 'spec_topic',
32+
partition: '0',
33+
offset: '1',
34+
create_time: Time.now,
35+
key: '1',
36+
value: {key: 'value'},
37+
headers: {key: 'value'}
38+
}
39+
ActiveSupport::Notifications.instrument('start_process_message.racecar', instrumentation_payload)
40+
ActiveSupport::Notifications.instrument('process_message.racecar', instrumentation_payload) do
3341
# this is the body of the racecar consumer #process method
3442
end
3543
first_transaction = @intercepted.transactions.first
3644
expect(first_transaction).not_to be_nil
37-
expect(first_transaction.name).to eq('process_message')
45+
expect(first_transaction.name).to eq("#{instrumentation_payload[:consumer_class]}#process_message")
3846
expect(first_transaction.type).to eq('kafka')
47+
expect(first_transaction.context.service.framework.name).to eq('racecar')
3948
end
4049
end
4150
end
4251
end
4352

4453
rescue LoadError # in case we don't have ActiveSupport
45-
end
54+
STDERR.puts "ActiveSupport not found, skipping."
55+
end

0 commit comments

Comments
 (0)