brainzlab 0.1.1 → 0.1.3

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.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +6 -21
  3. data/README.md +24 -2
  4. data/lib/brainzlab/beacon/client.rb +207 -0
  5. data/lib/brainzlab/beacon/provisioner.rb +44 -0
  6. data/lib/brainzlab/beacon.rb +215 -0
  7. data/lib/brainzlab/configuration.rb +372 -32
  8. data/lib/brainzlab/context.rb +2 -3
  9. data/lib/brainzlab/cortex/cache.rb +59 -0
  10. data/lib/brainzlab/cortex/client.rb +139 -0
  11. data/lib/brainzlab/cortex/provisioner.rb +49 -0
  12. data/lib/brainzlab/cortex.rb +223 -0
  13. data/lib/brainzlab/dendrite/client.rb +230 -0
  14. data/lib/brainzlab/dendrite/provisioner.rb +44 -0
  15. data/lib/brainzlab/dendrite.rb +195 -0
  16. data/lib/brainzlab/devtools/assets/devtools.css +1106 -0
  17. data/lib/brainzlab/devtools/assets/devtools.js +322 -0
  18. data/lib/brainzlab/devtools/assets/logo.svg +6 -0
  19. data/lib/brainzlab/devtools/assets/templates/debug_panel.html.erb +500 -0
  20. data/lib/brainzlab/devtools/assets/templates/error_page.html.erb +1086 -0
  21. data/lib/brainzlab/devtools/data/collector.rb +248 -0
  22. data/lib/brainzlab/devtools/middleware/asset_server.rb +63 -0
  23. data/lib/brainzlab/devtools/middleware/database_handler.rb +177 -0
  24. data/lib/brainzlab/devtools/middleware/debug_panel.rb +126 -0
  25. data/lib/brainzlab/devtools/middleware/error_page.rb +377 -0
  26. data/lib/brainzlab/devtools/renderers/debug_panel_renderer.rb +159 -0
  27. data/lib/brainzlab/devtools/renderers/error_page_renderer.rb +98 -0
  28. data/lib/brainzlab/devtools.rb +75 -0
  29. data/lib/brainzlab/flux/buffer.rb +96 -0
  30. data/lib/brainzlab/flux/client.rb +68 -0
  31. data/lib/brainzlab/flux/provisioner.rb +57 -0
  32. data/lib/brainzlab/flux.rb +174 -0
  33. data/lib/brainzlab/instrumentation/action_mailer.rb +14 -13
  34. data/lib/brainzlab/instrumentation/active_record.rb +28 -13
  35. data/lib/brainzlab/instrumentation/aws.rb +183 -0
  36. data/lib/brainzlab/instrumentation/dalli.rb +108 -0
  37. data/lib/brainzlab/instrumentation/delayed_job.rb +27 -29
  38. data/lib/brainzlab/instrumentation/elasticsearch.rb +23 -24
  39. data/lib/brainzlab/instrumentation/excon.rb +152 -0
  40. data/lib/brainzlab/instrumentation/faraday.rb +3 -4
  41. data/lib/brainzlab/instrumentation/good_job.rb +102 -0
  42. data/lib/brainzlab/instrumentation/grape.rb +24 -24
  43. data/lib/brainzlab/instrumentation/graphql.rb +24 -23
  44. data/lib/brainzlab/instrumentation/httparty.rb +13 -14
  45. data/lib/brainzlab/instrumentation/mongodb.rb +7 -7
  46. data/lib/brainzlab/instrumentation/net_http.rb +6 -6
  47. data/lib/brainzlab/instrumentation/redis.rb +14 -21
  48. data/lib/brainzlab/instrumentation/resque.rb +114 -0
  49. data/lib/brainzlab/instrumentation/sidekiq.rb +29 -28
  50. data/lib/brainzlab/instrumentation/solid_queue.rb +194 -0
  51. data/lib/brainzlab/instrumentation/stripe.rb +163 -0
  52. data/lib/brainzlab/instrumentation/typhoeus.rb +106 -0
  53. data/lib/brainzlab/instrumentation.rb +84 -12
  54. data/lib/brainzlab/nerve/client.rb +215 -0
  55. data/lib/brainzlab/nerve/provisioner.rb +44 -0
  56. data/lib/brainzlab/nerve.rb +219 -0
  57. data/lib/brainzlab/pulse/client.rb +15 -11
  58. data/lib/brainzlab/pulse/instrumentation.rb +90 -53
  59. data/lib/brainzlab/pulse/propagation.rb +29 -29
  60. data/lib/brainzlab/pulse/provisioner.rb +12 -12
  61. data/lib/brainzlab/pulse/tracer.rb +4 -4
  62. data/lib/brainzlab/pulse.rb +14 -14
  63. data/lib/brainzlab/rails/log_formatter.rb +127 -121
  64. data/lib/brainzlab/rails/log_subscriber.rb +70 -77
  65. data/lib/brainzlab/rails/railtie.rb +96 -86
  66. data/lib/brainzlab/recall/buffer.rb +1 -1
  67. data/lib/brainzlab/recall/client.rb +14 -10
  68. data/lib/brainzlab/recall/logger.rb +16 -18
  69. data/lib/brainzlab/recall/provisioner.rb +29 -12
  70. data/lib/brainzlab/recall.rb +14 -11
  71. data/lib/brainzlab/reflex/breadcrumbs.rb +2 -2
  72. data/lib/brainzlab/reflex/client.rb +14 -10
  73. data/lib/brainzlab/reflex/provisioner.rb +12 -12
  74. data/lib/brainzlab/reflex.rb +31 -31
  75. data/lib/brainzlab/sentinel/client.rb +216 -0
  76. data/lib/brainzlab/sentinel/provisioner.rb +44 -0
  77. data/lib/brainzlab/sentinel.rb +165 -0
  78. data/lib/brainzlab/signal/client.rb +60 -0
  79. data/lib/brainzlab/signal/provisioner.rb +55 -0
  80. data/lib/brainzlab/signal.rb +136 -0
  81. data/lib/brainzlab/synapse/client.rb +288 -0
  82. data/lib/brainzlab/synapse/provisioner.rb +44 -0
  83. data/lib/brainzlab/synapse.rb +270 -0
  84. data/lib/brainzlab/utilities/circuit_breaker.rb +261 -0
  85. data/lib/brainzlab/utilities/health_check.rb +294 -0
  86. data/lib/brainzlab/utilities/log_formatter.rb +254 -0
  87. data/lib/brainzlab/utilities/rate_limiter.rb +230 -0
  88. data/lib/brainzlab/utilities.rb +17 -0
  89. data/lib/brainzlab/vault/cache.rb +80 -0
  90. data/lib/brainzlab/vault/client.rb +196 -0
  91. data/lib/brainzlab/vault/provisioner.rb +49 -0
  92. data/lib/brainzlab/vault.rb +262 -0
  93. data/lib/brainzlab/version.rb +1 -1
  94. data/lib/brainzlab/vision/client.rb +128 -0
  95. data/lib/brainzlab/vision/provisioner.rb +136 -0
  96. data/lib/brainzlab/vision.rb +155 -0
  97. data/lib/brainzlab-sdk.rb +1 -1
  98. data/lib/brainzlab.rb +112 -13
  99. data/lib/generators/brainzlab/install/install_generator.rb +29 -27
  100. metadata +60 -1
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "net/http"
4
- require "uri"
5
- require "json"
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'json'
6
6
 
7
7
  module BrainzLab
8
8
  module Recall
@@ -18,14 +18,14 @@ module BrainzLab
18
18
  def send_log(log_entry)
19
19
  return unless @config.recall_enabled && @config.valid?
20
20
 
21
- post("/api/v1/log", log_entry)
21
+ post('/api/v1/log', log_entry)
22
22
  end
23
23
 
24
24
  def send_batch(log_entries)
25
25
  return unless @config.recall_enabled && @config.valid?
26
26
  return if log_entries.empty?
27
27
 
28
- post("/api/v1/logs", { logs: log_entries })
28
+ post('/api/v1/logs', { logs: log_entries })
29
29
  end
30
30
 
31
31
  private
@@ -33,9 +33,9 @@ module BrainzLab
33
33
  def post(path, body)
34
34
  uri = URI.join(@config.recall_url, path)
35
35
  request = Net::HTTP::Post.new(uri)
36
- request["Content-Type"] = "application/json"
37
- request["Authorization"] = "Bearer #{@config.secret_key}"
38
- request["User-Agent"] = "brainzlab-sdk-ruby/#{BrainzLab::VERSION}"
36
+ request['Content-Type'] = 'application/json'
37
+ request['Authorization'] = "Bearer #{@config.secret_key}"
38
+ request['User-Agent'] = "brainzlab-sdk-ruby/#{BrainzLab::VERSION}"
39
39
  request.body = JSON.generate(body)
40
40
 
41
41
  execute_with_retry(uri, request)
@@ -48,7 +48,7 @@ module BrainzLab
48
48
  retries = 0
49
49
  begin
50
50
  http = Net::HTTP.new(uri.host, uri.port)
51
- http.use_ssl = uri.scheme == "https"
51
+ http.use_ssl = uri.scheme == 'https'
52
52
  http.open_timeout = 5
53
53
  http.read_timeout = 10
54
54
 
@@ -56,7 +56,11 @@ module BrainzLab
56
56
 
57
57
  case response.code.to_i
58
58
  when 200..299
59
- JSON.parse(response.body) rescue {}
59
+ begin
60
+ JSON.parse(response.body)
61
+ rescue StandardError
62
+ {}
63
+ end
60
64
  when 429, 500..599
61
65
  raise RetryableError, "Server error: #{response.code}"
62
66
  else
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "logger"
3
+ require 'logger'
4
4
 
5
5
  module BrainzLab
6
6
  module Recall
@@ -12,16 +12,14 @@ module BrainzLab
12
12
  @service_name = service_name
13
13
  @broadcast_to = broadcast_to
14
14
  @level = ::Logger::DEBUG
15
- @formatter = proc { |severity, _time, _progname, msg| msg }
15
+ @formatter = proc { |_severity, _time, _progname, msg| msg }
16
16
  end
17
17
 
18
- def add(severity, message = nil, progname = nil, &block)
18
+ def add(severity, message = nil, progname = nil)
19
19
  severity ||= ::Logger::UNKNOWN
20
20
 
21
21
  # Handle block-based messages
22
- if message.nil? && block_given?
23
- message = yield
24
- end
22
+ message = yield if message.nil? && block_given?
25
23
 
26
24
  # Handle progname as message (standard Logger behavior)
27
25
  if message.nil?
@@ -52,28 +50,28 @@ module BrainzLab
52
50
  true
53
51
  end
54
52
 
55
- def debug(message = nil, &block)
56
- add(::Logger::DEBUG, message, &block)
53
+ def debug(message = nil, &)
54
+ add(::Logger::DEBUG, message, &)
57
55
  end
58
56
 
59
- def info(message = nil, &block)
60
- add(::Logger::INFO, message, &block)
57
+ def info(message = nil, &)
58
+ add(::Logger::INFO, message, &)
61
59
  end
62
60
 
63
- def warn(message = nil, &block)
64
- add(::Logger::WARN, message, &block)
61
+ def warn(message = nil, &)
62
+ add(::Logger::WARN, message, &)
65
63
  end
66
64
 
67
- def error(message = nil, &block)
68
- add(::Logger::ERROR, message, &block)
65
+ def error(message = nil, &)
66
+ add(::Logger::ERROR, message, &)
69
67
  end
70
68
 
71
- def fatal(message = nil, &block)
72
- add(::Logger::FATAL, message, &block)
69
+ def fatal(message = nil, &)
70
+ add(::Logger::FATAL, message, &)
73
71
  end
74
72
 
75
- def unknown(message = nil, &block)
76
- add(::Logger::UNKNOWN, message, &block)
73
+ def unknown(message = nil, &)
74
+ add(::Logger::UNKNOWN, message, &)
77
75
  end
78
76
 
79
77
  # Rails compatibility methods
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "net/http"
4
- require "uri"
5
- require "json"
6
- require "fileutils"
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'json'
6
+ require 'fileutils'
7
7
 
8
8
  module BrainzLab
9
9
  module Recall
10
10
  class Provisioner
11
- CACHE_DIR = ENV.fetch("BRAINZLAB_CACHE_DIR") { File.join(Dir.home, ".brainzlab") }
11
+ CACHE_DIR = ENV.fetch('BRAINZLAB_CACHE_DIR') { File.join(Dir.home, '.brainzlab') }
12
12
 
13
13
  def initialize(config)
14
14
  @config = config
@@ -37,20 +37,37 @@ module BrainzLab
37
37
  private
38
38
 
39
39
  def should_provision?
40
+ if @config.debug
41
+ log_debug('Checking provision conditions:')
42
+ log_debug(" recall_auto_provision: #{@config.recall_auto_provision}")
43
+ log_debug(" app_name: '#{@config.app_name}'")
44
+ log_debug(" secret_key set: #{@config.secret_key.to_s.strip.length.positive?}")
45
+ log_debug(" recall_master_key set: #{@config.recall_master_key.to_s.strip.length.positive?}")
46
+ end
47
+
40
48
  return false unless @config.recall_auto_provision
41
- return false unless @config.app_name.to_s.strip.length > 0
42
- return false if @config.secret_key.to_s.strip.length > 0
43
- return false unless @config.recall_master_key.to_s.strip.length > 0
49
+ return false unless @config.app_name.to_s.strip.length.positive?
50
+ return false if @config.secret_key.to_s.strip.length.positive?
51
+ return false unless @config.recall_master_key.to_s.strip.length.positive?
44
52
 
53
+ log_debug('Will provision Recall project') if @config.debug
45
54
  true
46
55
  end
47
56
 
57
+ def log_debug(message)
58
+ if @config.logger
59
+ @config.logger.info("[BrainzLab::Debug] #{message}")
60
+ else
61
+ puts "[BrainzLab::Debug] #{message}"
62
+ end
63
+ end
64
+
48
65
  def provision_project
49
66
  uri = URI.parse("#{@config.recall_url}/api/v1/projects/provision")
50
67
  request = Net::HTTP::Post.new(uri)
51
- request["Content-Type"] = "application/json"
52
- request["X-Master-Key"] = @config.recall_master_key
53
- request["User-Agent"] = "brainzlab-sdk-ruby/#{BrainzLab::VERSION}"
68
+ request['Content-Type'] = 'application/json'
69
+ request['X-Master-Key'] = @config.recall_master_key
70
+ request['User-Agent'] = "brainzlab-sdk-ruby/#{BrainzLab::VERSION}"
54
71
  request.body = JSON.generate({ name: @config.app_name })
55
72
 
56
73
  response = execute(uri, request)
@@ -97,7 +114,7 @@ module BrainzLab
97
114
 
98
115
  def execute(uri, request)
99
116
  http = Net::HTTP.new(uri.host, uri.port)
100
- http.use_ssl = uri.scheme == "https"
117
+ http.use_ssl = uri.scheme == 'https'
101
118
  http.open_timeout = 5
102
119
  http.read_timeout = 10
103
120
  http.request(request)
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "recall/client"
4
- require_relative "recall/buffer"
5
- require_relative "recall/logger"
6
- require_relative "recall/provisioner"
3
+ require_relative 'recall/client'
4
+ require_relative 'recall/buffer'
5
+ require_relative 'recall/logger'
6
+ require_relative 'recall/provisioner'
7
7
 
8
8
  module BrainzLab
9
9
  module Recall
@@ -30,7 +30,7 @@ module BrainzLab
30
30
 
31
31
  def log(level, message, **data)
32
32
  config = BrainzLab.configuration
33
- return unless config.recall_enabled
33
+ return unless config.recall_effectively_enabled?
34
34
 
35
35
  # Auto-provision project on first log if app_name is configured
36
36
  ensure_provisioned!
@@ -43,6 +43,9 @@ module BrainzLab
43
43
  end
44
44
 
45
45
  def ensure_provisioned!
46
+ config = BrainzLab.configuration
47
+ puts "[BrainzLab::Debug] Recall.ensure_provisioned! called, @provisioned=#{@provisioned}" if config.debug
48
+
46
49
  return if @provisioned
47
50
 
48
51
  @provisioned = true
@@ -58,7 +61,7 @@ module BrainzLab
58
61
  result = yield
59
62
  duration_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start) * 1000).round(1)
60
63
 
61
- info("#{label} (#{duration_ms}ms)", **data.merge(duration_ms: duration_ms))
64
+ info("#{label} (#{duration_ms}ms)", **data, duration_ms: duration_ms)
62
65
  result
63
66
  end
64
67
 
@@ -126,11 +129,11 @@ module BrainzLab
126
129
  case obj
127
130
  when Hash
128
131
  obj.each_with_object({}) do |(key, value), result|
129
- if should_scrub?(key, fields)
130
- result[key] = "[FILTERED]"
131
- else
132
- result[key] = deep_scrub(value, fields)
133
- end
132
+ result[key] = if should_scrub?(key, fields)
133
+ '[FILTERED]'
134
+ else
135
+ deep_scrub(value, fields)
136
+ end
134
137
  end
135
138
  when Array
136
139
  obj.map { |item| deep_scrub(item, fields) }
@@ -10,7 +10,7 @@ module BrainzLab
10
10
  @mutex = Mutex.new
11
11
  end
12
12
 
13
- def add(message:, category: "default", level: :info, data: nil)
13
+ def add(message:, category: 'default', level: :info, data: nil)
14
14
  crumb = {
15
15
  timestamp: Time.now.utc.iso8601(3),
16
16
  message: message.to_s,
@@ -43,7 +43,7 @@ module BrainzLab
43
43
  Context.current.breadcrumbs
44
44
  end
45
45
 
46
- def add_breadcrumb(message, category: "default", level: :info, data: nil)
46
+ def add_breadcrumb(message, category: 'default', level: :info, data: nil)
47
47
  breadcrumbs.add(message: message, category: category, level: level, data: data)
48
48
  end
49
49
 
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "net/http"
4
- require "uri"
5
- require "json"
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'json'
6
6
 
7
7
  module BrainzLab
8
8
  module Reflex
@@ -17,14 +17,14 @@ module BrainzLab
17
17
  def send_error(payload)
18
18
  return unless @config.reflex_enabled && @config.reflex_valid?
19
19
 
20
- post("/api/v1/errors", payload)
20
+ post('/api/v1/errors', payload)
21
21
  end
22
22
 
23
23
  def send_batch(payloads)
24
24
  return unless @config.reflex_enabled && @config.reflex_valid?
25
25
  return if payloads.empty?
26
26
 
27
- post("/api/v1/errors/batch", { errors: payloads })
27
+ post('/api/v1/errors/batch', { errors: payloads })
28
28
  end
29
29
 
30
30
  private
@@ -32,9 +32,9 @@ module BrainzLab
32
32
  def post(path, body)
33
33
  uri = URI.join(@config.reflex_url, path)
34
34
  request = Net::HTTP::Post.new(uri)
35
- request["Content-Type"] = "application/json"
36
- request["Authorization"] = "Bearer #{@config.reflex_auth_key}"
37
- request["User-Agent"] = "brainzlab-sdk-ruby/#{BrainzLab::VERSION}"
35
+ request['Content-Type'] = 'application/json'
36
+ request['Authorization'] = "Bearer #{@config.reflex_auth_key}"
37
+ request['User-Agent'] = "brainzlab-sdk-ruby/#{BrainzLab::VERSION}"
38
38
  request.body = JSON.generate(body)
39
39
 
40
40
  execute_with_retry(uri, request)
@@ -47,7 +47,7 @@ module BrainzLab
47
47
  retries = 0
48
48
  begin
49
49
  http = Net::HTTP.new(uri.host, uri.port)
50
- http.use_ssl = uri.scheme == "https"
50
+ http.use_ssl = uri.scheme == 'https'
51
51
  http.open_timeout = 5
52
52
  http.read_timeout = 10
53
53
 
@@ -55,7 +55,11 @@ module BrainzLab
55
55
 
56
56
  case response.code.to_i
57
57
  when 200..299
58
- JSON.parse(response.body) rescue {}
58
+ begin
59
+ JSON.parse(response.body)
60
+ rescue StandardError
61
+ {}
62
+ end
59
63
  when 429, 500..599
60
64
  raise RetryableError, "Server error: #{response.code}"
61
65
  else
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "net/http"
4
- require "uri"
5
- require "json"
6
- require "fileutils"
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'json'
6
+ require 'fileutils'
7
7
 
8
8
  module BrainzLab
9
9
  module Reflex
10
10
  class Provisioner
11
- CACHE_DIR = ENV.fetch("BRAINZLAB_CACHE_DIR") { File.join(Dir.home, ".brainzlab") }
11
+ CACHE_DIR = ENV.fetch('BRAINZLAB_CACHE_DIR') { File.join(Dir.home, '.brainzlab') }
12
12
 
13
13
  def initialize(config)
14
14
  @config = config
@@ -38,10 +38,10 @@ module BrainzLab
38
38
 
39
39
  def should_provision?
40
40
  return false unless @config.reflex_auto_provision
41
- return false unless @config.app_name.to_s.strip.length > 0
41
+ return false unless @config.app_name.to_s.strip.length.positive?
42
42
  # Only skip if reflex_api_key is already set (not secret_key, which may be for Recall)
43
- return false if @config.reflex_api_key.to_s.strip.length > 0
44
- return false unless @config.reflex_master_key.to_s.strip.length > 0
43
+ return false if @config.reflex_api_key.to_s.strip.length.positive?
44
+ return false unless @config.reflex_master_key.to_s.strip.length.positive?
45
45
 
46
46
  true
47
47
  end
@@ -49,9 +49,9 @@ module BrainzLab
49
49
  def provision_project
50
50
  uri = URI.parse("#{@config.reflex_url}/api/v1/projects/provision")
51
51
  request = Net::HTTP::Post.new(uri)
52
- request["Content-Type"] = "application/json"
53
- request["X-Master-Key"] = @config.reflex_master_key
54
- request["User-Agent"] = "brainzlab-sdk-ruby/#{BrainzLab::VERSION}"
52
+ request['Content-Type'] = 'application/json'
53
+ request['X-Master-Key'] = @config.reflex_master_key
54
+ request['User-Agent'] = "brainzlab-sdk-ruby/#{BrainzLab::VERSION}"
55
55
  request.body = JSON.generate({ name: @config.app_name })
56
56
 
57
57
  response = execute(uri, request)
@@ -100,7 +100,7 @@ module BrainzLab
100
100
 
101
101
  def execute(uri, request)
102
102
  http = Net::HTTP.new(uri.host, uri.port)
103
- http.use_ssl = uri.scheme == "https"
103
+ http.use_ssl = uri.scheme == 'https'
104
104
  http.open_timeout = 5
105
105
  http.read_timeout = 10
106
106
  http.request(request)
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "reflex/client"
4
- require_relative "reflex/breadcrumbs"
5
- require_relative "reflex/provisioner"
3
+ require_relative 'reflex/client'
4
+ require_relative 'reflex/breadcrumbs'
5
+ require_relative 'reflex/provisioner'
6
6
 
7
7
  module BrainzLab
8
8
  module Reflex
@@ -77,7 +77,7 @@ module BrainzLab
77
77
  private
78
78
 
79
79
  def enabled?
80
- BrainzLab.configuration.reflex_enabled
80
+ BrainzLab.configuration.reflex_effectively_enabled?
81
81
  end
82
82
 
83
83
  def capture_disabled?
@@ -158,7 +158,7 @@ module BrainzLab
158
158
 
159
159
  payload = {
160
160
  timestamp: Time.now.utc.iso8601(3),
161
- error_class: "Message",
161
+ error_class: 'Message',
162
162
  message: message.to_s,
163
163
  level: level.to_s,
164
164
 
@@ -245,19 +245,19 @@ module BrainzLab
245
245
  # - "path/to/file.rb:42:in `method_name'" (backtick + single quote)
246
246
  # - "path/to/file.rb:42:in 'method_name'" (single quotes)
247
247
  # - "path/to/file.rb:42" (no method)
248
- if line =~ /\A(.+):(\d+):in [`'](.+)'?\z/
248
+ if line =~ /\A(.+):(\d+):in [`']([^']+)'?\z/
249
249
  {
250
- file: $1,
251
- line: $2.to_i,
252
- function: $3,
253
- in_app: in_app_frame?($1)
250
+ file: ::Regexp.last_match(1),
251
+ line: ::Regexp.last_match(2).to_i,
252
+ function: ::Regexp.last_match(3),
253
+ in_app: in_app_frame?(::Regexp.last_match(1))
254
254
  }
255
255
  elsif line =~ /\A(.+):(\d+)\z/
256
256
  {
257
- file: $1,
258
- line: $2.to_i,
257
+ file: ::Regexp.last_match(1),
258
+ line: ::Regexp.last_match(2).to_i,
259
259
  function: nil,
260
- in_app: in_app_frame?($1)
260
+ in_app: in_app_frame?(::Regexp.last_match(1))
261
261
  }
262
262
  else
263
263
  # Still store file for display even if format is unexpected
@@ -267,14 +267,14 @@ module BrainzLab
267
267
 
268
268
  def in_app_frame?(path)
269
269
  return false if path.nil?
270
- return false if path.include?("vendor/")
271
- return false if path.include?("/gems/")
272
- return false if path.include?("/ruby/")
270
+ return false if path.include?('vendor/')
271
+ return false if path.include?('/gems/')
272
+ return false if path.include?('/ruby/')
273
273
 
274
274
  # Match both relative and absolute paths containing app/ or lib/
275
- path.start_with?("app/", "lib/", "./app/", "./lib/") ||
276
- path.include?("/app/") ||
277
- path.include?("/lib/")
275
+ path.start_with?('app/', 'lib/', './app/', './lib/') ||
276
+ path.include?('/app/') ||
277
+ path.include?('/lib/')
278
278
  end
279
279
 
280
280
  def filter_params(params)
@@ -288,11 +288,11 @@ module BrainzLab
288
288
  case obj
289
289
  when Hash
290
290
  obj.each_with_object({}) do |(key, value), result|
291
- if should_filter?(key, fields)
292
- result[key] = "[FILTERED]"
293
- else
294
- result[key] = deep_filter(value, fields)
295
- end
291
+ result[key] = if should_filter?(key, fields)
292
+ '[FILTERED]'
293
+ else
294
+ deep_filter(value, fields)
295
+ end
296
296
  end
297
297
  when Array
298
298
  obj.map { |item| deep_filter(item, fields) }
@@ -363,12 +363,12 @@ module BrainzLab
363
363
 
364
364
  def in_app_line?(line)
365
365
  return false if line.nil?
366
- return false if line.include?("vendor/")
367
- return false if line.include?("/gems/")
366
+ return false if line.include?('vendor/')
367
+ return false if line.include?('/gems/')
368
368
 
369
- line.start_with?("app/", "lib/", "./app/", "./lib/") ||
370
- line.include?("/app/") ||
371
- line.include?("/lib/")
369
+ line.start_with?('app/', 'lib/', './app/', './lib/') ||
370
+ line.include?('/app/') ||
371
+ line.include?('/lib/')
372
372
  end
373
373
 
374
374
  def normalize_frame_for_fingerprint(frame)
@@ -377,9 +377,9 @@ module BrainzLab
377
377
  # Extract file and method, normalize out line numbers
378
378
  # "app/models/user.rb:42:in `save'" -> "app/models/user.rb:in `save'"
379
379
  if frame =~ /\A(.+):\d+:in `(.+)'\z/
380
- "#{$1}:in `#{$2}'"
380
+ "#{::Regexp.last_match(1)}:in `#{::Regexp.last_match(2)}'"
381
381
  elsif frame =~ /\A(.+):\d+\z/
382
- $1
382
+ ::Regexp.last_match(1)
383
383
  else
384
384
  frame
385
385
  end