newrelic-sequel 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,34 @@
1
+ Newrelic Sequel
2
+ ===============
3
+ **Sequel instrumentation for Newrelic.**
4
+
5
+ Usage
6
+ -----
7
+
8
+ 1. Install gem
9
+
10
+ >gem install newrelic-sequel
11
+
12
+ 2. Config dependencies in application.rb
13
+
14
+ >config.gem "rpm_contrib"
15
+ >
16
+ >config.gem "newrelic_rpm"
17
+
18
+ Dependencies
19
+ ------------
20
+
21
+ 1. rpm_contrib
22
+ 2. newrelic_rpm > 3.0
23
+ 3. sequel > 3.22
24
+
25
+ License
26
+ -------
27
+
28
+ Copyright (C) 2012 REA Group Ltd.
29
+
30
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
31
+
32
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
33
+
34
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ require 'newrelic_sequel/sequel'
@@ -0,0 +1,109 @@
1
+ DependencyDetection.defer do
2
+ depends_on do
3
+ defined?(::Sequel)
4
+ end
5
+
6
+ depends_on do
7
+ begin
8
+ (Sequel::MAJOR == 3 && Sequel::MINOR >= 22)
9
+ rescue Exception => e
10
+ false
11
+ end
12
+ end
13
+
14
+ executes do
15
+ ::Sequel::Model::ClassMethods.class_eval do
16
+
17
+ add_method_tracer :[], 'ActiveRecord/#{self.name}/find'
18
+
19
+ add_method_tracer :all, 'ActiveRecord/#{self.name}/find'
20
+ add_method_tracer :each, 'ActiveRecord/#{self.name}/find'
21
+ add_method_tracer :create, 'ActiveRecord/#{self.name}/create'
22
+ add_method_tracer :insert, 'ActiveRecord/#{self.name}/create'
23
+ add_method_tracer :insert_multiple, 'ActiveRecord/#{self.name}/create'
24
+ add_method_tracer :import, 'ActiveRecord/#{self.name}/create'
25
+ add_method_tracer :update, 'ActiveRecord/#{self.name}/update'
26
+ add_method_tracer :delete, 'ActiveRecord/#{self.name}/delete'
27
+
28
+ end
29
+
30
+ ::Sequel::Model::InstanceMethods.class_eval do
31
+
32
+ add_method_tracer :_insert, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/create'
33
+ add_method_tracer :_update, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/update'
34
+ add_method_tracer :_delete, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/destroy'
35
+
36
+ end
37
+
38
+ ::Sequel::Dataset.class_eval do
39
+
40
+ add_method_tracer :execute, 'ActiveRecord/#{self.respond_to?(:model) ? self.model.name : "Dataset"}/find'
41
+ add_method_tracer :execute_insert, 'ActiveRecord/#{self.respond_to?(:model) ? self.model.name : "Dataset"}/create'
42
+ add_method_tracer :execute_dui, 'ActiveRecord/#{self.respond_to?(:model) ? self.model.name : "Dataset"}/update'
43
+ add_method_tracer :execute_ddl, 'ActiveRecord/#{self.respond_to?(:model) ? self.model.name : "Dataset"}/all'
44
+
45
+ end
46
+
47
+ ::Sequel::Database.class_eval do
48
+
49
+ add_method_tracer :execute, 'ActiveRecord/Database/find'
50
+ add_method_tracer :execute_insert, 'ActiveRecord/Database/create'
51
+ add_method_tracer :execute_dui, 'ActiveRecord/Database/update'
52
+ add_method_tracer :execute_ddl, 'ActiveRecord/Database/all'
53
+
54
+ end
55
+ end
56
+ end
57
+
58
+
59
+ module NewRelic
60
+ module Agent
61
+ module Instrumentation
62
+ module SequelInstrumentation
63
+ def self.included(klass)
64
+ klass.class_eval do
65
+ alias_method :log_duration_without_newrelic_instrumentation, :log_duration
66
+ alias_method :log_duration, :log_duration_with_newrelic_instrumentation
67
+ end
68
+ end
69
+
70
+ def log_duration_with_newrelic_instrumentation(duration, sql)
71
+ return unless NewRelic::Agent.is_execution_traced?
72
+ return unless operation = case sql
73
+ when /^\s*select/i then
74
+ 'find'
75
+ when /^\s*(update|insert)/i then
76
+ 'save'
77
+ when /^\s*delete/i then
78
+ 'destroy'
79
+ else
80
+ nil
81
+ end
82
+
83
+ NewRelic::Agent.instance.transaction_sampler.notice_sql(sql, nil, duration)
84
+
85
+ metrics = ["ActiveRecord/#{operation}", 'ActiveRecord/all']
86
+ metrics.each do |metric|
87
+ NewRelic::Agent.instance.stats_engine.get_stats_no_scope(metric).trace_call(duration)
88
+ end
89
+ ensure
90
+ log_duration_without_newrelic_instrumentation(duration, sql)
91
+ end
92
+
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ DependencyDetection.defer do
99
+ depends_on do
100
+ defined?(::Sequel) && defined?(::Sequel::Database)
101
+ end
102
+
103
+ executes do
104
+ ::Sequel::Database.class_eval do
105
+ include ::NewRelic::Agent::Instrumentation::SequelInstrumentation
106
+ end
107
+ end
108
+ end
109
+
@@ -0,0 +1,3 @@
1
+ class NewRelicSequel
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "newrelic-sequel"
5
+ s.version = "0.0.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["REA Group"]
9
+ s.date = "2012-05-30"
10
+ s.description = "Sequel instrumentation for Newrelic."
11
+ s.email = ["yong.fu@rea-group.com", "wei.guangcheng@rea-group.com"]
12
+ s.extra_rdoc_files = ["README.markdown"]
13
+ s.files = ["README.markdown", "lib/newrelic-sequel.rb", "lib/newrelic_sequel/sequel.rb", "lib/newrelic_sequel/version.rb", "newrelic-sequel.gemspec"]
14
+ s.homepage = "https://github.com/realestate-com-au/newrelic-sequel"
15
+ s.require_paths = ["lib"]
16
+ s.rubygems_version = "1.8.22"
17
+ s.summary = "Sequel instrumentation for Newrelic."
18
+
19
+ if s.respond_to? :specification_version then
20
+ s.specification_version = 3
21
+
22
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
23
+ s.add_runtime_dependency(%q<sequel>, ["> 3.22"])
24
+ s.add_runtime_dependency(%q<newrelic_rpm>, ["~> 3.0"])
25
+ s.add_development_dependency(%q<rdoc>, ["~> 3.10"])
26
+ s.add_development_dependency(%q<hoe>, ["~> 2.16"])
27
+ else
28
+ s.add_dependency(%q<sequel>, ["> 3.22"])
29
+ s.add_dependency(%q<newrelic_rpm>, ["~> 3.0"])
30
+ s.add_dependency(%q<rdoc>, ["~> 3.10"])
31
+ s.add_dependency(%q<hoe>, ["~> 2.16"])
32
+ end
33
+ else
34
+ s.add_dependency(%q<sequel>, ["> 3.22"])
35
+ s.add_dependency(%q<newrelic_rpm>, ["~> 3.0"])
36
+ s.add_dependency(%q<rdoc>, ["~> 3.10"])
37
+ s.add_dependency(%q<hoe>, ["~> 2.16"])
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: newrelic-sequel
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - REA Group
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-05-30 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: sequel
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">"
27
+ - !ruby/object:Gem::Version
28
+ hash: 43
29
+ segments:
30
+ - 3
31
+ - 22
32
+ version: "3.22"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: newrelic_rpm
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 7
44
+ segments:
45
+ - 3
46
+ - 0
47
+ version: "3.0"
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rdoc
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 19
59
+ segments:
60
+ - 3
61
+ - 10
62
+ version: "3.10"
63
+ type: :development
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: hoe
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ hash: 35
74
+ segments:
75
+ - 2
76
+ - 16
77
+ version: "2.16"
78
+ type: :development
79
+ version_requirements: *id004
80
+ description: Sequel instrumentation for Newrelic.
81
+ email:
82
+ - yong.fu@rea-group.com
83
+ - wei.guangcheng@rea-group.com
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files:
89
+ - README.markdown
90
+ files:
91
+ - README.markdown
92
+ - lib/newrelic-sequel.rb
93
+ - lib/newrelic_sequel/sequel.rb
94
+ - lib/newrelic_sequel/version.rb
95
+ - newrelic-sequel.gemspec
96
+ homepage: https://github.com/realestate-com-au/newrelic-sequel
97
+ licenses: []
98
+
99
+ post_install_message:
100
+ rdoc_options: []
101
+
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ requirements: []
123
+
124
+ rubyforge_project:
125
+ rubygems_version: 1.8.10
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: Sequel instrumentation for Newrelic.
129
+ test_files: []
130
+