Skip to content

Commit

Permalink
Merge pull request #1150 from dasch/dasch-racecar-single-toplevel-span
Browse files Browse the repository at this point in the history
Add a single top level span for Racecar consumers
  • Loading branch information
marcotc authored Aug 24, 2020
2 parents b5f3769 + 3b16692 commit ecdb524
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/ddtrace/contrib/racecar/events.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
require 'ddtrace/contrib/racecar/events/batch'
require 'ddtrace/contrib/racecar/events/message'
require 'ddtrace/contrib/racecar/events/consume'

module Datadog
module Contrib
module Racecar
# Defines collection of instrumented Racecar events
module Events
ALL = [
Events::Consume,
Events::Batch,
Events::Message
].freeze
Expand Down
27 changes: 27 additions & 0 deletions lib/ddtrace/contrib/racecar/events/consume.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'ddtrace/contrib/racecar/ext'
require 'ddtrace/contrib/racecar/event'

module Datadog
module Contrib
module Racecar
module Events
# Defines instrumentation for main_loop.racecar event
module Consume
include Racecar::Event

EVENT_NAME = 'main_loop.racecar'.freeze

module_function

def event_name
self::EVENT_NAME
end

def span_name
Ext::SPAN_CONSUME
end
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/ddtrace/contrib/racecar/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Ext
ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_RACECAR_ANALYTICS_SAMPLE_RATE'.freeze
ENV_ANALYTICS_SAMPLE_RATE_OLD = 'DD_RACECAR_ANALYTICS_SAMPLE_RATE'.freeze
SERVICE_NAME = 'racecar'.freeze
SPAN_CONSUME = 'racecar.consume'.freeze
SPAN_BATCH = 'racecar.batch'.freeze
SPAN_MESSAGE = 'racecar.message'.freeze
TAG_CONSUMER = 'kafka.consumer'.freeze
Expand Down
58 changes: 58 additions & 0 deletions spec/ddtrace/contrib/racecar/patcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,64 @@
Datadog.registry[:racecar].reset_configuration!
end

describe 'for both single and batch message processing' do
let(:consumer) { 'DummyConsumer' }
let(:payload) { { consumer_class: consumer } }

let(:span) do
spans.select { |s| s.name == Datadog::Contrib::Racecar::Ext::SPAN_CONSUME }.first
end

context 'that doesn\'t raise an error' do
it 'is expected to send a span' do
ActiveSupport::Notifications.instrument('main_loop.racecar', payload)

span.tap do |span|
expect(span).to_not be nil
expect(span.service).to eq('racecar')
expect(span.name).to eq('racecar.consume')
expect(span.resource).to eq(consumer)
expect(span.get_tag('kafka.consumer')).to eq(consumer)
expect(span).to_not have_error
end
end
end

context 'that raises an error' do
let(:error_class) { Class.new(StandardError) }

it 'is expected to send a span' do
# Emulate failure
begin
ActiveSupport::Notifications.instrument('main_loop.racecar', payload) do
raise error_class
end
rescue error_class
nil
end

span.tap do |span|
expect(span).to_not be nil
expect(span.service).to eq('racecar')
expect(span.name).to eq('racecar.consume')
expect(span.resource).to eq(consumer)
expect(span.get_tag('kafka.consumer')).to eq(consumer)
expect(span).to have_error
end
end
end

it_behaves_like 'analytics for integration' do
before { ActiveSupport::Notifications.instrument('main_loop.racecar', payload) }
let(:analytics_enabled_var) { Datadog::Contrib::Racecar::Ext::ENV_ANALYTICS_ENABLED }
let(:analytics_sample_rate_var) { Datadog::Contrib::Racecar::Ext::ENV_ANALYTICS_SAMPLE_RATE }
end

it_behaves_like 'measured span for integration', true do
before { ActiveSupport::Notifications.instrument('main_loop.racecar', payload) }
end
end

describe 'for single message processing' do
let(:topic) { 'dd_trace_test_dummy' }
let(:consumer) { 'DummyConsumer' }
Expand Down

0 comments on commit ecdb524

Please sign in to comment.