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 Datadog tracer #360

Merged
merged 2 commits into from
Apr 3, 2021
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
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"
end
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