-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
251 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
require 'ddtrace/contrib/support/spec_helper' | ||
require_relative 'support/helper' | ||
|
||
RSpec.describe 'ClientTracerTest' do | ||
include_context 'Sidekiq testing' | ||
|
||
subject(:perform_async) { job_class.perform_async } | ||
let(:job_class) { EmptyWorker } | ||
|
||
before do | ||
Sidekiq.configure_client do |config| | ||
config.client_middleware.clear | ||
config.client_middleware do |chain| | ||
chain.add(Datadog::Contrib::Sidekiq::ClientTracer) | ||
end | ||
end | ||
|
||
Sidekiq::Testing.server_middleware.clear | ||
Sidekiq::Extensions.enable_delay! if Sidekiq::VERSION > '5.0.0' | ||
end | ||
|
||
it 'traces job push' do | ||
perform_async | ||
|
||
expect(span.service).to eq('sidekiq-client') | ||
expect(span.resource).to eq('EmptyWorker') | ||
expect(span.get_tag('sidekiq.job.queue')).to eq('default') | ||
expect(span.status).to eq(0) | ||
expect(span.parent).to be_nil | ||
expect(span.get_metric('_dd.measured')).to be_nil | ||
end | ||
|
||
context 'with nested trace' do | ||
it 'traces job push' do | ||
tracer.trace('parent.span', service: 'parent-service') do | ||
perform_async | ||
end | ||
|
||
expect(spans).to have(2).items | ||
|
||
parent_span, child_span = spans | ||
|
||
expect(parent_span.name).to eq('parent.span') | ||
expect(parent_span.status).to eq(0) | ||
expect(parent_span.parent).to be_nil | ||
|
||
expect(child_span.service).to eq('sidekiq-client') | ||
expect(child_span.resource).to eq('EmptyWorker') | ||
expect(child_span.get_tag('sidekiq.job.queue')).to eq('default') | ||
expect(child_span.status).to eq(0) | ||
expect(child_span.parent).to eq(parent_span) | ||
expect(child_span.get_metric('_dd.measured')).to be_nil | ||
end | ||
end | ||
|
||
context 'with delayed extensions' do | ||
subject(:do_work) { DelayableClass.delay.do_work } | ||
|
||
before do | ||
stub_const('DelayableClass', Class.new do | ||
def self.do_work; end | ||
end) | ||
end | ||
|
||
it 'traces with correct resource' do | ||
do_work | ||
expect(spans.first.resource).to eq('DelayableClass.do_work') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'ddtrace/contrib/support/spec_helper' | ||
require_relative 'support/helper' | ||
|
||
RSpec.describe 'Disabled tracer' do | ||
include_context 'Sidekiq testing' | ||
|
||
subject(:perform_async) { job_class.perform_async } | ||
let(:job_class) { EmptyWorker } | ||
|
||
before do | ||
Sidekiq::Testing.server_middleware.clear | ||
Sidekiq::Testing.server_middleware do |chain| | ||
Datadog.tracer.configure(enabled: false) | ||
chain.add(Datadog::Contrib::Sidekiq::ServerTracer) | ||
end | ||
end | ||
|
||
it 'does not trace' do | ||
perform_async | ||
|
||
expect(spans).to be_empty | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
require 'ddtrace/contrib/support/spec_helper' | ||
require_relative 'support/helper' | ||
|
||
RSpec.describe 'Server tracer' do | ||
include_context 'Sidekiq testing' | ||
|
||
subject(:perform_async) { job_class.perform_async } | ||
let(:job_class) { EmptyWorker } | ||
|
||
before do | ||
Sidekiq::Testing.server_middleware.clear | ||
Sidekiq::Testing.server_middleware do |chain| | ||
chain.add(Datadog::Contrib::Sidekiq::ServerTracer) | ||
end | ||
|
||
Sidekiq::Extensions.enable_delay! if Sidekiq::VERSION > '5.0.0' | ||
end | ||
|
||
it 'traces async job run' do | ||
perform_async | ||
|
||
expect(spans).to have(2).items | ||
|
||
span, _push = spans | ||
expect(span.service).to eq('sidekiq') | ||
expect(span.resource).to eq('EmptyWorker') | ||
expect(span.get_tag('sidekiq.job.queue')).to eq('default') | ||
expect(span.get_tag('sidekiq.job.delay')).to_not be_nil | ||
expect(span.status).to eq(0) | ||
expect(span.parent).to be_nil | ||
expect(span.get_tag('sidekiq.job.args')).to be_nil | ||
expect(span.get_metric('_dd.measured')).to eq(1.0) | ||
end | ||
|
||
context 'with job run failing' do | ||
let(:job_class) { ErrorWorker } | ||
|
||
before do | ||
stub_const('ErrorWorker', Class.new do | ||
include Sidekiq::Worker | ||
|
||
def perform | ||
raise ZeroDivisionError, 'job error' | ||
end | ||
end) | ||
end | ||
|
||
it 'traces async job run' do | ||
expect { perform_async }.to raise_error(ZeroDivisionError) | ||
expect(spans).to have(2).items | ||
|
||
span, _push = spans | ||
expect(span.service).to eq('sidekiq') | ||
expect(span.resource).to eq('ErrorWorker') | ||
expect(span.get_tag('sidekiq.job.queue')).to eq('default') | ||
expect(span.get_tag('sidekiq.job.delay')).to_not be_nil | ||
expect(span.status).to eq(1) | ||
expect(span.get_tag(Datadog::Ext::Errors::MSG)).to eq('job error') | ||
expect(span.get_tag(Datadog::Ext::Errors::TYPE)).to eq('ZeroDivisionError') | ||
expect(span.parent).to be_nil | ||
expect(span.get_tag('sidekiq.job.args')).to be_nil | ||
expect(span.get_metric('_dd.measured')).to eq(1.0) | ||
end | ||
end | ||
|
||
context 'with custom job' do | ||
before do | ||
stub_const('CustomWorker', Class.new do | ||
include Sidekiq::Worker | ||
|
||
def self.datadog_tracer_config | ||
{ service_name: 'sidekiq-slow', tag_args: true } | ||
end | ||
|
||
def perform(_) end | ||
end) | ||
end | ||
|
||
it 'traces async job run' do | ||
perform_async | ||
CustomWorker.perform_async('random_id') | ||
|
||
expect(spans).to have(4).items | ||
|
||
custom, empty, _push, _push = spans | ||
|
||
expect(empty.service).to eq('sidekiq') | ||
expect(empty.resource).to eq('EmptyWorker') | ||
expect(empty.get_tag('sidekiq.job.queue')).to eq('default') | ||
expect(empty.get_tag('sidekiq.job.delay')).to_not be_nil | ||
expect(empty.status).to eq(0) | ||
expect(empty.parent).to be_nil | ||
expect(empty.get_metric('_dd.measured')).to eq(1.0) | ||
|
||
expect(custom.service).to eq('sidekiq-slow') | ||
expect(custom.resource).to eq('CustomWorker') | ||
expect(custom.get_tag('sidekiq.job.queue')).to eq('default') | ||
expect(custom.status).to eq(0) | ||
expect(custom.parent).to be_nil | ||
expect(custom.get_tag('sidekiq.job.args')).to eq(['random_id'].to_s) | ||
expect(custom.get_metric('_dd.measured')).to eq(1.0) | ||
end | ||
end | ||
|
||
context 'with delayed extensions' do | ||
subject(:do_work) { DelayableClass.delay.do_work } | ||
|
||
before do | ||
stub_const('DelayableClass', Class.new do | ||
def self.do_work; end | ||
end) | ||
end | ||
|
||
it 'traces with correct resource' do | ||
do_work | ||
expect(spans.first.resource).to eq('DelayableClass.do_work') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'ddtrace/contrib/support/spec_helper' | ||
require_relative 'support/helper' | ||
|
||
RSpec.describe 'Tracer configuration' do | ||
include_context 'Sidekiq testing' | ||
|
||
subject(:perform_async) { job_class.perform_async } | ||
let(:job_class) { EmptyWorker } | ||
|
||
context 'with custom middleware configuration' do | ||
before do | ||
Sidekiq::Testing.server_middleware do |chain| | ||
chain.add( | ||
Datadog::Contrib::Sidekiq::ServerTracer, | ||
service_name: 'my-service' | ||
) | ||
end | ||
end | ||
|
||
it 'instruments with custom values' do | ||
perform_async | ||
|
||
expect(spans).to have(2).items | ||
|
||
span, _push = spans | ||
expect(span.service).to eq('my-service') | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.