datadog_apm 0.9.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: 39f3698fb3ea1e3ffe0799f4dae4dffa2fe684a7
4
+ data.tar.gz: 7fb7cdf9c946a922583213551ddf9db0fafcb698
5
+ SHA512:
6
+ metadata.gz: 88aed3c9f25baa9fdd1fbd763e44d45272e27724e4c132769e789bd940fe7430a244c953399ae05752df489aa7e0480eaa556df3a810c9e2c39110fc6b38c2bb
7
+ data.tar.gz: ceddc892ae8d372e504476b6d82f1d5f5df070d3be19843b9253518eaa5ddaaf8c343ae0c0b43f3e0c6dbdc01e09a7823f59c4b1c36fdc2c9516e4390045e4cd
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .idea/
6
+ .yardoc
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in datadoge.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ datadoge (0.0.3)
5
+ dogstatsd-ruby (> 0)
6
+ gem_config (~> 0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ dogstatsd-ruby (1.5.0)
12
+ gem_config (0.3.1)
13
+ rake (0.9.6)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ bundler (~> 1.6)
20
+ datadoge!
21
+ rake (~> 0)
22
+
23
+ BUNDLED WITH
24
+ 1.10.6
data/LICENSE.txt ADDED
@@ -0,0 +1,11 @@
1
+ Licensed under the Apache License, Version 2.0 (the "License");
2
+ you may not use this file except in compliance with the License.
3
+ You may obtain a copy of the License at
4
+
5
+ http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # DatadogApm
2
+
3
+ This gem is notified of basic performance metrics for a Rails application, and sends the measurements to DataDog.
4
+
5
+ ## Installation
6
+
7
+ Install the [Datadog Agent](https://app.datadoghq.com/account/settings#agent) on your application server. This gem only
8
+ works on servers which have the Datadog Agent installed.
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'datadog_apm'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install datadog_apm
21
+
22
+ ## Usage
23
+
24
+ By default, performance metrics are only reported to Datadog from production environments which have the
25
+ [Datadog agent](https://app.datadoghq.com/account/settings#agent) installed.
26
+
27
+ To enable Datadog reporting in non-production environments, add the following to an initializer:
28
+
29
+ DatadogApm.configure do |config|
30
+ config.environments = ['staging', 'production']
31
+ end
32
+
33
+ To add additional tags, add the following to the configuration:
34
+
35
+ config.tags = ['role:myapp', 'host:myapp-1', 'region:east']
36
+
37
+ Override the default metric name with the following configuration:
38
+
39
+ config.metric = :apm
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( https://github.com/johnpipi/datadog_apm/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'datadog_apm/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'datadog_apm'
8
+ spec.version = DatadogApm::VERSION
9
+ spec.authors = ['John Peterson']
10
+ spec.email = ['johnpipi@gmail.com']
11
+ spec.summary = 'A simple integration of Datadog to report on Rails application performance.'
12
+ spec.description = 'This gem is notified of basic performance metrics for a Rails application, and sends the measurements to Datadog.'
13
+ spec.homepage = ''
14
+ spec.license = 'Apache'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'rake', '~> 0'
23
+
24
+ spec.add_runtime_dependency 'dogstatsd-ruby', "> 0"
25
+ spec.add_runtime_dependency 'gem_config', '~> 0'
26
+ end
@@ -0,0 +1,78 @@
1
+ require 'datadog_apm/version'
2
+ require 'gem_config'
3
+ require 'statsd'
4
+
5
+ module DatadogApm
6
+ include GemConfig::Base
7
+
8
+ with_configuration do
9
+ has :environments, classes: Array, default: ['production']
10
+ has :tags, classes: Array, default: []
11
+ has :metric, classes: [Symbol, String], default: 'apm'
12
+ has :slow_query_max_duration, classes: [Float], default: 2.0
13
+ end
14
+
15
+ class Railtie < Rails::Railtie
16
+ initializer "datadoge.configure_rails_initialization" do |app|
17
+ $statsd = Statsd.new
18
+
19
+ ActiveSupport::Notifications.subscribe /process_action.action_controller/ do |*args|
20
+ event = ActiveSupport::Notifications::Event.new(*args)
21
+ controller = "controller:#{event.payload[:controller]}"
22
+ action = "action:#{event.payload[:action]}"
23
+ controller_action = "controller_action:#{event.payload[:controller]}##{event.payload[:action]}"
24
+ format = "format:#{event.payload[:format] || 'all'}"
25
+ format = "format:all" if format == "format:*/*"
26
+ status = event.payload[:status]
27
+ #Rails.logger.error "payload@@: #{event.inspect}"
28
+ tags = DatadogApm.configuration.tags + [controller, action, controller_action, format, "request.status.#{status}", "request.method.#{event.payload[:method]}"]
29
+ ActiveSupport::Notifications.instrument :performance, :action => :timing, :tags => tags, :measurement => "request.total_duration", :value => event.duration
30
+ ActiveSupport::Notifications.instrument :performance, :action => :timing, :tags => tags, :measurement => "database.query.time", :value => event.payload[:db_runtime]
31
+ ActiveSupport::Notifications.instrument :performance, :action => :timing, :tags => tags, :measurement => "web.view.time", :value => event.payload[:view_runtime]
32
+ ActiveSupport::Notifications.instrument :performance, :action => :timing, :tags => tags, :measurement => "elasticsearch.query.time", :value => event.payload[:elasticsearch_runtime]
33
+ ActiveSupport::Notifications.instrument :performance, :tags => tags, :measurement => "request.status.#{status}"
34
+ ActiveSupport::Notifications.instrument :performance, :tags => tags, :measurement => "request.method.#{event.payload[:method]}"
35
+ end
36
+
37
+ ActiveSupport::Notifications.subscribe('sql.active_record') do |name, start, finish, id, payload|
38
+ duration = finish.to_f - start.to_f
39
+ if duration >= DatadogApm.configuration.slow_query_max_duration.to_f
40
+ if !payload[:sql].starts_with?("EXPLAIN", "SHOW")
41
+ ActiveRecord::Base.connection.execute("EXPLAIN #{payload[:sql]}").each(:as => :hash) do |row|
42
+ #{"id"=>1, "select_type"=>"SIMPLE", "table"=>"currencies", "partitions"=>nil, "type"=>"const", "possible_keys"=>"PRIMARY", "key"=>"PRIMARY", "key_len"=>"4", "ref"=>"const", "rows"=>1, "filtered"=>100.0, "Extra"=>nil}
43
+ message = {
44
+ sql: payload[:sql].gsub("\n", ""),
45
+ select_type: row["select_type"],
46
+ table: row["table"],
47
+ possible_keys: row["possible_keys"],
48
+ key: row["key"],
49
+ key_len: row["key_len"],
50
+ rows: row["rows"],
51
+ filtered: row["filtered"]
52
+ }.map{ |k, v| "#{k} = #{v}" }.join('\n')
53
+ $statsd.event("SQL Slow Query: #{duration} >= #{DatadogApm.configuration.slow_query_max_duration.to_f}", message, :tags => DatadogApm.configuration.tags) unless $statsd.nil?
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ ActiveSupport::Notifications.subscribe /performance/ do |name, start, finish, id, payload|
60
+ send_event_to_statsd(name, payload) if DatadogApm.configuration.environments.include?(Rails.env)
61
+ end
62
+
63
+ def send_event_to_statsd(name, payload)
64
+ action = payload[:action] || :increment
65
+ measurement = payload[:measurement]
66
+ value = payload[:value]
67
+ tags = payload[:tags]
68
+ key_name = "#{DatadogApm.configuration.metric.to_s}.#{measurement}"
69
+ if action == :increment
70
+ $statsd.increment key_name, :tags => tags unless $statsd.nil?
71
+ else
72
+ $statsd.histogram key_name, value, :tags => tags unless $statsd.nil?
73
+ end
74
+ end
75
+
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,3 @@
1
+ module DatadogApm
2
+ VERSION = "0.9.0"
3
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: datadog_apm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - John Peterson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: dogstatsd-ruby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: gem_config
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: This gem is notified of basic performance metrics for a Rails application,
70
+ and sends the measurements to Datadog.
71
+ email:
72
+ - johnpipi@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - datadog_apm.gemspec
84
+ - lib/datadog_apm.rb
85
+ - lib/datadog_apm/version.rb
86
+ homepage: ''
87
+ licenses:
88
+ - Apache
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.4.5.1
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: A simple integration of Datadog to report on Rails application performance.
110
+ test_files: []