dogstatsd-instrumentation 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 824f7af6b9721c4038b9f1ab00721721b86f1c94
4
+ data.tar.gz: 7a0698ce32f8396dcb5f8bfd47145d1dbcc9de27
5
+ SHA512:
6
+ metadata.gz: ef1309218bfec2701a2b211cb7ac2e4bc60d9d6248cdad28f8eab88d3bb1b96fcd0cbe15f08782d52ff2740732419489ffb0c1ed37d4e34c7e503f64a932d595
7
+ data.tar.gz: 9a15666e7859f8412d768f4261568c7125aa1633293cc5de1f8faa77079e86d18b5fdf5649b5722037e3d94a86c9196ec85e8c9567c35f7d799f53006319ebc1
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Wealthsimple
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # DogStatsd::Instrumentation
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/dogstatsd-instrumentation.svg)](http://badge.fury.io/rb/dogstatsd-instrumentation)
4
+ [![CircleCI](https://circleci.com/gh/wealthsimple/dogstatsd-instrumentation.svg?style=shield)](https://circleci.com/gh/wealthsimple/dogstatsd-instrumentation)
5
+ [![Dependency Status](https://gemnasium.com/badges/github.com/wealthsimple/dogstatsd-instrumentation.svg)](https://gemnasium.com/github.com/wealthsimple/dogstatsd-instrumentation)
6
+ [![Code Climate](https://codeclimate.com/github/wealthsimple/dogstatsd-instrumentation/badges/gpa.svg)](https://codeclimate.com/github/wealthsimple/dogstatsd-instrumentation)
7
+ [![codecov](https://codecov.io/gh/wealthsimple/dogstatsd-instrumentation/branch/master/graph/badge.svg)](https://codecov.io/gh/wealthsimple/dogstatsd-instrumentation)
8
+ [![Gitter chat](https://img.shields.io/gitter/room/wealthsimple/Lobby.svg?style=flat)](https://gitter.im/wealthsimple/Lobby)
9
+
10
+
11
+ <!-- Tocer[start]: Auto-generated, don't remove. -->
12
+
13
+ # Table of Contents
14
+
15
+ - [Features](#features)
16
+ - [Examples](#examples)
17
+ - [Requirements](#requirements)
18
+ - [Setup](#setup)
19
+ - [Tests](#tests)
20
+ - [Versioning](#versioning)
21
+ - [Code of Conduct](#code-of-conduct)
22
+ - [Contributions](#contributions)
23
+ - [License](#license)
24
+ - [History](#history)
25
+ - [Credits](#credits)
26
+
27
+ <!-- Tocer[finish]: Auto-generated, don't remove. -->
28
+
29
+ # Features
30
+
31
+ DogStatsd::Instrumentation collects various [ActiveSupport::Notifications](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html) and sends them to StatsD, more precisely, Datadog's DogStatsD.
32
+
33
+
34
+ ## Examples
35
+
36
+ # Requirements
37
+
38
+ 0. [Ruby 2.3.0](https://www.ruby-lang.org)
39
+
40
+ # Setup
41
+
42
+ For a secure install, type the following (recommended):
43
+
44
+ gem cert --add <(curl --location --silent /gem-public.pem)
45
+ gem install dogstatsd-instrumentation --trust-policy MediumSecurity
46
+
47
+ NOTE: A HighSecurity trust policy would be best but MediumSecurity enables signed gem verification
48
+ while allowing the installation of unsigned dependencies since they are beyond the scope of this
49
+ gem.
50
+
51
+ For an insecure install, type the following (not recommended):
52
+
53
+ gem install dogstatsd-instrumentation
54
+
55
+ Add the following to your Gemfile:
56
+
57
+ gem "dogstatsd-instrumentation"
58
+
59
+ # Tests
60
+
61
+ To test, run:
62
+
63
+ bundle exec rake
64
+
65
+ # Versioning
66
+
67
+ Read [Semantic Versioning](http://semver.org) for details. Briefly, it means:
68
+
69
+ - Patch (x.y.Z) - Incremented for small, backwards compatible, bug fixes.
70
+ - Minor (x.Y.z) - Incremented for new, backwards compatible, public API enhancements/fixes.
71
+ - Major (X.y.z) - Incremented for any backwards incompatible public API changes.
72
+
73
+ # Code of Conduct
74
+
75
+ Please note that this project is released with a [CODE OF CONDUCT](CODE_OF_CONDUCT.md). By
76
+ participating in this project you agree to abide by its terms.
77
+
78
+ # Contributions
79
+
80
+ Read [CONTRIBUTING](CONTRIBUTING.md) for details.
81
+
82
+ # License
83
+
84
+ [MIT License](LICENSE.md)
85
+
86
+ Copyright (c) 2016 [Wealthsimple](https://wealthsimple.com).
87
+
88
+ # History
89
+
90
+ Read [CHANGES](CHANGES.md) for details.
91
+ Built with [Gemsmith](https://github.com/bkuhlmann/gemsmith).
92
+
93
+ # Credits
94
+
95
+ Developed by [Marco Costa](http://marcotc.com) at [Wealthsimple](https://wealthsimple.com).
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dogstatsd/instrumentation/identity"
4
+ require "dogstatsd/instrumentation/request"
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DogStatsd
4
+ module Instrumentation
5
+ # Gem identity information.
6
+ module Identity
7
+ def self.name
8
+ "dogstatsd-instrumentation"
9
+ end
10
+
11
+ def self.label
12
+ "DogStatsd::Instrumentation"
13
+ end
14
+
15
+ def self.version
16
+ "0.1.0"
17
+ end
18
+
19
+ def self.version_label
20
+ "#{label} #{version}"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+ require 'gem_config'
5
+ require 'datadog/statsd'
6
+
7
+ module DogStatsd
8
+ module Instrumentation
9
+ module Request
10
+ include GemConfig::Base
11
+
12
+ with_configuration do
13
+ has :environments, classes: Array, default: ['production']
14
+ has :host, classes: String, default: Datadog::Statsd::DEFAULT_HOST
15
+ has :port, classes: Integer, default: Datadog::Statsd::DEFAULT_PORT
16
+ has :opts, classes: Hash, default: {}
17
+ has :max_buffer_size, classes: Integer, default: 50
18
+ end
19
+
20
+ # From GemConfig::Base
21
+ def self.configure
22
+ super
23
+ @@subscriber.unsubscribe if @@subscriber
24
+ @@subscriber = Subscriber.new(configuration)
25
+ end
26
+
27
+ @@subscriber = nil
28
+
29
+ class Subscriber
30
+ def initialize(configuration)
31
+ @statsd = Datadog::Statsd.new(
32
+ configuration.host,
33
+ configuration.port,
34
+ configuration.opts,
35
+ configuration.max_buffer_size
36
+ )
37
+
38
+ @subscriber = ActiveSupport::Notifications.subscribe /process_action.action_controller/ do |*args|
39
+ event = ActiveSupport::Notifications::Event.new(*args)
40
+ tags = {
41
+ controller: event.payload[:controller],
42
+ action: event.payload[:action],
43
+ method: event.payload[:method],
44
+ status: event.payload[:status],
45
+ }
46
+
47
+ instrument stat: 'process_action.action_controller.duration', value: event.duration, tags: tags
48
+
49
+ event.payload.select { |key, _| key.to_s.end_with? '_runtime' }.each do |name, duration|
50
+ instrument stat: "process_action.action_controller.#{name}", value: duration, tags: tags
51
+ end
52
+ end
53
+ end
54
+
55
+ def instrument(stat:, value:, tags:)
56
+ @statsd.histogram stat, value, tags: tagify(tags)
57
+ end
58
+
59
+ def tagify(hash)
60
+ hash.select{|_,value| value.present? }.map { |key, value| "#{key}:#{value}" }
61
+ end
62
+
63
+ def unsubscribe
64
+ ActiveSupport::Notifications.unsubscribe @subscriber
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "reek/rake/task"
5
+ Reek::Rake::Task.new
6
+ rescue LoadError => error
7
+ puts error.message
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "rspec/core/rake_task"
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ rescue LoadError => error
7
+ puts error.message
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "rubocop/rake_task"
5
+ RuboCop::RakeTask.new
6
+ rescue LoadError => error
7
+ puts error.message
8
+ end
metadata ADDED
@@ -0,0 +1,209 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dogstatsd-instrumentation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marco Costa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dogstatsd-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: gem_config
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '11.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '11.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: gemsmith
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '8.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '8.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-state
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.5'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.5'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '4.7'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '4.7'
139
+ - !ruby/object:Gem::Dependency
140
+ name: reek
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '4.5'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '4.5'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.45'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.45'
167
+ description: This gem processes relevant ActiveSupport::Notifications for Rails, Sinatra
168
+ and Rake applications, sending metrics to Datadog.
169
+ email:
170
+ - marco@marcotc.com
171
+ executables: []
172
+ extensions: []
173
+ extra_rdoc_files:
174
+ - README.md
175
+ - LICENSE.md
176
+ files:
177
+ - LICENSE.md
178
+ - README.md
179
+ - lib/dogstatsd/instrumentation.rb
180
+ - lib/dogstatsd/instrumentation/identity.rb
181
+ - lib/dogstatsd/instrumentation/request.rb
182
+ - lib/tasks/reek.rake
183
+ - lib/tasks/rspec.rake
184
+ - lib/tasks/rubocop.rake
185
+ homepage: https://github.com/wealthsimple/dogstatsd-instrumentation
186
+ licenses:
187
+ - MIT
188
+ metadata: {}
189
+ post_install_message:
190
+ rdoc_options: []
191
+ require_paths:
192
+ - lib
193
+ required_ruby_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ required_rubygems_version: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ requirements: []
204
+ rubyforge_project:
205
+ rubygems_version: 2.5.1
206
+ signing_key:
207
+ specification_version: 4
208
+ summary: Reports instrumention metrics from various Ruby web frameworks to Datadog.
209
+ test_files: []