newrelic-slack-ruby-bot 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dbe6d3164cf6e4048053f40f1b16a86a633ba791
4
- data.tar.gz: 541d728290a0449c4e55c5672630549bc13dc2c0
3
+ metadata.gz: 93eb40878e93b48b07f21362a982459d05b7e676
4
+ data.tar.gz: 9e3c8a237a1200ffbc76f1aa257800bb671e81e3
5
5
  SHA512:
6
- metadata.gz: abd4bc708ba4fe1ccc1286a0a1b0057aaa906f7c74ac7000005274f4b5aefe218bcf8f571bd800d88b7ef4155af063a59f84324bebae2ba10adbcd90266c8764
7
- data.tar.gz: '0045281a46ba59a104ec4c8a1671d4a1f27f1726f2fa1bc4788fc5dbab03281931b991ed47f80742fcc8f4a15fc3e5a4acf5f2feaec9cee194a34e3b17c7d4dc'
6
+ metadata.gz: 65c659cd156786c01e79638898ac9695a1a5be8e8348122d52c1b56ff66fd92a9de519bdcbf69d5285a21fde5785aca487504503a403f43fe36f6ca019ea810c
7
+ data.tar.gz: f090f404c0a52570d5dc4927c470989e62ea11a1966065ef8b16a6cc5fa7718ce41f7a4fd1fe86df76792ae73f34efb6e909ef0411857713fe46da549f3de9a9
@@ -1,3 +1,9 @@
1
+ ### 0.2.1 (11/10/2017)
2
+
3
+ * [#6](https://github.com/slack-ruby/newrelic-slack-ruby-bot/pull/6): Add team, channel, and user attributes to New Relic traces - [@kstole](https://github.com/kstole).
4
+ * [#8](https://github.com/slack-ruby/newrelic-slack-ruby-bot/pull/8): Name New Relic transactions according to command called - [@kstole](https://github.com/kstole).
5
+ * [#10](https://github.com/slack-ruby/newrelic-slack-ruby-bot/pull/10): Fix occasional infinite loop caused by Instrumentation - [@kstole](https://github.com/kstole).
6
+
1
7
  ### 0.2.0 (9/26/2017)
2
8
 
3
9
  * [#4](https://github.com/slack-ruby/newrelic-slack-ruby-bot/pull/4): Revise New Relic log messages - [@kstole](https://github.com/kstole).
@@ -1,4 +1,4 @@
1
- # Contributing to Ruby-Enum
1
+ # Contributing to SlackRubyBot NewRelic Instrumentation
2
2
 
3
3
  This project is work of [many contributors](https://github.com/slack-ruby/newrelic-slack-ruby-bot/graphs/contributors).
4
4
 
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- newrelic-slack-ruby-bot (0.2.0)
4
+ newrelic-slack-ruby-bot (0.2.1)
5
5
  newrelic_rpm
6
- slack-ruby-bot (>= 0.8.0)
6
+ slack-ruby-bot (>= 0.10.5)
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
@@ -43,14 +43,15 @@ GEM
43
43
  multipart-post (>= 1.2, < 3)
44
44
  faraday_middleware (0.12.2)
45
45
  faraday (>= 0.7.4, < 1.0)
46
- gli (2.16.1)
46
+ gli (2.17.0)
47
47
  hashie (3.5.6)
48
48
  hitimes (1.2.6)
49
- i18n (0.8.6)
49
+ i18n (0.9.1)
50
+ concurrent-ruby (~> 1.0)
50
51
  json (2.1.0)
51
52
  minitest (5.10.3)
52
53
  multipart-post (2.0.0)
53
- newrelic_rpm (4.4.0.336)
54
+ newrelic_rpm (4.5.0.337)
54
55
  nio4r (2.1.0)
55
56
  parser (2.4.0.0)
56
57
  ast (~> 2.2)
@@ -79,7 +80,7 @@ GEM
79
80
  ruby-progressbar (~> 1.7)
80
81
  tins (<= 1.6.0)
81
82
  ruby-progressbar (1.8.3)
82
- slack-ruby-bot (0.10.4)
83
+ slack-ruby-bot (0.10.5)
83
84
  hashie
84
85
  slack-ruby-client (>= 0.6.0)
85
86
  slack-ruby-client (0.10.0)
@@ -94,7 +95,7 @@ GEM
94
95
  timers (4.1.2)
95
96
  hitimes
96
97
  tins (1.6.0)
97
- tzinfo (1.2.3)
98
+ tzinfo (1.2.4)
98
99
  thread_safe (~> 0.1)
99
100
  websocket-driver (0.7.0)
100
101
  websocket-extensions (>= 0.1.0)
data/README.md CHANGED
@@ -7,7 +7,7 @@ NewRelic Instrumentation for SlackRubyBot
7
7
 
8
8
  NewRelic instrumentation for [slack-ruby-bot](https://github.com/slack-ruby/slack-ruby-bot).
9
9
 
10
- ![](screenshots/breakdown.png)
10
+ ![NewRelic Transactions](screenshots/newrelic_transactions.png)
11
11
 
12
12
  ## Install
13
13
 
@@ -17,6 +17,33 @@ Add to Gemfile.
17
17
  gem 'newrelic-slack-ruby-bot'
18
18
  ```
19
19
 
20
+ ## Usage
21
+
22
+ This gem adds New Relic tracing to the Slack message hook, which is the start of all messages coming in from Slack.
23
+ New Relic will automatically record any external requests made through supported libraries (such as `Net::HTTP`) and database queries for supported databases (such as `MongoDB` and `Redis`).
24
+ This gem also adds the team, channel, user, and match data from each message, which can be seen in New Relic transaction traces and Insights.
25
+
26
+ ![NewRelic Breakdown of calculate command](screenshots/newrelic_calculate_breakdown.png)
27
+
28
+ ### Renaming transactions
29
+
30
+ By default, `newrelic-slack-ruby-bot` names New Relic transactions according to the operator, command, match, or scan route that was called.
31
+ To rename a New Relic transaction, make a call directly to the New Relic agent.
32
+
33
+ ```ruby
34
+ ::NewRelic::Agent.set_transaction_name('new name')
35
+ ```
36
+
37
+ The typical format for transaction names is `ClassName/method`.
38
+
39
+ ### Adding custom attributes
40
+
41
+ You can add additional custom attributes via the New Relic agent.
42
+
43
+ ```ruby
44
+ ::NewRelic::Agent.add_custom_attributes(key: value)
45
+ ```
46
+
20
47
  ## Contributing
21
48
 
22
49
  You're encouraged to contribute to this gem. See [CONTRIBUTING](CONTRIBUTING.md) for details.
@@ -11,15 +11,17 @@ DependencyDetection.defer do
11
11
 
12
12
  executes do
13
13
  NewRelic::Agent.logger.info 'Installing SlackRubyBot instrumentation'
14
- instrument_call
15
14
  end
16
15
 
17
- def instrument_call
16
+ executes do
18
17
  ::SlackRubyBot::Hooks::Message.class_eval do
19
18
  include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
20
19
 
21
20
  def message_with_new_relic(client, data)
22
21
  perform_action_with_newrelic_trace(name: 'call', category: 'OtherTransaction/Slack') do
22
+ ::NewRelic::Agent.add_custom_attributes(team: data.team,
23
+ channel: data.channel,
24
+ user: data.user)
23
25
  message_without_new_relic(client, data)
24
26
  end
25
27
  end
@@ -28,4 +30,36 @@ DependencyDetection.defer do
28
30
  alias_method :call, :message_with_new_relic
29
31
  end
30
32
  end
33
+
34
+ executes do
35
+ ::SlackRubyBot::Commands::Base.class_eval do
36
+ class << self
37
+ def command_name(match)
38
+ if match.is_a? MatchData
39
+ if match.names.include? 'command'
40
+ match[:command].downcase
41
+ elsif match.names.include? 'operator'
42
+ match[:operator].downcase
43
+ else
44
+ 'match'
45
+ end
46
+ else
47
+ 'scan'
48
+ end
49
+ end
50
+
51
+ def call_command_with_new_relic(client, data, match, block)
52
+ ::NewRelic::Agent.set_transaction_name("#{self}/#{command_name(match)}")
53
+ if match.is_a? MatchData
54
+ ::NewRelic::Agent
55
+ .add_custom_attributes(Hash[match.names.map(&:to_sym).zip(match.captures)])
56
+ end
57
+ call_command_without_new_relic(client, data, match, block)
58
+ end
59
+
60
+ alias_method :call_command_without_new_relic, :call_command
61
+ alias_method :call_command, :call_command_with_new_relic
62
+ end
63
+ end
64
+ end
31
65
  end
@@ -1,8 +1,9 @@
1
1
  module NewRelic
2
2
  module Agent
3
3
  module Instrumentation
4
+ # New Relic instrumentation for SlackRubyBot
4
5
  module SlackRubyBot
5
- VERSION = '0.2.0'.freeze
6
+ VERSION = '0.2.1'.freeze
6
7
  end
7
8
  end
8
9
  end
@@ -14,5 +14,5 @@ Gem::Specification.new do |s|
14
14
  s.licenses = ['MIT']
15
15
  s.summary = 'NewRelic instrumentation for slack-ruby-bot.'
16
16
  s.add_dependency 'newrelic_rpm'
17
- s.add_dependency 'slack-ruby-bot', '>= 0.8.0'
17
+ s.add_dependency 'slack-ruby-bot', '>= 0.10.5'
18
18
  end
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  describe NewRelic::Agent::Instrumentation do
4
4
  subject { SlackRubyBot::Hooks::Message.new }
5
5
  let(:client) { SlackRubyBot::Client.new }
6
+ before(:all) { SlackRubyBot::Config.user = 'mybot' }
6
7
 
7
8
  it 'perform_action_with_newrelic_trace' do
8
9
  expect(subject)
@@ -10,6 +11,130 @@ describe NewRelic::Agent::Instrumentation do
10
11
  .with(hash_including(name: 'call', category: 'OtherTransaction/Slack'))
11
12
  .and_yield
12
13
 
13
- subject.call(client, Hashie::Mash.new(message: 'message', text: 'hi'))
14
+ subject.call(client, Slack::Messages::Message.new(message: 'message',
15
+ text: 'hi',
16
+ team: 'TEAM',
17
+ channel: 'CHANNEL',
18
+ user: 'USER'))
19
+ end
20
+
21
+ context 'operator' do
22
+ before(:all) do
23
+ MyOperatorClass = Class.new(SlackRubyBot::Commands::Base) do
24
+ operator('+') { |_client, _data, _match| }
25
+ end
26
+ end
27
+ it 'adds team, channel, user, and match attributes' do
28
+ expect(::NewRelic::Agent)
29
+ .to receive(:add_custom_attributes)
30
+ .with(hash_including(team: 'TEAM', channel: 'CHANNEL', user: 'USER'))
31
+ expect(::NewRelic::Agent)
32
+ .to receive(:add_custom_attributes)
33
+ .with(hash_including(operator: '+', expression: '42'))
34
+
35
+ subject.call(client, Slack::Messages::Message.new(message: 'message',
36
+ text: '+42',
37
+ team: 'TEAM',
38
+ channel: 'CHANNEL',
39
+ user: 'USER'))
40
+ end
41
+ it 'sets transaction name' do
42
+ expect(::NewRelic::Agent).to receive(:set_transaction_name).with('MyOperatorClass/+')
43
+
44
+ subject.call(client, Slack::Messages::Message.new(message: 'message',
45
+ text: '+42',
46
+ team: 'TEAM',
47
+ channel: 'CHANNEL',
48
+ user: 'USER'))
49
+ end
50
+ end
51
+
52
+ context 'command' do
53
+ before(:all) do
54
+ MyCommandClass = Class.new(SlackRubyBot::Commands::Base) do
55
+ command('this') { |_client, _data, _match| }
56
+ end
57
+ end
58
+ it 'adds team, channel, user, and match attributes' do
59
+ expect(::NewRelic::Agent)
60
+ .to receive(:add_custom_attributes)
61
+ .with(hash_including(team: 'TEAM', channel: 'CHANNEL', user: 'USER'))
62
+ expect(::NewRelic::Agent)
63
+ .to receive(:add_custom_attributes)
64
+ .with(hash_including(bot: 'mybot', command: 'this', expression: 'is the command'))
65
+
66
+ subject.call(client, Slack::Messages::Message.new(message: 'message',
67
+ text: "#{client.name} this is the command",
68
+ team: 'TEAM',
69
+ channel: 'CHANNEL',
70
+ user: 'USER'))
71
+ end
72
+ it 'sets transaction name' do
73
+ expect(::NewRelic::Agent).to receive(:set_transaction_name).with('MyCommandClass/this')
74
+
75
+ subject.call(client, Slack::Messages::Message.new(message: 'message',
76
+ text: "#{client.name} this is the command",
77
+ team: 'TEAM',
78
+ channel: 'CHANNEL',
79
+ user: 'USER'))
80
+ end
81
+ end
82
+
83
+ context 'match' do
84
+ before(:all) do
85
+ MyMatchClass = Class.new(SlackRubyBot::Commands::Base) do
86
+ match('read this') { |_client, _data, _match| }
87
+ end
88
+ end
89
+ it 'adds team, channel, user, and match attributes' do
90
+ expect(::NewRelic::Agent)
91
+ .to receive(:add_custom_attributes)
92
+ .with(hash_including(team: 'TEAM', channel: 'CHANNEL', user: 'USER'))
93
+ expect(::NewRelic::Agent).to receive(:add_custom_attributes).with({})
94
+
95
+ subject.call(client, Slack::Messages::Message.new(message: 'message',
96
+ text: 'read this',
97
+ team: 'TEAM',
98
+ channel: 'CHANNEL',
99
+ user: 'USER'))
100
+ end
101
+ it 'sets transaction name' do
102
+ expect(::NewRelic::Agent).to receive(:set_transaction_name).with('MyMatchClass/match')
103
+
104
+ subject.call(client, Slack::Messages::Message.new(message: 'message',
105
+ text: 'read this',
106
+ team: 'TEAM',
107
+ channel: 'CHANNEL',
108
+ user: 'USER'))
109
+ end
110
+ end
111
+
112
+ context 'scan' do
113
+ before(:all) do
114
+ MyScanClass = Class.new(SlackRubyBot::Commands::Base) do
115
+ scan('scanned') { |_client, _data, _match| }
116
+ end
117
+ end
118
+ it 'adds team, channel, user, and match attributes' do
119
+ expect(::NewRelic::Agent)
120
+ .to receive(:add_custom_attributes)
121
+ .with(hash_including(team: 'TEAM', channel: 'CHANNEL', user: 'USER'))
122
+ expect(::NewRelic::Agent).not_to receive(:add_custom_attributes)
123
+
124
+ subject.call(client, Slack::Messages::Message.new(message: 'message',
125
+ text: 'I scanned this',
126
+ team: 'TEAM',
127
+ channel: 'CHANNEL',
128
+ user: 'USER'))
129
+ end
130
+ it 'sets transaction name' do
131
+ expect(::NewRelic::Agent).to receive(:set_transaction_name).with('MyScanClass/scan')
132
+
133
+ subject.call(client, Slack::Messages::Message.new(message: 'message',
134
+ text: 'I scanned this',
135
+ team: 'TEAM',
136
+ channel: 'CHANNEL',
137
+ user: 'USER'))
138
+ end
14
139
  end
15
140
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newrelic-slack-ruby-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-27 00:00:00.000000000 Z
11
+ date: 2017-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: newrelic_rpm
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.8.0
33
+ version: 0.10.5
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.8.0
40
+ version: 0.10.5
41
41
  description:
42
42
  email: dblock@dblock.org
43
43
  executables: []
@@ -57,7 +57,9 @@ files:
57
57
  - lib/newrelic-slack-ruby-bot/version.rb
58
58
  - newrelic-slack-ruby-bot.gemspec
59
59
  - pkg/newrelic-slack-ruby-bot-0.1.1.gem
60
- - screenshots/breakdown.png
60
+ - pkg/newrelic-slack-ruby-bot-0.2.0.gem
61
+ - screenshots/newrelic_calculate_breakdown.png
62
+ - screenshots/newrelic_transactions.png
61
63
  - spec/newrelic-slack-ruby-bot/instrumentation_spec.rb
62
64
  - spec/newrelic-slack-ruby-bot/version_spec.rb
63
65
  - spec/spec_helper.rb
Binary file