Skip to content

Commit

Permalink
Merge pull request #360 from Azdaroth/add-datadog-tracer
Browse files Browse the repository at this point in the history
add Datadog tracer
  • Loading branch information
michaelklishin authored Apr 3, 2021
2 parents a5a5e8f + a60bdd9 commit 85e0d7d
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ group :development, :test do
gem "honeybadger"
gem "coveralls", "~> 0.8.15", require: false
gem "newrelic_rpm"
gem "ddtrace"
gem "airbrake", "~> 10.0"
gem "rollbar"
gem "bugsnag"
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ This will enable NewRelic custom instrumentation:
Hutch::Config.set(:tracer, Hutch::Tracers::NewRelic)
```

And this will enable Datadog custom instrumentation:

```ruby
Hutch::Config.set(:tracer, Hutch::Tracers::Datadog)
```

Batteries included!

## Running Hutch
Expand Down Expand Up @@ -246,7 +252,7 @@ and the consumers are not loaded in development environment you will need to
trigger the autoloading in an initializer with

```ruby
::Zeitwerk::Loader.eager_load_all
::Zeitwerk::Loader.eager_load_all
```

or with something more specific like
Expand Down
1 change: 1 addition & 0 deletions lib/hutch/tracers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module Hutch
module Tracers
autoload :NullTracer, 'hutch/tracers/null_tracer'
autoload :NewRelic, 'hutch/tracers/newrelic'
autoload :Datadog, 'hutch/tracers/datadog'
end
end
17 changes: 17 additions & 0 deletions lib/hutch/tracers/datadog.rb
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
44 changes: 44 additions & 0 deletions spec/hutch/tracers/datadog_spec.rb
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

0 comments on commit 85e0d7d

Please sign in to comment.