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

Add a single top level span for Racecar consumers #1150

Merged
merged 2 commits into from
Aug 24, 2020
Merged
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/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