stackify-ruby-apm 1.3.1 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e69ba17aa5e795974868a28d69a053d1e40a1991a9894d7b76e38fc147cdbc15
4
- data.tar.gz: d556ea3ecff8621cb3024f33a82d396fa74a5582a5d86f34077cda9cf79ca60b
3
+ metadata.gz: 37b3e9d03e3a48f658ac93e0c7fb2bde7ff1bbe4b477d8db6307288182da1218
4
+ data.tar.gz: d85d9a3ebefa5f9fa86b232887087634c7fa3a464b8a430da6f43ec1e2a76973
5
5
  SHA512:
6
- metadata.gz: ab0cc4910e4b1004e7d78074df65000a6d3c23d47f4b1cab36a5613418e9a4752c216bd0c1cfd2b476be6716eb877a36a1e3dc0e66b85d480f0f10f27994ab35
7
- data.tar.gz: 199c9b05f7d9abbbddf4dce9aefd25b58edb61ee4aee28cd43ad88b225b5edc6b4e129f97dff2c7bfb3300b0bdb8330b1e3dd2202c611d49ef6d405f2693d7b7
6
+ metadata.gz: 6d7ad0838dc3db4eedb0f1dd9dfdc7ad7987952fcbdb8a5b1e852ecd2451b4193cf6f7e3df70046db7b9766834a23313e059bb5ea9752b965bba79c5332330d0
7
+ data.tar.gz: e5bddb17c802ee238fb73ad50b4208ff91b5072b6057726977478d61189cab9812eaef7df8153688722118fb7fbd5e69869c963d35c17a4084a33e1f16e7420b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stackify-ruby-apm (1.3.0)
4
+ stackify-ruby-apm (1.3.1)
5
5
  concurrent-ruby (~> 1.0)
6
6
  delegate_matcher (~> 0.4)
7
7
  rufus-scheduler (~> 3.5)
@@ -60,7 +60,7 @@ GEM
60
60
  domain_name (0.5.20180417)
61
61
  unf (>= 0.0.5, < 1.0.0)
62
62
  erubis (2.7.0)
63
- et-orbi (1.2.1)
63
+ et-orbi (1.2.0)
64
64
  tzinfo
65
65
  fakeredis (0.7.0)
66
66
  redis (>= 3.2, < 5.0)
@@ -68,7 +68,7 @@ GEM
68
68
  multipart-post (>= 1.2, < 3)
69
69
  file-tail (1.2.0)
70
70
  tins (~> 1.0)
71
- fugit (1.2.1)
71
+ fugit (1.2.0)
72
72
  et-orbi (~> 1.1, >= 1.1.8)
73
73
  raabro (~> 1.1)
74
74
  globalid (0.4.2)
@@ -98,12 +98,16 @@ GEM
98
98
  bson (>= 4.4.2, < 5.0.0)
99
99
  multipart-post (2.0.0)
100
100
  mysql2 (0.5.2)
101
+ mysql2 (0.5.2-x64-mingw32)
101
102
  nokogiri (1.6.8.1)
102
103
  mini_portile2 (~> 2.1.0)
104
+ nokogiri (1.6.8.1-x64-mingw32)
105
+ mini_portile2 (~> 2.1.0)
103
106
  parallel (1.13.0)
104
107
  parser (2.6.0.0)
105
108
  ast (~> 2.4.0)
106
109
  pg (0.21.0)
110
+ pg (0.21.0-x64-mingw32)
107
111
  powerpack (0.1.2)
108
112
  proc_extensions (0.2)
109
113
  sourcify (~> 0.5)
@@ -193,6 +197,7 @@ GEM
193
197
  activesupport (>= 4.0)
194
198
  sprockets (>= 3.0.0)
195
199
  sqlite3 (1.3.13)
200
+ sqlite3 (1.3.13-x64-mingw32)
196
201
  stackify-api-ruby (1.0.13)
197
202
  faraday (~> 0.8)
198
203
  thor (0.20.3)
@@ -206,6 +211,7 @@ GEM
206
211
  unf (0.1.4)
207
212
  unf_ext
208
213
  unf_ext (0.0.7.5)
214
+ unf_ext (0.0.7.5-x64-mingw32)
209
215
  unicode-display_width (1.5.0)
210
216
  webmock (3.5.1)
211
217
  addressable (>= 2.3.6)
@@ -214,6 +220,7 @@ GEM
214
220
 
215
221
  PLATFORMS
216
222
  ruby
223
+ x64-mingw32
217
224
 
218
225
  DEPENDENCIES
219
226
  activerecord
@@ -33,10 +33,11 @@ module StackifyRubyAPM
33
33
  pid = $PID || Process.pid
34
34
  host_name = config.hostname || `hostname`
35
35
  date_now = Time.now
36
- current_trace_file = config.log_trace_path + squish(host_name) + '#' + squish(pid.to_s) + '.log'
36
+ current_trace_file = config.log_trace_path + squish(host_name) + '#' + squish(pid.to_s)
37
37
 
38
38
  if ENV['STACKIFY_RUBY_ENV'] != 'rspec'
39
39
  config.tracer_logger = StackifyLogger.new(current_trace_file, config.filenum_rotate, config.logger_byte_size)
40
+ config.debug_logger
40
41
  config.logtime_created = date_now.strftime('%H:%M')
41
42
  Util::TraceLogWatcher.delete_trace_logs(config)
42
43
  end
@@ -102,7 +103,7 @@ module StackifyRubyAPM
102
103
  require "stackify_apm/spies/#{lib}"
103
104
  end
104
105
 
105
- debug '[Agent] Loaded spies:' + spies_name
106
+ debug '[Agent] Loaded spies: ' + spies_name if ENV['STACKIFY_APM_LOG_LEVEL'] == '0'
106
107
  self
107
108
  end
108
109
 
@@ -177,17 +178,17 @@ module StackifyRubyAPM
177
178
  # This method will strip and remove garbage character and multiple spaces.
178
179
 
179
180
  def self.squish(str)
180
- str = str.gsub(/\A[[:space:]]+/, '')
181
- str = str.gsub(/[[:space:]]+\z/, '')
182
- str = str.gsub(/[[:space:]]+/, ' ')
183
- str = str.strip.gsub(/\s+/, '')
181
+ str = str.sub(/\A[[:space:]]+/, '')
182
+ str = str.sub(/[[:space:]]+\z/, '')
183
+ str = str.sub(/[[:space:]]+/, ' ')
184
+ str = str.strip.sub(/\s+/, '')
184
185
  str
185
186
  end
186
187
 
187
188
  private
188
189
 
189
190
  def boot_worker
190
- debug '[Agent] Booting worker'
191
+ debug '[Agent] Booting worker' if ENV['STACKIFY_APM_LOG_LEVEL'] == '0'
191
192
 
192
193
  @worker_thread = Thread.new do
193
194
  Worker.new(
@@ -21,9 +21,9 @@ module StackifyRubyAPM
21
21
  rum_auto_injection: false,
22
22
  instrument: true,
23
23
  debug_logging: false,
24
- log_path: '/usr/local/stackify/stackify-ruby-apm/log/stackify-ruby-apm.log',
24
+ log_path: StackifyRubyAPM::Util.host_os == 'WINDOWS' ? 'C:\ProgramData\Stackify\Ruby\log\stackify-ruby-apm-1.log' : '/usr/local/stackify/stackify-ruby-apm/log/stackify-ruby-apm-1.log',
25
25
  log_level: Logger::INFO,
26
- log_trace_path: '/usr/local/stackify/stackify-ruby-apm/log/',
26
+ log_trace_path: StackifyRubyAPM::Util.host_os == 'WINDOWS' ? 'C:\ProgramData\Stackify\Ruby\log\\' : '/usr/local/stackify/stackify-ruby-apm/log/',
27
27
 
28
28
  max_queue_size: 500, # Maximum queue length of transactions before sending transactions to the APM.
29
29
  flush_interval: 1, # interval with which transactions should be sent to the APM. Default value: 10 seconds
@@ -83,9 +83,8 @@ module StackifyRubyAPM
83
83
  set_from_env
84
84
 
85
85
  yield self if block_given?
86
-
87
- build_logger if logger.nil? || log_path
88
- load_stackify_props
86
+ build_logger if ENV['STACKIFY_RUBY_ENV'] == 'rspec'
87
+ StackifyRubyAPM::Util.host_os == 'WINDOWS' ? load_stackify_props_windows : load_stackify_props
89
88
  end
90
89
 
91
90
  attr_accessor :config_file
@@ -202,6 +201,13 @@ module StackifyRubyAPM
202
201
  new_available_spies - disabled_spies
203
202
  end
204
203
 
204
+ def debug_logger
205
+ debuger_logpath = log_path == '-' ? $stdout : log_path
206
+ logger = StackifyLogger.new(debuger_logpath, debugger_filenum_rotate, debugger_byte_size)
207
+ logger.level = log_level
208
+ self.logger = logger
209
+ end
210
+
205
211
  private
206
212
 
207
213
  def assign(options)
@@ -274,26 +280,55 @@ module StackifyRubyAPM
274
280
  @device_id = nil
275
281
  @client_run_domain = nil
276
282
  begin
277
- info 'Reading the stackify.properties file'
283
+ info '[Config] Reading the stackify.properties file'
278
284
  IO.foreach(@stackify_properties_file) do |line|
279
285
  case line.downcase
280
286
  when /clientid=\d+/
281
- @client_id = line.split('=')[1].strip
287
+ cid = line.split('=')[1].strip
288
+ @client_id = "C#{cid}"
282
289
  when /deviceid=\d+/
283
- @device_id = line.split('=')[1].strip
290
+ devid = line.split('=')[1].strip
291
+ @device_id = "CD#{devid}"
284
292
  when /clientrumdomain=([\w\s\d\"\']+)+/i
285
293
  @client_run_domain = line.split('=')[1].strip
286
294
  end
287
295
  end
288
- info "stackify.properties: clientId=#{@client_id}, deviceId=#{@device_id}, client_rum_domain=#{@client_run_domain}"
296
+ info "[Config] stackify.properties: clientId=#{@client_id}, deviceId=#{@device_id}, client_rum_domain=#{@client_run_domain}"
297
+ rescue StandardError => e
298
+ info '[Config] Error occured while reading the stackify.properties file.'
299
+ info e.inspect
300
+ end
301
+ info '[Config] No clientId found from stackify.properties file.' if @client_id.nil?
302
+ info '[Config] No deviceId found from stackify.properties file.' if @device_id.nil?
303
+ info '[Config] No client RUM domain found from stackify.properties file.' if @client_run_domain.nil?
304
+ end
305
+ # rubocop:enable Metrics/CyclomaticComplexity
306
+
307
+ # rubocop:disable Metrics/CyclomaticComplexity
308
+ # rubocop:disable Metrics/PerceivedComplexity
309
+ def load_stackify_props_windows
310
+ require 'win32ole'
311
+ @client_id = nil
312
+ @device_id = nil
313
+ @client_run_domain = nil
314
+ begin
315
+ info 'Reading the Stackify props in Environment variables'
316
+ @client_run_domain = ENV['STACKIFY_RUM_DOMAIN'] || nil
317
+ if ENV['STACKIFY_ENV']
318
+ props = ENV['STACKIFY_ENV'].split('|')
319
+ @client_id = props[0].to_s if props[0]
320
+ @device_id = props[1].to_s if props[1]
321
+ info "stackify.properties: clientId=#{@client_id}, deviceId=#{@device_id}, client_rum_domain=#{@client_run_domain}"
322
+ end
289
323
  rescue StandardError => e
290
- info 'Error occured while reading the stackify.properties file.'
324
+ info 'Error occured while reading the Stackify props in Environment variables.'
291
325
  info e.inspect
292
326
  end
293
- info 'No clientId found from stackify.properties file.' if @client_id.nil?
294
- info 'No deviceId found from stackify.properties file.' if @device_id.nil?
295
- info 'No client RUM domain found from stackify.properties file.' if @client_run_domain.nil?
327
+ info 'No clientId found in environment variables.' if @client_id.nil?
328
+ info 'No deviceId found in environment variables.' if @device_id.nil?
329
+ info 'No client RUM domain found in environment variables.' if @client_run_domain.nil?
296
330
  end
297
331
  # rubocop:enable Metrics/CyclomaticComplexity
332
+ # rubocop:enable Metrics/PerceivedComplexity
298
333
  end
299
334
  end
@@ -26,7 +26,7 @@ module StackifyRubyAPM
26
26
  transaction_id = StackifyRubyAPM.agent.current_transaction.id
27
27
  client_id = StackifyRubyAPM.agent.config.client_id
28
28
  device_id = StackifyRubyAPM.agent.config.device_id
29
- headers['X-StackifyID'] = "V1|#{transaction_id}|C#{client_id}|CD#{device_id}" if client_id && device_id
29
+ headers['X-StackifyID'] = "V1|#{transaction_id}|#{client_id}|#{device_id}" if client_id && device_id
30
30
  end
31
31
  end
32
32
  end
@@ -24,11 +24,8 @@ module StackifyRubyAPM
24
24
  req = rails_req?(rack_env) ? rack_env : Rack::Request.new(rack_env)
25
25
  context.request = Context::Request.new unless context.request
26
26
  request = context.request
27
- request.socket = Context::Request::Socket.new(req).to_h
28
- request.http_version = build_http_version rack_env
29
27
  request.method = req.request_method
30
28
  request.url = Context::Request::Url.new(req).to_h
31
- request.headers, request.env = get_headers_and_env(rack_env)
32
29
  request.body = get_body(req)
33
30
 
34
31
  context
@@ -46,31 +43,5 @@ module StackifyRubyAPM
46
43
  defined?(ActionDispatch::Request) &&
47
44
  env.is_a?(ActionDispatch::Request)
48
45
  end
49
-
50
- def get_headers_and_env(rack_env)
51
- # In Rails < 5 ActionDispatch::Request inherits from Hash
52
- headers =
53
- rack_env.respond_to?(:headers) ? rack_env.headers : rack_env
54
-
55
- headers.each_with_object([{}, {}]) do |(key, value), (http, env)|
56
- next unless key == key.upcase
57
-
58
- if key.start_with?('HTTP_')
59
- http[camel_key(key)] = value
60
- else
61
- env[key] = value
62
- end
63
- end
64
- end
65
-
66
- def camel_key(key)
67
- key.gsub(/^HTTP_/, '').split('_').map(&:capitalize).join('-')
68
- end
69
-
70
- def build_http_version(rack_env)
71
- return unless (http_version = rack_env['HTTP_VERSION'])
72
-
73
- http_version.gsub(%r{HTTP/}, '')
74
- end
75
46
  end
76
47
  end
@@ -27,7 +27,7 @@ module StackifyRubyAPM
27
27
  end
28
28
 
29
29
  def initialize(agent)
30
- debug '[Instrumenter] initialize()'
30
+ debug '[Instrumenter] initialize()' if ENV['STACKIFY_APM_LOG_LEVEL'] == '0'
31
31
  @agent = agent
32
32
  @config = agent.config
33
33
 
@@ -57,7 +57,6 @@ module StackifyRubyAPM
57
57
  # Creates a new transaction or return the currently running
58
58
  #
59
59
  def transaction(*args)
60
- debug '[Instrumenter] transaction(*args)'
61
60
  unless config.instrument
62
61
  yield if block_given?
63
62
  return
@@ -96,8 +95,8 @@ module StackifyRubyAPM
96
95
  # Once the transaction is submitted it will be stored temporarily in queue
97
96
  #
98
97
  def submit_transaction(transaction)
99
- debug '[Instrumenter] submit_transaction(transaction):'
100
- debug transaction.inspect
98
+ debug '[Instrumenter] submit_transaction(transaction)' if ENV['STACKIFY_APM_LOG_LEVEL'] == '0'
99
+ debug '[Instrumenter] submit_transaction(transaction) transaction: ' + transaction.inspect.to_s if ENV['STACKIFY_APM_LOG_LEVEL'] == '0'
101
100
  agent.enqueue_transaction transaction
102
101
  return unless config.debug_transactions
103
102
  end
@@ -33,9 +33,9 @@ module StackifyRubyAPM
33
33
  # Newly created file example <file>-2.log is the latest appended log
34
34
  def shift_log_age
35
35
  # set a temporary filename that doesn't have the increment prefix and .log format.
36
- temp_filename = @filename.gsub(/\-(d*\.?\d*).log/, '')
36
+ temp_filename = @filename.to_s.sub(/\-(d*\.?\d*).log/, '')
37
37
  # set a temporary file increment while stripping the current filename and retain the number
38
- txttemp_fileincrement = @filename.gsub(temp_filename, '').delete('^0-9')
38
+ txttemp_fileincrement = @filename.to_s.sub(temp_filename, '').delete('^0-9')
39
39
  # convert the string value to integer
40
40
  current_fileprefix = txttemp_fileincrement.to_i
41
41
  # assign as filename counter
@@ -12,23 +12,25 @@ module StackifyRubyAPM
12
12
  # rubocop:disable Style/GuardClause
13
13
  # rubocop:disable Metrics/ParameterLists
14
14
  # rubocop:disable Lint/UnusedMethodArgument
15
- def initialize(logdev, shift_age = 0, shift_size = 1048576, level: DEBUG,
16
- progname: nil, formatter: nil, datetime_format: nil,
15
+ def initialize(logdev,
16
+ shift_age = 0,
17
+ shift_size = 1048576,
18
+ level: DEBUG,
19
+ progname: nil,
20
+ formatter: nil,
21
+ datetime_format: nil,
17
22
  shift_period_suffix: '%Y%m%d')
18
23
  super(nil) # this prevents it from initializing a LogDevice
19
24
  @logdev = nil
20
25
  if logdev
21
26
  new_logdev = logdev
22
27
  if logdev.instance_of? String
23
- temp_filename = logdev.gsub('.log', '')
28
+ temp_filename = logdev.gsub('-1.log', '')
24
29
  new_logdev = temp_filename + '-1.log'
25
30
  end
26
- @logdev = LogDevice.new(new_logdev, shift_age: shift_age,
27
- shift_size: shift_size,
28
- shift_period_suffix: shift_period_suffix)
31
+ @logdev = LogDevice.new(new_logdev, shift_size: shift_size)
29
32
  end
30
33
  end
31
-
32
34
  require 'stackify_apm/logger/log_device'
33
35
  end
34
36
  end
@@ -10,17 +10,16 @@ module StackifyRubyAPM
10
10
  class StackifyLogger < Logger
11
11
  # rubocop:disable Style/NumericLiterals
12
12
  # rubocop:disable Style/GuardClause
13
- def initialize(logdev, shift_age = 0, shift_size = 1048576)
13
+ def initialize(logdev, _shift_age = 0, shift_size = 1048576)
14
14
  super(nil) # this prevents it from initializing a LogDevice
15
15
  @logdev = nil
16
16
  if logdev
17
17
  new_logdev = logdev
18
18
  if logdev.instance_of? String
19
- temp_filename = logdev.gsub('.log', '')
19
+ temp_filename = logdev.gsub('-1.log', '')
20
20
  new_logdev = temp_filename + '-1.log'
21
21
  end
22
- @logdev = LogDevice.new(new_logdev, shift_age: shift_age,
23
- shift_size: shift_size)
22
+ @logdev = LogDevice.new(new_logdev, shift_size: shift_size)
24
23
  end
25
24
  end
26
25
 
@@ -47,7 +47,10 @@ module StackifyRubyAPM # :nodoc:
47
47
  end
48
48
 
49
49
  def for(name)
50
- @normalizers.fetch(name, @default)
50
+ # Performance suggestion by fasterer
51
+ # Hash#fetch with second argument is slower than Hash#fetch with block.
52
+ # @normalizers.fetch(name, @default)
53
+ @normalizers.fetch(name) { @default }
51
54
  end
52
55
 
53
56
  def keys
@@ -28,8 +28,6 @@ module StackifyRubyAPM
28
28
  private
29
29
 
30
30
  def query_variables(payload)
31
- debug '[SqlNormalizer] query_variables payload:'
32
- debug payload.inspect
33
31
  {
34
32
  CATEGORY: 'Database',
35
33
  SUBCATEGORY: 'Execute',
@@ -42,7 +40,8 @@ module StackifyRubyAPM
42
40
 
43
41
  def lookup_adapter
44
42
  ::ActiveRecord::Base.connection.adapter_name.downcase
45
- rescue StandardError
43
+ rescue StandardError => error
44
+ debug '[SqlNormalizer] lookup_adapter err: ' + error.inspect.to_s
46
45
  nil
47
46
  end
48
47
  end
@@ -67,10 +67,12 @@ module StackifyRubyAPM
67
67
  client_rundomain = @config.client_run_domain
68
68
  inject_flag = false
69
69
 
70
- if client_rundomain != '' && StackifyRubyAPM.check_isdomain(client_rundomain) && client_id && device_id
71
- inject_flag = true
72
- else
73
- warn 'ClientRumDomain might be empty or Invalid URL stackify.properties.'
70
+ if client_id && device_id
71
+ if StackifyRubyAPM.check_isdomain(client_rundomain)
72
+ inject_flag = true
73
+ else
74
+ info 'Error: Stackify Client RUM Domain is invalid.'
75
+ end
74
76
  end
75
77
 
76
78
  return unless inject_flag
@@ -94,7 +96,7 @@ module StackifyRubyAPM
94
96
  source = source[0...insertion_index] <<
95
97
  jsfile_to_inject <<
96
98
  source[insertion_index..-1]
97
- source = source.gsub('[RUM_SCRIPT_VARIABLE]', '') if rum_variable_script
99
+ source = source.sub('[RUM_SCRIPT_VARIABLE]', '') if rum_variable_script
98
100
  end
99
101
  source
100
102
  end
@@ -27,10 +27,10 @@ module StackifyRubyAPM
27
27
  TRACETYPE: 'WEBAPP',
28
28
  TRACE_ID: @transaction.id,
29
29
  THREAD_ID: Thread.current.object_id,
30
- TRACE_SOURCE: 'Ruby',
30
+ TRACE_SOURCE: 'RUBY',
31
31
  TRACE_TARGET: 'RETRACE',
32
32
  HOST_NAME: @config.hostname || `hostname`,
33
- OS_TYPE: 'LINUX',
33
+ OS_TYPE: StackifyRubyAPM::Util.host_os,
34
34
  PROCESS_ID: pid,
35
35
  TRACE_VERSION: '2.0'
36
36
  }
@@ -69,8 +69,9 @@ module StackifyRubyAPM
69
69
  def self.parse_json_config(file)
70
70
  jsondata = {}
71
71
  if ENV['STACKIFY_RUBY_ENV'] == 'rspec'
72
- file = 'spec/integration/stackify.json'
72
+ file = 'spec/integration/stackify_spec.json'
73
73
  end
74
+
74
75
  return unless File.exist?(file)
75
76
 
76
77
  File.open(file) do |f|
@@ -24,7 +24,7 @@ module StackifyRubyAPM
24
24
  req = http_without_apm(verb, url, _post_body = nil, _put_data = nil, &block)
25
25
  # Builds span context
26
26
  #
27
- status_code = req.status.gsub(/^0-9/, '').to_i
27
+ status_code = req.status.sub(/^0-9/, '').to_i
28
28
 
29
29
  ctx = Span::Context.new(
30
30
  CATEGORY: 'Web External',
@@ -30,7 +30,7 @@ module StackifyRubyAPM
30
30
  req = perform_without_apm(*args)
31
31
  # Builds span context
32
32
  #
33
- status_code = req.status.gsub(/^0-9/, '').to_i
33
+ status_code = req.status.sub(/^0-9/, '').to_i
34
34
  ctx = Span::Context.new(
35
35
  CATEGORY: 'Web External',
36
36
  SUBCATEGORY: 'Execute',
@@ -55,7 +55,7 @@ module StackifyRubyAPM
55
55
  name = "#{method} #{uri}"
56
56
  type = "ext.Curb.Easy.#{method}"
57
57
  req = http_post_without_apm(*args)
58
- status_code = req.status.gsub(/^0-9/, '').to_i
58
+ status_code = req.status.sub(/^0-9/, '').to_i
59
59
 
60
60
  ctx = Span::Context.new(
61
61
  CATEGORY: 'Web External',
@@ -81,7 +81,7 @@ module StackifyRubyAPM
81
81
  name = "#{method} #{uri}"
82
82
  type = "ext.Curb.Easy.#{method}"
83
83
  req = http_put_without_apm(url, data)
84
- status_code = req.status.gsub(/^0-9/, '').to_i
84
+ status_code = req.status.sub(/^0-9/, '').to_i
85
85
 
86
86
  ctx = Span::Context.new(
87
87
  CATEGORY: 'Web External',
@@ -107,7 +107,7 @@ module StackifyRubyAPM
107
107
  name = "#{method} #{uri}"
108
108
  type = "ext.Curb.Easy.#{method}"
109
109
  req = http_get_without_apm(*args)
110
- status_code = req.status.gsub(/^0-9/, '').to_i
110
+ status_code = req.status.sub(/^0-9/, '').to_i
111
111
 
112
112
  ctx = Span::Context.new(
113
113
  CATEGORY: 'Web External',
@@ -133,7 +133,7 @@ module StackifyRubyAPM
133
133
  name = "#{method} #{uri}"
134
134
  type = "ext.Curb.Easy.#{method}"
135
135
  req = http_delete_without_apm(*args)
136
- status_code = req.status.gsub(/^0-9/, '').to_i
136
+ status_code = req.status.sub(/^0-9/, '').to_i
137
137
 
138
138
  ctx = Span::Context.new(
139
139
  CATEGORY: 'Web External',
@@ -87,8 +87,8 @@ module StackifyRubyAPM
87
87
  tracked_func_name
88
88
  end
89
89
 
90
- tracked_function_name = tracked_function_tpl.gsub '{{ClassName}}', current_class
91
- tracked_function_name = tracked_function_name.gsub '{{MethodName}}', current_method
90
+ tracked_function_name = tracked_function_tpl.sub '{{ClassName}}', current_class
91
+ tracked_function_name = tracked_function_name.sub '{{MethodName}}', current_method
92
92
 
93
93
  # rubocop:disable Style/Next
94
94
  if class_exists?(current_class)
@@ -12,8 +12,7 @@ module StackifyRubyAPM
12
12
  include Log
13
13
 
14
14
  def initialize(agent)
15
- debug '[Subscriber] initialize()'
16
- debug agent.inspect
15
+ debug '[Subscriber] initialize(agent)' if ENV['STACKIFY_APM_LOG_LEVEL'] == '0'
17
16
  @agent = agent
18
17
  @normalizers = Normalizers.build(agent.config)
19
18
  end
@@ -40,11 +39,6 @@ module StackifyRubyAPM
40
39
  def call(name, started, finished, id, payload)
41
40
  return unless (transaction = @agent.current_transaction)
42
41
 
43
- debug '[Subscriber] call():'
44
- debug id
45
- debug name
46
- debug transaction
47
-
48
42
  normalized = @normalizers.normalize(transaction, name, payload)
49
43
 
50
44
  if started
@@ -77,10 +71,6 @@ module StackifyRubyAPM
77
71
  def start(name, id, payload)
78
72
  return unless (transaction = @agent.current_transaction)
79
73
 
80
- debug '[Subscriber] start():'
81
- debug id
82
- debug name
83
- debug transaction
84
74
  normalized = @normalizers.normalize(transaction, name, payload)
85
75
 
86
76
  span =
@@ -96,8 +86,6 @@ module StackifyRubyAPM
96
86
 
97
87
  # [finish] Called when the rails version is NOT 3.x
98
88
  def finish(_name, id, _payload)
99
- # debug "AS::Notification#finish:#{name}:#{id}"
100
- debug '[Subscriber] finish():'
101
89
  return unless (transaction = @agent.current_transaction)
102
90
 
103
91
  while (notification = transaction.notifications.pop)
@@ -19,6 +19,7 @@ module StackifyRubyAPM
19
19
  attr_accessor :trace_file_counter
20
20
 
21
21
  def post(transactions = [])
22
+ debug '[TraceLogger] post()' if ENV['STACKIFY_APM_LOG_LEVEL'] == '0'
22
23
  # convert transactions to json
23
24
  json_traces = []
24
25
  transactions.each do |transaction|
@@ -29,14 +30,12 @@ module StackifyRubyAPM
29
30
  json_traces.push(json_transaction)
30
31
  end
31
32
 
32
- date_now = Time.now
33
- current_datetime = date_now.strftime('%Y-%m-%d, %H:%M:%S.%6N')
33
+ current_datetime = Time.now.utc.strftime('%Y-%m-%d, %H:%M:%S.%6N')
34
34
 
35
35
  return unless ENV['STACKIFY_RUBY_ENV'] != 'rspec'
36
36
 
37
37
  json_traces.each do |json_trace|
38
- update_json = current_datetime + ' > ' + json_trace + "\n"
39
- @config.tracer_logger.<<(update_json)
38
+ @config.tracer_logger.<<("#{current_datetime} > #{json_trace} \n")
40
39
  end
41
40
  end
42
41
  end
@@ -116,7 +116,17 @@ module StackifyRubyAPM
116
116
  end
117
117
 
118
118
  def build_and_start_span(name, type, context, backtrace)
119
- span = next_span(name, type, context)
119
+ span = Span.new(
120
+ self,
121
+ next_span_id,
122
+ name,
123
+ type,
124
+ parent_id: current_span.nil? ? -1 : current_span.id,
125
+ context: context,
126
+ http_status: @http_status
127
+ )
128
+
129
+ # span = next_span(name, type, context)
120
130
  spans << span
121
131
 
122
132
  span.original_backtrace = backtrace if backtrace && span_frames_min_duration?
@@ -16,6 +16,24 @@ module StackifyRubyAPM
16
16
  cmd_rake = ($PROGRAM_NAME =~ /rake$/)
17
17
  StackifyRubyAPM.agent.config.instrument = false if cmd_rake
18
18
  end
19
+
20
+ def self.host_os
21
+ host_os = RbConfig::CONFIG['host_os']
22
+ case host_os
23
+ when /cygwin|mswin|mingw|bccwin|wince|emx/i
24
+ 'WINDOWS'
25
+ when /linux|arch/i
26
+ 'LINUX'
27
+ when /sunos|solaris/i
28
+ 'SOLARIS'
29
+ when /bsd/i
30
+ 'BSD'
31
+ when /darwin/i
32
+ 'MAC OS X'
33
+ else
34
+ "UNKNOWN #{host_os}"
35
+ end
36
+ end
19
37
  end
20
38
  end
21
39
  require 'stackify_apm/util/inspector'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Sets the version of the APM
4
4
  module StackifyRubyAPM
5
- VERSION = '1.3.1'.freeze
5
+ VERSION = '1.4.0'.freeze
6
6
  end
@@ -81,7 +81,7 @@ module StackifyRubyAPM
81
81
  def collect_and_send_transactions
82
82
  return if pending_transactions.empty?
83
83
  transactions = collect_batched_transactions
84
- debug '[Worker] Successfully collect and send transaction to the to trace logger.'
84
+ debug '[Worker] collect_and_send_transactions() transactions : ' + transactions.inspect.to_s if ENV['STACKIFY_APM_LOG_LEVEL'] == '0'
85
85
  begin
86
86
  @trace_logger.post(transactions)
87
87
  rescue ::Exception => e
@@ -97,7 +97,6 @@ module StackifyRubyAPM
97
97
  return if pending_transactions.empty?
98
98
  # transactions = collect_batched_transactions
99
99
  # payload = @serializers.errors.build_all([msg.error])
100
- debug '[Worker] post_error()'
101
100
  # @trace_logger.post(payload, transactions[0])
102
101
  end
103
102
 
@@ -20,11 +20,12 @@ require 'stackify_apm/agent'
20
20
  # Checks ruby version
21
21
  require RUBY_VERSION.to_f >= 2.4 ? 'stackify_apm/logger/logger_high_version' : 'stackify_apm/logger/logger_lower_version'
22
22
  require 'stackify_apm/helper/database_helper'
23
+ require 'stackify_apm/util'
23
24
  require 'stackify_apm/config'
24
25
  require 'stackify_apm/context'
25
26
  require 'stackify_apm/instrumenter'
26
27
  require 'stackify_apm/internal_error'
27
- require 'stackify_apm/util'
28
+ # require 'stackify_apm/util'
28
29
  require 'stackify_apm/middleware'
29
30
 
30
31
  # Checks if the framework using is Rails
@@ -40,8 +41,6 @@ module StackifyRubyAPM
40
41
  Agent.start config
41
42
  end
42
43
 
43
- # rubocop:disable Metrics/CyclomaticComplexity
44
- # rubocop:disable Metrics/PerceivedComplexity
45
44
  def self.inject_rum_script
46
45
  config = StackifyRubyAPM::Config.new
47
46
  client_id = config.client_id
@@ -51,14 +50,16 @@ module StackifyRubyAPM
51
50
 
52
51
  inject_flag = false
53
52
 
54
- if client_rundomain != '' && check_isdomain(client_rundomain) && client_id && device_id
55
- inject_flag = true
56
- else
57
- warn 'ClientRumDomain might be empty or Invalid URL stackify.properties.'
53
+ if client_id && device_id
54
+ if check_isdomain(client_rundomain)
55
+ inject_flag = true
56
+ else
57
+ info 'Error: Stackify Client RUM Domain is invalid.'
58
+ end
58
59
  end
59
60
 
60
61
  return unless inject_flag
61
- data_request_id = 'V2|' + transaction_id + '|C' + client_id + '|CD' + device_id
62
+ data_request_id = "V2|#{transaction_id}|#{client_id}|#{device_id}"
62
63
  @rum_script_injected = true
63
64
  "<script src=\"#{config.rum_script_src}\" data-host=\"#{client_rundomain}\" data-requestId=\"#{data_request_id}\"
64
65
  data-a=\"#{config.application_name}\" data-e=\"#{config.environment_name}\" data-enableInternalLogging=\"#{config.debug_logging}\" type=\"text/javascript\" async></script>"
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.3.1
4
+ version: 1.4.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-05-16 00:00:00.000000000 Z
11
+ date: 2019-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler