stackify-ruby-apm 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5644c5079318a7c3529770465f45372106c02a8334b4648880cee789495c9a17
4
- data.tar.gz: 6309a247094d7795b7abf970bf7ca46c3ea6a499de6aa03cb8b92c22080ee191
3
+ metadata.gz: 9e21411e3d9be64aa1c8907e09552f6aac44ecf712e59065d1a1156381c9a278
4
+ data.tar.gz: a0b0aaa469349611840c4b222c920a87253678ab1d681969f4a5b5804cb40515
5
5
  SHA512:
6
- metadata.gz: b3ebbe0dc60d749aa5cffde012ac3f5fa815fd3b1a52c110fc9ff213ab7252a69a1d43dc951f3578c725cfdc32e29b3b1a1f59666293357c3f86deabefd6b5f5
7
- data.tar.gz: 97a7f413c89124d246d4c499c8fada9e6c2373a21adc3e096fcce9c8dadd1cb0e32e55b300cbe1c4c3a633711444ef3822796596047cf2b25629f7fc00d1b0fa
6
+ metadata.gz: 61300001e05eb6eb32b0adfb66eead66dac56eea502fb1f64da60cfcdc51c5d33bf96f284f433441adb2488779f709307d9c05d5fc97c8271114dbf155be5413
7
+ data.tar.gz: ebd7cc6ff9e131f89ff38152135fc82eb22b8955ec417959edb4bfa63843cfbc2fce4608e8241d14832b43dc88e24dbc1c096ea2789e1cfd7d7323ea0c8eb61b
data/README.md CHANGED
@@ -26,8 +26,24 @@
26
26
  5. Build/Deploy your application
27
27
 
28
28
  ### Custom Instrumentation in Rails
29
-
30
- In the config/initializer folder of your Rails app create a file `config/initializer/stackify.rb` and then add this configuration
29
+ 1. Create `config/stackify.json` file from the root of your app and place the class name and method name in which you want to instrument.
30
+
31
+ Example stackify.json:
32
+ ```
33
+ {
34
+ "instrumentation": [
35
+ {
36
+ "class": "<class name>",
37
+ "method": "<method name>",
38
+ "trackedFunctionName": "{{ClassName}}#{{MethodName}}",
39
+ "trackedFunction": <true or false>,
40
+ "transaction": <true or false>
41
+ }
42
+ ]
43
+ }
44
+ ```
45
+
46
+ 2. In the config/initializer folder of your Rails app create a file `config/initializer/stackify.rb` and then add this configuration
31
47
 
32
48
  Rails.configuration.to_prepare do
33
49
  StackifyRubyAPM.run_custom_instrument
@@ -64,8 +80,24 @@ In the config/initializer folder of your Rails app create a file `config/initial
64
80
  6. Build/Deploy your application
65
81
 
66
82
  ### Custom Instrumentation in Non-Rails
67
-
68
- In `config.ru` file add this line: StackifyRubyAPM.run_custom_instrument
83
+ 1. Create `config/stackify.json` file from the root of your app and place the class name and method name in which you want to instrument.
84
+
85
+ Example stackify.json:
86
+ ```
87
+ {
88
+ "instrumentation": [
89
+ {
90
+ "class": "<class name>",
91
+ "method": "<method name>",
92
+ "trackedFunctionName": "{{ClassName}}#{{MethodName}}",
93
+ "trackedFunction": <true or false>,
94
+ "transaction": <true or false>
95
+ }
96
+ ]
97
+ }
98
+ ```
99
+
100
+ 2. In `config.ru` file add this line: StackifyRubyAPM.run_custom_instrument
69
101
 
70
102
  Example:
71
103
 
@@ -12,6 +12,7 @@ module StackifyRubyAPM
12
12
  attr_accessor :custom_instrumented, :custom_class_info
13
13
  @custom_instrumented = {}
14
14
  @custom_class_info = {}
15
+ TRACETYPE = 'TASK'.freeze
15
16
 
16
17
  def self.custom_instrumented_reset
17
18
  @custom_instrumented.each do |custom_instrument, values|
@@ -26,7 +27,10 @@ module StackifyRubyAPM
26
27
  end
27
28
  end
28
29
 
29
- def self.m_class(tracked_func, current_class, class_path, current_method, tracked_function_name)
30
+ def self.m_class(tracked_func, current_class, class_path, **options)
31
+ current_method = options[:current_method] || nil
32
+ tracked_function_name = options[:tracked_function_name] || nil
33
+ transaction = options[:is_transaction] || nil
30
34
  module_consget = Module.const_get(current_class)
31
35
  classspyitem = "#{current_class}Spy"
32
36
  module_consget_spy = Module.const_get(current_class)
@@ -61,24 +65,37 @@ module StackifyRubyAPM
61
65
  alias_method "#{current_method_without}", "#{current_method}"
62
66
 
63
67
  def #{current_method}(*args, &block)
64
- return #{current_method_without}(*args, &block) unless StackifyRubyAPM.current_transaction
65
-
66
- name = "Custom Instrument"
67
- type = "#{current_class}##{current_method}"
68
- ctx = if "#{tracked_func}" == 'true'
69
- Span::Context.new(
70
- CATEGORY: 'Ruby',
71
- TRACKED_FUNC: "#{tracked_function_name}"
72
- )
73
- else
74
- Span::Context.new(
75
- CATEGORY: 'Ruby'
76
- )
77
- end
78
-
79
- req = #{current_method_without}(*args, &block)
80
- StackifyRubyAPM.span name, type, context: ctx do
68
+ if StackifyRubyAPM.current_transaction.nil? && #{!transaction.nil?}
69
+ t = StackifyRubyAPM.transaction("custom.#{current_class}.#{current_method}", TRACETYPE)
70
+ begin
71
+ req = #{current_method_without}(*args, &block)
72
+ rescue Exception => e
73
+ StackifyRubyAPM.report(e)
74
+ raise e
75
+ ensure
76
+ t.submit
77
+ end
78
+ return req
79
+ elsif StackifyRubyAPM.current_transaction
80
+ name = "Custom Instrument"
81
+ type = "#{current_class}##{current_method}"
82
+ ctx = if "#{tracked_func}" == 'true'
83
+ Span::Context.new(
84
+ CATEGORY: 'Ruby',
85
+ TRACKED_FUNC: "#{tracked_function_name}"
86
+ )
87
+ else
88
+ Span::Context.new(
89
+ CATEGORY: 'Ruby'
90
+ )
91
+ end
92
+
93
+ req = #{current_method_without}(*args, &block)
94
+ StackifyRubyAPM.span name, type, context: ctx do
81
95
  req
96
+ end
97
+ else
98
+ return #{current_method_without}(*args, &block)
82
99
  end
83
100
  end
84
101
  end
@@ -92,7 +109,10 @@ module StackifyRubyAPM
92
109
  @custom_class_info[current_class.to_s]['model'] = true if class_path && class_path.include?('models')
93
110
  end
94
111
 
95
- def self.m_singleton(tracked_func, current_class, class_path, current_method, tracked_function_name)
112
+ def self.m_singleton(tracked_func, current_class, class_path, **options)
113
+ current_method = options[:current_method] || nil
114
+ tracked_function_name = options[:tracked_function_name] || nil
115
+ transaction = options[:is_transaction] || nil
96
116
  module_consget = Module.const_get(current_class)
97
117
  classspyitem = "#{current_class}Spy"
98
118
 
@@ -125,23 +145,36 @@ module StackifyRubyAPM
125
145
  singleton_class.send(:alias_method, :"_self_without_apm_#{current_method}", :"#{current_method}")
126
146
 
127
147
  def self.#{current_method}(*args, &block)
128
- return _self_without_apm_#{current_method}(*args, &block) unless StackifyRubyAPM.current_transaction
129
-
130
- name = "Custom Instrument"
131
- type = "#{current_class}##{current_method}"
132
- ctx = if "#{tracked_func}" == 'true'
133
- Span::Context.new(
134
- CATEGORY: 'Ruby',
135
- TRACKED_FUNC: "#{tracked_function_name}"
136
- )
137
- else
138
- Span::Context.new(
139
- CATEGORY: 'Ruby'
140
- )
141
- end
142
- req = _self_without_apm_#{current_method}(*args, &block)
143
- StackifyRubyAPM.span name, type, context: ctx do
144
- req
148
+ if StackifyRubyAPM.current_transaction.nil? && #{!transaction.nil?}
149
+ t = StackifyRubyAPM.transaction("custom.#{current_class}.#{current_method}", TRACETYPE)
150
+ begin
151
+ req = _self_without_apm_#{current_method}(*args, &block)
152
+ rescue Exception => e
153
+ StackifyRubyAPM.report(e)
154
+ raise e
155
+ ensure
156
+ t.submit
157
+ end
158
+ return req
159
+ elsif StackifyRubyAPM.current_transaction
160
+ name = "Custom Instrument"
161
+ type = "#{current_class}##{current_method}"
162
+ ctx = if "#{tracked_func}" == 'true'
163
+ Span::Context.new(
164
+ CATEGORY: 'Ruby',
165
+ TRACKED_FUNC: "#{tracked_function_name}"
166
+ )
167
+ else
168
+ Span::Context.new(
169
+ CATEGORY: 'Ruby'
170
+ )
171
+ end
172
+ req = _self_without_apm_#{current_method}(*args, &block)
173
+ StackifyRubyAPM.span name, type, context: ctx do
174
+ req
175
+ end
176
+ else
177
+ return _self_without_apm_#{current_method}(*args, &block)
145
178
  end
146
179
  end
147
180
 
@@ -90,7 +90,7 @@ module StackifyRubyAPM
90
90
  # Start of transaction building with params: name, type, context
91
91
  #
92
92
  def build_transaction(env)
93
- StackifyRubyAPM.transaction 'Rack', 'request', context: StackifyRubyAPM.build_context(env)
93
+ StackifyRubyAPM.transaction 'Rack', 'WEBAPP', context: StackifyRubyAPM.build_context(env)
94
94
  end
95
95
 
96
96
  def running?
@@ -10,21 +10,18 @@ module StackifyRubyAPM
10
10
  @config = config
11
11
  end
12
12
 
13
+ # rubocop:disable Metrics/CyclomaticComplexity
14
+ # rubocop:disable Metrics/PerceivedComplexity
13
15
  def build
14
16
  # get process id
15
17
  pid = $PID || Process.pid
16
-
17
- {
18
+ hash = {
18
19
  CATEGORY: 'Ruby',
19
20
  APPLICATION_PATH: '/',
20
21
  APPLICATION_FILESYSTEM_PATH: @config.root_path,
21
22
  APPLICATION_NAME: @config.application_name,
22
- APPLICATION_ENV: @config.environment_name,
23
+ APPLICATION_ENV: @config.environment_name || 'Development',
23
24
  REPORTING_URL: @transaction.name,
24
- METHOD: @transaction.context.request.method,
25
- STATUS: @transaction.context.response.status_code,
26
- URL: @transaction.context.request.url[:full],
27
- TRACETYPE: 'WEBAPP',
28
25
  TRACE_ID: @transaction.id,
29
26
  THREAD_ID: Thread.current.object_id,
30
27
  TRACE_SOURCE: 'RUBY',
@@ -32,9 +29,16 @@ module StackifyRubyAPM
32
29
  HOST_NAME: @config.hostname || `hostname`,
33
30
  OS_TYPE: StackifyRubyAPM::Util.host_os,
34
31
  PROCESS_ID: pid,
35
- TRACE_VERSION: '2.0'
32
+ TRACE_VERSION: '2.0',
33
+ TRACETYPE: @transaction.type || 'WEBAPP'
36
34
  }
35
+ hash[:METHOD] = @transaction.context.request.method if @transaction.context && @transaction.context.request && @transaction.context.request.method
36
+ hash[:STATUS] = @transaction.context.response.status_code if @transaction.context && @transaction.context.response && @transaction.context.response.status_code
37
+ hash[:URL] = @transaction.context.request.url[:full] if @transaction.context && @transaction.context.request && @transaction.context.request.url[:full]
38
+ hash
37
39
  end
40
+ # rubocop:enable Metrics/CyclomaticComplexity
41
+ # rubocop:enable Metrics/PerceivedComplexity
38
42
 
39
43
  def self.build(config, transaction)
40
44
  new(config, transaction).build
@@ -9,15 +9,13 @@ module StackifyRubyAPM
9
9
  def build(error)
10
10
  if (exception = error.exception)
11
11
  current_timestamp = error.timestamp
12
-
13
12
  base = {
14
- CaughtBy: exception.module,
13
+ CaughtBy: exception.module != '' ? exception.module : exception.type,
15
14
  Exception: exception.type,
16
15
  Message: exception.message,
17
16
  Timestamp: current_timestamp.round.to_s,
18
17
  Frames: exception.stacktrace.to_a
19
18
  }
20
-
21
19
  end
22
20
 
23
21
  base
@@ -26,9 +26,9 @@ module StackifyRubyAPM
26
26
  current_method = custom_spy['method']
27
27
  tracked_func = custom_spy['trackedFunction']
28
28
  tracked_func_name = defined?(custom_spy['trackedFunctionName']) ? custom_spy['trackedFunctionName'] : ''
29
+ transaction = defined?(custom_spy['transaction']) ? custom_spy['transaction'] : nil
29
30
 
30
31
  tracked_function_tpl = tracked_func_name.nil? ? '{{ClassName}}.{{MethodName}}' : tracked_func_name
31
-
32
32
  tracked_function_name = tracked_function_tpl.sub '{{ClassName}}', current_class
33
33
  tracked_function_name = tracked_function_name.sub '{{MethodName}}', current_method
34
34
 
@@ -45,9 +45,9 @@ module StackifyRubyAPM
45
45
  class_path = class_location.last
46
46
 
47
47
  if klass_method_flag
48
- StackifyRubyAPM::InstrumenterHelper.m_class(tracked_func, current_class, class_path, current_method, tracked_function_name)
48
+ StackifyRubyAPM::InstrumenterHelper.m_class(tracked_func, current_class, class_path, current_method: current_method, tracked_function_name: tracked_function_name, is_transaction: transaction)
49
49
  elsif singleton_method_flag
50
- StackifyRubyAPM::InstrumenterHelper.m_singleton(tracked_func, current_class, class_path, current_method, tracked_function_name)
50
+ StackifyRubyAPM::InstrumenterHelper.m_singleton(tracked_func, current_class, class_path, current_method: current_method, tracked_function_name: tracked_function_name, is_transaction: transaction)
51
51
  end
52
52
  end
53
53
  # rubocop:enable Style/Next
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Sets the version of the APM
4
4
  module StackifyRubyAPM
5
- VERSION = '1.5.0'.freeze
5
+ VERSION = '1.6.0'.freeze
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackify-ruby-apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stackify
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-25 00:00:00.000000000 Z
11
+ date: 2019-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler