-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #360 from Azdaroth/add-datadog-tracer
add Datadog tracer
- Loading branch information
Showing
5 changed files
with
70 additions
and
1 deletion.
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
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
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,17 @@ | ||
require 'ddtrace' | ||
|
||
module Hutch | ||
module Tracers | ||
class Datadog | ||
def initialize(klass) | ||
@klass = klass | ||
end | ||
|
||
def handle(message) | ||
::Datadog.tracer.trace(@klass.class.name, service: 'hutch', span_type: 'rabbitmq') do | ||
@klass.process(message) | ||
end | ||
end | ||
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,44 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Hutch::Tracers::Datadog do | ||
describe "#handle" do | ||
subject(:handle) { tracer.handle(message) } | ||
|
||
let(:tracer) { described_class.new(klass) } | ||
let(:klass) do | ||
Class.new do | ||
attr_reader :message | ||
|
||
def initialize | ||
@message = nil | ||
end | ||
|
||
def class | ||
OpenStruct.new(name: 'ClassName') | ||
end | ||
|
||
def process(message) | ||
@message = message | ||
end | ||
end.new | ||
end | ||
let(:message) { double(:message) } | ||
|
||
before do | ||
allow(Datadog.tracer).to receive(:trace).and_call_original | ||
end | ||
|
||
it 'uses Datadog tracer' do | ||
handle | ||
|
||
expect(Datadog.tracer).to have_received(:trace).with('ClassName', | ||
hash_including(service: 'hutch', span_type: 'rabbitmq')) | ||
end | ||
|
||
it 'processes the message' do | ||
expect { | ||
handle | ||
}.to change { klass.message }.from(nil).to(message) | ||
end | ||
end | ||
end |