card-mod-new_relic 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9d5ae87a5aa454d6e841898a99d92e42aac6203e9539b80f9538ee038d42cc3c
4
+ data.tar.gz: 252bf0a2edb83784da2c1d4d96fd06f83cca84db549b1d870886bdf67d065f14
5
+ SHA512:
6
+ metadata.gz: cbf91735500f0d5bb74bb81abe50bd15ad42601c88b2a1998a59d9a25cf6849461230761930c8d1ad144b5f76ce4eed1117ad7b98b32404ddce66f6610b839fb
7
+ data.tar.gz: 2c82dd418cf0caaf9cfd153089ca55e0ad18fe072afb3281658cc4edba5e3582ec13b3131937d83304ce77b29db1045fe217470bb23b01bcd7611f15966b0595
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ <!--
2
+ # @title README - mod: new relic
3
+ -->
4
+
5
+ # NewRelic mod (experimental)
6
+
7
+ NewRelic is a sophisticated web-based performance tracking tool.
8
+
9
+ This mod supports integration with NewRelic by adding tracers for important
10
+ methods like `Card#fetch`, `Format#final_render`, `Card::Query.new`,
11
+ `Voo.process`, and for action events.
12
+
13
+ There are also _many_ other tracers not activated but that can easily be
14
+ copied from the source code here and reused in a local mod.
15
+
16
+ To attach this mod to your NewRelic account, add a `newrelic.yml` file in the
17
+ deck's `config` directory.
18
+
19
+ For full documentation of agent configuration options, please refer to
20
+ https://docs.newrelic.com/docs/agents/ruby-agent/installation-configuration/ruby-agent-configuration
@@ -0,0 +1 @@
1
+ require "newrelic_rpm"
data/set/all/cache.rb ADDED
@@ -0,0 +1,4 @@
1
+ # module ClassMethods
2
+ # include ::NewRelic::Agent::MethodTracer
3
+ # add_method_tracer :write_to_cache, "Custom/Card/write_to_cache"
4
+ # end
data/set/all/fetch.rb ADDED
@@ -0,0 +1,4 @@
1
+ module ClassMethods
2
+ include ::NewRelic::Agent::MethodTracer
3
+ add_method_tracer :fetch, "Custom/Card/fetch"
4
+ end
@@ -0,0 +1,2 @@
1
+ # include ::NewRelic::Agent::MethodTracer
2
+ # add_method_tracer :include_set_modules, "Custom/Card/include_set_modules"
@@ -0,0 +1,88 @@
1
+ event :new_relic_act_transaction, after: :act, when: :new_relic_tracking? do
2
+ add_new_relic_card_attributes
3
+ add_new_relic_act_attributes unless @action == :read
4
+ name_new_relic_transaction new_relic_transaction_name_parts, category: :controller
5
+ end
6
+
7
+ event :notify_new_relic, after: :notable_exception_raised, when: :new_relic_tracking? do
8
+ ::NewRelic::Agent.notice_error Card::Error.current
9
+ end
10
+
11
+ event :new_relic_act_start, before: :act, when: :new_relic_tracking? do
12
+ @act_start = Time.now
13
+ end
14
+
15
+ ::Card::Set::Event::IntegrateWithDelayJob.after_perform do |job|
16
+ Director.contextualize_delayed_event *job.arguments[0..3] do
17
+ card = job.arguments[1]
18
+ card&.track_delayed_job job
19
+ end
20
+ end
21
+
22
+ # for override. cards with same label are grouped in new relic reporting
23
+ def new_relic_label
24
+ type_code
25
+ end
26
+
27
+ def new_relic_tracking?
28
+ Rails.env.production?
29
+ end
30
+
31
+ def track_delayed_job job
32
+ name_new_relic_transaction ["delayed-#{job.queue_name}"]
33
+ add_new_relic_card_attributes
34
+ add_new_relic_act_attributes time=false
35
+ end
36
+
37
+ private
38
+
39
+ def new_relic_transaction_name_parts
40
+ controller = Env[:controller]
41
+ parts = [controller&.action_name, new_relic_label]
42
+ return parts unless @action == :read
43
+
44
+ parts << controller&.response_format
45
+ end
46
+
47
+ def name_new_relic_transaction name_parts, args={}
48
+ name = Array.wrap(name_parts).compact.map(&:to_s).join "-"
49
+ ::NewRelic::Agent.set_transaction_name name, args
50
+ end
51
+
52
+ def add_new_relic_card_attributes
53
+ ::NewRelic::Agent.add_custom_attributes(
54
+ card: { type: type_code, name: name },
55
+ user: { roles: all_roles.join(", ") }
56
+ )
57
+ end
58
+
59
+ def add_new_relic_act_attributes time=true
60
+ args = { act: { actions: action_names_for_new_relic } }
61
+ args[:time_from_start] = "#{(Time.now - @act_start) * 1000} ms" if time
62
+ ::NewRelic::Agent.add_custom_attributes args
63
+ end
64
+
65
+ def action_names_for_new_relic
66
+ return unless (actions = Director.act&.actions(false))
67
+ actions.map(&:card).compact.map &:name
68
+ end
69
+
70
+ # test new relic custom metrics
71
+ # module ::ActiveRecord::ConnectionAdapters
72
+ # class AbstractMysqlAdapter
73
+ # unless method_defined? :new_relic_execute
74
+ # alias_method :new_relic_execute, :execute
75
+ # def execute sql, name=nil
76
+ # result, duration = count_ms { original_execute(sql, name) }
77
+ # ::NewRelic::Agent.record_metric "Custom/Card/queries", duration
78
+ # result
79
+ # end
80
+ #
81
+ # def count_ms
82
+ # start = Time.now
83
+ # result = yield
84
+ # [result, (Time.now - start) * 1000]
85
+ # end
86
+ # end
87
+ # end
88
+ # end
@@ -0,0 +1,2 @@
1
+ # include ::NewRelic::Agent::MethodTracer
2
+ # add_method_tracer :set_modules, "Custom/Card/set_modules"
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: card-mod-new_relic
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Philipp Kühl
8
+ - Ethan McCutchen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2021-10-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: card
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: decko
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: newrelic_rpm
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: handle new relic integration with decko decks
57
+ email:
58
+ - info@decko.org
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - README.md
64
+ - lib/card/mod/new_relic.rb
65
+ - set/all/cache.rb
66
+ - set/all/fetch.rb
67
+ - set/all/initialize.rb
68
+ - set/all/new_relic.rb
69
+ - set/all/pattern.rb
70
+ homepage: http://decko.org
71
+ licenses:
72
+ - GPL-3.0
73
+ metadata:
74
+ card-mod: new_relic
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '2.5'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 3.2.28
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: new relic support for decko
94
+ test_files: []