Skip to content

Commit

Permalink
Support latest version of SlackRubyBot by applying instrumentation to…
Browse files Browse the repository at this point in the history
… message hook
  • Loading branch information
kstole committed Sep 26, 2017
1 parent ece856b commit b895538
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### 0.2.0 (Next)

* [#5](https://github.com/slack-ruby/newrelic-slack-ruby-bot/pull/5): Support latest version of SlackRubyBot by applying instrumentation to message hook [@kstole](https://github.com/kstole).
* Your contribution here.

### 0.1.1 (9/26/2017)
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ source 'http://rubygems.org'

gemspec

gem 'celluloid-io', require: %w(celluloid/current celluloid/io)
gem 'rspec', '~> 3.4.0'
gem 'rake', '< 11.0'
gem 'rubocop', '0.35.1'
8 changes: 4 additions & 4 deletions lib/newrelic-slack-ruby-bot/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
end

def instrument_call
::SlackRubyBot::Server.class_eval do
::SlackRubyBot::Hooks::Message.class_eval do
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation

def message_with_new_relic(client, data)
perform_action_with_newrelic_trace(name: 'message', category: 'OtherTransaction/Slack') do
perform_action_with_newrelic_trace(name: 'call', category: 'OtherTransaction/Slack') do
message_without_new_relic(client, data)
end
end

alias_method :message_without_new_relic, :message
alias_method :message, :message_with_new_relic
alias_method :message_without_new_relic, :call
alias_method :call, :message_with_new_relic
end
end
end
2 changes: 1 addition & 1 deletion newrelic-slack-ruby-bot.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ Gem::Specification.new do |s|
s.licenses = ['MIT']
s.summary = 'NewRelic instrumentation for slack-ruby-bot.'
s.add_dependency 'newrelic_rpm'
s.add_dependency 'slack-ruby-bot', '<= 0.7.0'
s.add_dependency 'slack-ruby-bot', '> 0.7.0'
end
9 changes: 4 additions & 5 deletions spec/newrelic-slack-ruby-bot/instrumentation_spec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
require 'spec_helper'

describe NewRelic::Agent::Instrumentation do
subject { SlackRubyBot::Hooks::Message.new }
let(:client) { SlackRubyBot::Client.new }
subject do
SlackRubyBot::Server.new
end

it 'perform_action_with_newrelic_trace' do
expect(subject)
.to receive(:perform_action_with_newrelic_trace)
.with(hash_including(name: 'message'))
.with(hash_including(name: 'call', category: 'OtherTransaction/Slack'))
.and_yield

subject.message(client, Hashie::Mash.new(message: 'message', text: 'hi'))
subject.call(client, Hashie::Mash.new(message: 'message', text: 'hi'))
end
end

0 comments on commit b895538

Please sign in to comment.