brainzlab 0.1.2 → 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 (94) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +6 -21
  3. data/README.md +16 -2
  4. data/lib/brainzlab/beacon/client.rb +38 -40
  5. data/lib/brainzlab/beacon/provisioner.rb +1 -1
  6. data/lib/brainzlab/beacon.rb +15 -15
  7. data/lib/brainzlab/configuration.rb +92 -90
  8. data/lib/brainzlab/context.rb +2 -3
  9. data/lib/brainzlab/cortex/client.rb +29 -31
  10. data/lib/brainzlab/cortex/provisioner.rb +1 -1
  11. data/lib/brainzlab/cortex.rb +7 -11
  12. data/lib/brainzlab/dendrite/client.rb +42 -44
  13. data/lib/brainzlab/dendrite/provisioner.rb +1 -1
  14. data/lib/brainzlab/dendrite.rb +4 -4
  15. data/lib/brainzlab/devtools/data/collector.rb +22 -22
  16. data/lib/brainzlab/devtools/middleware/asset_server.rb +14 -14
  17. data/lib/brainzlab/devtools/middleware/database_handler.rb +52 -55
  18. data/lib/brainzlab/devtools/middleware/debug_panel.rb +19 -19
  19. data/lib/brainzlab/devtools/middleware/error_page.rb +45 -44
  20. data/lib/brainzlab/devtools/renderers/debug_panel_renderer.rb +39 -35
  21. data/lib/brainzlab/devtools/renderers/error_page_renderer.rb +13 -9
  22. data/lib/brainzlab/devtools.rb +11 -11
  23. data/lib/brainzlab/flux/buffer.rb +3 -3
  24. data/lib/brainzlab/flux/client.rb +14 -16
  25. data/lib/brainzlab/flux/provisioner.rb +13 -13
  26. data/lib/brainzlab/flux.rb +8 -8
  27. data/lib/brainzlab/instrumentation/action_mailer.rb +14 -13
  28. data/lib/brainzlab/instrumentation/active_record.rb +13 -15
  29. data/lib/brainzlab/instrumentation/aws.rb +43 -39
  30. data/lib/brainzlab/instrumentation/dalli.rb +20 -20
  31. data/lib/brainzlab/instrumentation/delayed_job.rb +27 -29
  32. data/lib/brainzlab/instrumentation/elasticsearch.rb +23 -24
  33. data/lib/brainzlab/instrumentation/excon.rb +27 -27
  34. data/lib/brainzlab/instrumentation/faraday.rb +3 -4
  35. data/lib/brainzlab/instrumentation/good_job.rb +28 -28
  36. data/lib/brainzlab/instrumentation/grape.rb +24 -24
  37. data/lib/brainzlab/instrumentation/graphql.rb +24 -23
  38. data/lib/brainzlab/instrumentation/httparty.rb +13 -14
  39. data/lib/brainzlab/instrumentation/mongodb.rb +7 -7
  40. data/lib/brainzlab/instrumentation/net_http.rb +6 -6
  41. data/lib/brainzlab/instrumentation/redis.rb +14 -21
  42. data/lib/brainzlab/instrumentation/resque.rb +23 -24
  43. data/lib/brainzlab/instrumentation/sidekiq.rb +29 -28
  44. data/lib/brainzlab/instrumentation/solid_queue.rb +37 -41
  45. data/lib/brainzlab/instrumentation/stripe.rb +36 -37
  46. data/lib/brainzlab/instrumentation/typhoeus.rb +19 -17
  47. data/lib/brainzlab/instrumentation.rb +20 -20
  48. data/lib/brainzlab/nerve/client.rb +38 -40
  49. data/lib/brainzlab/nerve/provisioner.rb +1 -1
  50. data/lib/brainzlab/nerve.rb +6 -6
  51. data/lib/brainzlab/pulse/client.rb +15 -11
  52. data/lib/brainzlab/pulse/instrumentation.rb +61 -57
  53. data/lib/brainzlab/pulse/propagation.rb +28 -28
  54. data/lib/brainzlab/pulse/provisioner.rb +12 -12
  55. data/lib/brainzlab/pulse/tracer.rb +3 -3
  56. data/lib/brainzlab/pulse.rb +13 -13
  57. data/lib/brainzlab/rails/log_formatter.rb +127 -121
  58. data/lib/brainzlab/rails/log_subscriber.rb +70 -76
  59. data/lib/brainzlab/rails/railtie.rb +66 -89
  60. data/lib/brainzlab/recall/buffer.rb +1 -1
  61. data/lib/brainzlab/recall/client.rb +14 -10
  62. data/lib/brainzlab/recall/logger.rb +16 -18
  63. data/lib/brainzlab/recall/provisioner.rb +16 -16
  64. data/lib/brainzlab/recall.rb +11 -13
  65. data/lib/brainzlab/reflex/breadcrumbs.rb +2 -2
  66. data/lib/brainzlab/reflex/client.rb +14 -10
  67. data/lib/brainzlab/reflex/provisioner.rb +12 -12
  68. data/lib/brainzlab/reflex.rb +29 -29
  69. data/lib/brainzlab/sentinel/client.rb +40 -42
  70. data/lib/brainzlab/sentinel/provisioner.rb +1 -1
  71. data/lib/brainzlab/sentinel.rb +5 -5
  72. data/lib/brainzlab/signal/client.rb +12 -14
  73. data/lib/brainzlab/signal/provisioner.rb +12 -12
  74. data/lib/brainzlab/signal.rb +7 -7
  75. data/lib/brainzlab/synapse/client.rb +42 -44
  76. data/lib/brainzlab/synapse/provisioner.rb +1 -1
  77. data/lib/brainzlab/synapse.rb +6 -6
  78. data/lib/brainzlab/utilities/circuit_breaker.rb +37 -41
  79. data/lib/brainzlab/utilities/health_check.rb +53 -55
  80. data/lib/brainzlab/utilities/log_formatter.rb +38 -40
  81. data/lib/brainzlab/utilities/rate_limiter.rb +5 -5
  82. data/lib/brainzlab/utilities.rb +4 -4
  83. data/lib/brainzlab/vault/cache.rb +1 -1
  84. data/lib/brainzlab/vault/client.rb +39 -41
  85. data/lib/brainzlab/vault/provisioner.rb +1 -1
  86. data/lib/brainzlab/vault.rb +19 -25
  87. data/lib/brainzlab/version.rb +1 -1
  88. data/lib/brainzlab/vision/client.rb +20 -20
  89. data/lib/brainzlab/vision/provisioner.rb +21 -21
  90. data/lib/brainzlab/vision.rb +17 -19
  91. data/lib/brainzlab-sdk.rb +1 -1
  92. data/lib/brainzlab.rb +22 -24
  93. data/lib/generators/brainzlab/install/install_generator.rb +29 -27
  94. metadata +1 -1
@@ -13,14 +13,14 @@ module BrainzLab
13
13
  # For GraphQL Ruby 2.0+
14
14
  if ::GraphQL::Schema.respond_to?(:trace_with)
15
15
  # Will be installed per-schema via BrainzLab::GraphQL::Tracer
16
- BrainzLab.debug_log("GraphQL tracer available - add `trace_with BrainzLab::Instrumentation::GraphQLInstrumentation::Tracer` to your schema")
16
+ BrainzLab.debug_log('GraphQL tracer available - add `trace_with BrainzLab::Instrumentation::GraphQLInstrumentation::Tracer` to your schema')
17
17
  end
18
18
 
19
19
  # Subscribe to ActiveSupport notifications if available
20
20
  install_notifications!
21
21
 
22
22
  @installed = true
23
- BrainzLab.debug_log("GraphQL instrumentation installed")
23
+ BrainzLab.debug_log('GraphQL instrumentation installed')
24
24
  end
25
25
 
26
26
  def installed?
@@ -35,17 +35,17 @@ module BrainzLab
35
35
 
36
36
  def install_notifications!
37
37
  # GraphQL-ruby emits ActiveSupport notifications
38
- ActiveSupport::Notifications.subscribe("execute.graphql") do |*args|
38
+ ActiveSupport::Notifications.subscribe('execute.graphql') do |*args|
39
39
  event = ActiveSupport::Notifications::Event.new(*args)
40
40
  record_execution(event)
41
41
  end
42
42
 
43
- ActiveSupport::Notifications.subscribe("analyze.graphql") do |*args|
43
+ ActiveSupport::Notifications.subscribe('analyze.graphql') do |*args|
44
44
  event = ActiveSupport::Notifications::Event.new(*args)
45
45
  record_analyze(event)
46
46
  end
47
47
 
48
- ActiveSupport::Notifications.subscribe("validate.graphql") do |*args|
48
+ ActiveSupport::Notifications.subscribe('validate.graphql') do |*args|
49
49
  event = ActiveSupport::Notifications::Event.new(*args)
50
50
  record_validate(event)
51
51
  end
@@ -56,15 +56,15 @@ module BrainzLab
56
56
  def record_execution(event)
57
57
  payload = event.payload
58
58
  query = payload[:query]
59
- operation_name = query&.operation_name || "anonymous"
60
- operation_type = query&.selected_operation&.operation_type || "query"
59
+ operation_name = query&.operation_name || 'anonymous'
60
+ operation_type = query&.selected_operation&.operation_type || 'query'
61
61
  duration_ms = event.duration.round(2)
62
62
 
63
63
  # Add breadcrumb
64
64
  if BrainzLab.configuration.reflex_enabled
65
65
  BrainzLab::Reflex.add_breadcrumb(
66
66
  "GraphQL #{operation_type} #{operation_name}",
67
- category: "graphql.execute",
67
+ category: 'graphql.execute',
68
68
  level: payload[:errors]&.any? ? :error : :info,
69
69
  data: {
70
70
  operation_name: operation_name,
@@ -78,7 +78,7 @@ module BrainzLab
78
78
  # Record span
79
79
  record_span(
80
80
  name: "GraphQL #{operation_type} #{operation_name}",
81
- kind: "graphql",
81
+ kind: 'graphql',
82
82
  duration_ms: duration_ms,
83
83
  started_at: event.time,
84
84
  ended_at: event.end,
@@ -97,12 +97,12 @@ module BrainzLab
97
97
 
98
98
  def record_analyze(event)
99
99
  record_span(
100
- name: "GraphQL analyze",
101
- kind: "graphql",
100
+ name: 'GraphQL analyze',
101
+ kind: 'graphql',
102
102
  duration_ms: event.duration.round(2),
103
103
  started_at: event.time,
104
104
  ended_at: event.end,
105
- data: { phase: "analyze" }
105
+ data: { phase: 'analyze' }
106
106
  )
107
107
  rescue StandardError => e
108
108
  BrainzLab.debug_log("GraphQL analyze recording failed: #{e.message}")
@@ -110,12 +110,12 @@ module BrainzLab
110
110
 
111
111
  def record_validate(event)
112
112
  record_span(
113
- name: "GraphQL validate",
114
- kind: "graphql",
113
+ name: 'GraphQL validate',
114
+ kind: 'graphql',
115
115
  duration_ms: event.duration.round(2),
116
116
  started_at: event.time,
117
117
  ended_at: event.end,
118
- data: { phase: "validate" }
118
+ data: { phase: 'validate' }
119
119
  )
120
120
  rescue StandardError => e
121
121
  BrainzLab.debug_log("GraphQL validate recording failed: #{e.message}")
@@ -139,6 +139,7 @@ module BrainzLab
139
139
 
140
140
  def truncate_query(query)
141
141
  return nil unless query
142
+
142
143
  query.to_s[0, 2000]
143
144
  end
144
145
 
@@ -148,7 +149,7 @@ module BrainzLab
148
149
  scrub_fields = BrainzLab.configuration.scrub_fields
149
150
  variables.transform_values do |value|
150
151
  if scrub_fields.any? { |f| value.to_s.downcase.include?(f.to_s) }
151
- "[FILTERED]"
152
+ '[FILTERED]'
152
153
  else
153
154
  value
154
155
  end
@@ -163,19 +164,19 @@ module BrainzLab
163
164
  module Tracer
164
165
  def execute_query(query:)
165
166
  started_at = Time.now.utc
166
- operation_name = query.operation_name || "anonymous"
167
- operation_type = query.selected_operation&.operation_type || "query"
167
+ operation_name = query.operation_name || 'anonymous'
168
+ operation_type = query.selected_operation&.operation_type || 'query'
168
169
 
169
170
  result = super
170
171
 
171
172
  duration_ms = ((Time.now.utc - started_at) * 1000).round(2)
172
- has_errors = result.to_h["errors"]&.any?
173
+ has_errors = result.to_h['errors']&.any?
173
174
 
174
175
  # Add breadcrumb
175
176
  if BrainzLab.configuration.reflex_enabled
176
177
  BrainzLab::Reflex.add_breadcrumb(
177
178
  "GraphQL #{operation_type} #{operation_name}",
178
- category: "graphql.execute",
179
+ category: 'graphql.execute',
179
180
  level: has_errors ? :error : :info,
180
181
  data: {
181
182
  operation_name: operation_name,
@@ -191,7 +192,7 @@ module BrainzLab
191
192
  spans << {
192
193
  span_id: SecureRandom.uuid,
193
194
  name: "GraphQL #{operation_type} #{operation_name}",
194
- kind: "graphql",
195
+ kind: 'graphql',
195
196
  started_at: started_at,
196
197
  ended_at: Time.now.utc,
197
198
  duration_ms: duration_ms,
@@ -209,7 +210,7 @@ module BrainzLab
209
210
  if BrainzLab.configuration.reflex_enabled
210
211
  BrainzLab::Reflex.add_breadcrumb(
211
212
  "GraphQL #{operation_type} #{operation_name} failed",
212
- category: "graphql.error",
213
+ category: 'graphql.error',
213
214
  level: :error,
214
215
  data: { error: e.class.name }
215
216
  )
@@ -231,7 +232,7 @@ module BrainzLab
231
232
  spans << {
232
233
  span_id: SecureRandom.uuid,
233
234
  name: "GraphQL field #{field.owner.graphql_name}.#{field.graphql_name}",
234
- kind: "graphql.field",
235
+ kind: 'graphql.field',
235
236
  started_at: started_at,
236
237
  ended_at: Time.now.utc,
237
238
  duration_ms: duration_ms,
@@ -13,7 +13,7 @@ module BrainzLab
13
13
  ::HTTParty.singleton_class.prepend(Patch)
14
14
 
15
15
  @installed = true
16
- BrainzLab.debug_log("HTTParty instrumentation installed")
16
+ BrainzLab.debug_log('HTTParty instrumentation installed')
17
17
  end
18
18
 
19
19
  def installed?
@@ -26,14 +26,13 @@ module BrainzLab
26
26
  end
27
27
 
28
28
  module Patch
29
- def perform_request(http_method, path, options = {}, &block)
29
+ def perform_request(http_method, path, options = {}, &)
30
30
  return super unless should_track?(path, options)
31
31
 
32
32
  # Inject distributed tracing headers
33
33
  options = inject_trace_context(options)
34
34
 
35
35
  started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
36
- error_info = nil
37
36
 
38
37
  begin
39
38
  response = super
@@ -79,7 +78,7 @@ module BrainzLab
79
78
  method = extract_method_name(http_method)
80
79
  uri = parse_uri(path, options)
81
80
  url = uri ? sanitize_url(uri) : path.to_s
82
- host = uri&.host || "unknown"
81
+ host = uri&.host || 'unknown'
83
82
  request_path = uri&.path || path.to_s
84
83
  level = error || (status && status >= 400) ? :error : :info
85
84
 
@@ -87,7 +86,7 @@ module BrainzLab
87
86
  if BrainzLab.configuration.reflex_enabled
88
87
  BrainzLab::Reflex.add_breadcrumb(
89
88
  "#{method} #{url}",
90
- category: "http.httparty",
89
+ category: 'http.httparty',
91
90
  level: level,
92
91
  data: {
93
92
  method: method,
@@ -127,7 +126,7 @@ module BrainzLab
127
126
  span = {
128
127
  span_id: SecureRandom.uuid,
129
128
  name: "HTTP #{method} #{host}",
130
- kind: "http",
129
+ kind: 'http',
131
130
  started_at: Time.now.utc - (duration_ms / 1000.0),
132
131
  ended_at: Time.now.utc,
133
132
  duration_ms: duration_ms,
@@ -149,14 +148,14 @@ module BrainzLab
149
148
 
150
149
  def extract_method_name(http_method)
151
150
  case http_method.name
152
- when /Get$/ then "GET"
153
- when /Post$/ then "POST"
154
- when /Put$/ then "PUT"
155
- when /Patch$/ then "PATCH"
156
- when /Delete$/ then "DELETE"
157
- when /Head$/ then "HEAD"
158
- when /Options$/ then "OPTIONS"
159
- else http_method.name.split("::").last.upcase
151
+ when /Get$/ then 'GET'
152
+ when /Post$/ then 'POST'
153
+ when /Put$/ then 'PUT'
154
+ when /Patch$/ then 'PATCH'
155
+ when /Delete$/ then 'DELETE'
156
+ when /Head$/ then 'HEAD'
157
+ when /Options$/ then 'OPTIONS'
158
+ else http_method.name.split('::').last.upcase
160
159
  end
161
160
  end
162
161
 
@@ -26,7 +26,7 @@ module BrainzLab
26
26
  return unless installed_any
27
27
 
28
28
  @installed = true
29
- BrainzLab.debug_log("MongoDB instrumentation installed")
29
+ BrainzLab.debug_log('MongoDB instrumentation installed')
30
30
  end
31
31
 
32
32
  def installed?
@@ -51,9 +51,9 @@ module BrainzLab
51
51
 
52
52
  def install_mongoid!
53
53
  # For Mongoid 7+, use the APM module
54
- if ::Mongoid.respond_to?(:subscribe)
55
- ::Mongoid.subscribe(CommandSubscriber.new)
56
- end
54
+ return unless ::Mongoid.respond_to?(:subscribe)
55
+
56
+ ::Mongoid.subscribe(CommandSubscriber.new)
57
57
  end
58
58
  end
59
59
 
@@ -96,7 +96,7 @@ module BrainzLab
96
96
  def extract_collection(event)
97
97
  # Try to extract collection name from command
98
98
  cmd = event.command
99
- cmd["collection"] || cmd[event.command_name] || cmd.keys.first
99
+ cmd['collection'] || cmd[event.command_name] || cmd.keys.first
100
100
  rescue StandardError
101
101
  nil
102
102
  end
@@ -116,7 +116,7 @@ module BrainzLab
116
116
  if BrainzLab.configuration.reflex_enabled
117
117
  BrainzLab::Reflex.add_breadcrumb(
118
118
  "MongoDB #{command_name}",
119
- category: "mongodb",
119
+ category: 'mongodb',
120
120
  level: level,
121
121
  data: {
122
122
  command: command_name,
@@ -163,7 +163,7 @@ module BrainzLab
163
163
  span = {
164
164
  span_id: SecureRandom.uuid,
165
165
  name: "MongoDB #{command_name} #{collection}".strip,
166
- kind: "mongodb",
166
+ kind: 'mongodb',
167
167
  started_at: started_at,
168
168
  ended_at: Time.now.utc,
169
169
  duration_ms: duration_ms.round(2),
@@ -24,7 +24,7 @@ module BrainzLab
24
24
  end
25
25
 
26
26
  module Patch
27
- def request(req, body = nil, &block)
27
+ def request(req, body = nil, &)
28
28
  return super unless should_track?
29
29
 
30
30
  # Inject distributed tracing context into outgoing request headers
@@ -38,7 +38,7 @@ module BrainzLab
38
38
  response = super
39
39
  track_request(method, url, response.code.to_i, started_at)
40
40
  response
41
- rescue => e
41
+ rescue StandardError => e
42
42
  track_request(method, url, nil, started_at, e.class.name)
43
43
  raise
44
44
  end
@@ -69,9 +69,9 @@ module BrainzLab
69
69
  end
70
70
 
71
71
  def build_url(req)
72
- scheme = use_ssl? ? "https" : "http"
72
+ scheme = use_ssl? ? 'https' : 'http'
73
73
  port_str = if (use_ssl? && port == 443) || (!use_ssl? && port == 80)
74
- ""
74
+ ''
75
75
  else
76
76
  ":#{port}"
77
77
  end
@@ -86,7 +86,7 @@ module BrainzLab
86
86
  if BrainzLab.configuration.reflex_enabled
87
87
  BrainzLab::Reflex.add_breadcrumb(
88
88
  "#{method} #{url}",
89
- category: "http",
89
+ category: 'http',
90
90
  level: level,
91
91
  data: { method: method, url: url, status_code: status, duration_ms: duration_ms, error: error }.compact
92
92
  )
@@ -99,7 +99,7 @@ module BrainzLab
99
99
  method: method, url: url, status_code: status, duration_ms: duration_ms, error: error
100
100
  )
101
101
  end
102
- rescue => e
102
+ rescue StandardError => e
103
103
  # Don't let instrumentation errors crash the app
104
104
  BrainzLab.configuration.logger&.error("[BrainzLab] HTTP instrumentation error: #{e.message}")
105
105
  end
@@ -18,7 +18,7 @@ module BrainzLab
18
18
  end
19
19
 
20
20
  @installed = true
21
- BrainzLab.debug_log("Redis instrumentation installed")
21
+ BrainzLab.debug_log('Redis instrumentation installed')
22
22
  end
23
23
 
24
24
  def installed?
@@ -32,7 +32,7 @@ module BrainzLab
32
32
  private
33
33
 
34
34
  def redis_5_or_newer?
35
- defined?(::Redis::VERSION) && Gem::Version.new(::Redis::VERSION) >= Gem::Version.new("5.0")
35
+ defined?(::Redis::VERSION) && Gem::Version.new(::Redis::VERSION) >= Gem::Version.new('5.0')
36
36
  end
37
37
 
38
38
  def install_middleware!
@@ -50,10 +50,6 @@ module BrainzLab
50
50
 
51
51
  # Middleware for Redis 5+ (RedisClient)
52
52
  module Middleware
53
- def connect(redis_config)
54
- super
55
- end
56
-
57
53
  def call(command, redis_config)
58
54
  return super unless should_track?
59
55
 
@@ -78,10 +74,10 @@ module BrainzLab
78
74
  ignore.map(&:downcase).include?(cmd_name)
79
75
  end
80
76
 
81
- def track_command(command, &block)
77
+ def track_command(command)
82
78
  return yield if should_skip_command?(command)
79
+
83
80
  started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
84
- error_info = nil
85
81
 
86
82
  begin
87
83
  result = yield
@@ -94,9 +90,8 @@ module BrainzLab
94
90
  end
95
91
  end
96
92
 
97
- def track_pipeline(commands, &block)
93
+ def track_pipeline(commands)
98
94
  started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
99
- error_info = nil
100
95
 
101
96
  begin
102
97
  result = yield
@@ -119,7 +114,7 @@ module BrainzLab
119
114
  if BrainzLab.configuration.reflex_enabled
120
115
  BrainzLab::Reflex.add_breadcrumb(
121
116
  "Redis #{cmd_name}",
122
- category: "redis",
117
+ category: 'redis',
123
118
  level: level,
124
119
  data: {
125
120
  command: cmd_name,
@@ -138,14 +133,14 @@ module BrainzLab
138
133
 
139
134
  def record_pipeline(commands, started_at, error = nil)
140
135
  duration_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - started_at) * 1000).round(2)
141
- cmd_names = commands.map { |c| c.first.to_s.upcase }.uniq.join(", ")
136
+ cmd_names = commands.map { |c| c.first.to_s.upcase }.uniq.join(', ')
142
137
  level = error ? :error : :info
143
138
 
144
139
  # Add breadcrumb for Reflex
145
140
  if BrainzLab.configuration.reflex_enabled
146
141
  BrainzLab::Reflex.add_breadcrumb(
147
142
  "Redis PIPELINE (#{commands.size} commands)",
148
- category: "redis",
143
+ category: 'redis',
149
144
  level: level,
150
145
  data: {
151
146
  commands: cmd_names,
@@ -157,7 +152,7 @@ module BrainzLab
157
152
  end
158
153
 
159
154
  # Record span for Pulse APM
160
- record_pulse_span("PIPELINE", nil, duration_ms, error, commands.size)
155
+ record_pulse_span('PIPELINE', nil, duration_ms, error, commands.size)
161
156
  rescue StandardError => e
162
157
  BrainzLab.debug_log("Redis instrumentation error: #{e.message}")
163
158
  end
@@ -169,7 +164,7 @@ module BrainzLab
169
164
  span = {
170
165
  span_id: SecureRandom.uuid,
171
166
  name: "Redis #{command}",
172
- kind: "redis",
167
+ kind: 'redis',
173
168
  started_at: Time.now.utc - (duration_ms / 1000.0),
174
169
  ended_at: Time.now.utc,
175
170
  duration_ms: duration_ms,
@@ -210,7 +205,6 @@ module BrainzLab
210
205
  return super if should_skip_command?(command)
211
206
 
212
207
  started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
213
- error_info = nil
214
208
 
215
209
  begin
216
210
  result = super
@@ -227,7 +221,6 @@ module BrainzLab
227
221
  return super unless should_track?
228
222
 
229
223
  started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
230
- error_info = nil
231
224
  commands = pipeline.commands
232
225
 
233
226
  begin
@@ -262,7 +255,7 @@ module BrainzLab
262
255
  if BrainzLab.configuration.reflex_enabled
263
256
  BrainzLab::Reflex.add_breadcrumb(
264
257
  "Redis #{cmd_name}",
265
- category: "redis",
258
+ category: 'redis',
266
259
  level: level,
267
260
  data: {
268
261
  command: cmd_name,
@@ -285,7 +278,7 @@ module BrainzLab
285
278
  if BrainzLab.configuration.reflex_enabled
286
279
  BrainzLab::Reflex.add_breadcrumb(
287
280
  "Redis PIPELINE (#{commands.size} commands)",
288
- category: "redis",
281
+ category: 'redis',
289
282
  level: level,
290
283
  data: {
291
284
  count: commands.size,
@@ -295,7 +288,7 @@ module BrainzLab
295
288
  )
296
289
  end
297
290
 
298
- record_pulse_span("PIPELINE", nil, duration_ms, error, commands.size)
291
+ record_pulse_span('PIPELINE', nil, duration_ms, error, commands.size)
299
292
  rescue StandardError => e
300
293
  BrainzLab.debug_log("Redis instrumentation error: #{e.message}")
301
294
  end
@@ -307,7 +300,7 @@ module BrainzLab
307
300
  span = {
308
301
  span_id: SecureRandom.uuid,
309
302
  name: "Redis #{command}",
310
- kind: "redis",
303
+ kind: 'redis',
311
304
  started_at: Time.now.utc - (duration_ms / 1000.0),
312
305
  ended_at: Time.now.utc,
313
306
  duration_ms: duration_ms,
@@ -10,13 +10,13 @@ module BrainzLab
10
10
  install_hooks!
11
11
  install_failure_backend!
12
12
 
13
- BrainzLab.debug_log("[Instrumentation] Resque instrumentation installed")
13
+ BrainzLab.debug_log('[Instrumentation] Resque instrumentation installed')
14
14
  end
15
15
 
16
16
  private
17
17
 
18
18
  def install_hooks!
19
- ::Resque.before_fork do |job|
19
+ ::Resque.before_fork do |_job|
20
20
  # Clear any stale connections before forking
21
21
  BrainzLab::Recall.reset! if defined?(BrainzLab::Recall)
22
22
  BrainzLab::Pulse.reset! if defined?(BrainzLab::Pulse)
@@ -38,31 +38,30 @@ module BrainzLab
38
38
  end
39
39
 
40
40
  def save
41
- job_class = @payload["class"] || "Unknown"
41
+ job_class = @payload['class'] || 'Unknown'
42
42
 
43
43
  if BrainzLab.configuration.reflex_effectively_enabled?
44
44
  BrainzLab::Reflex.capture(@exception,
45
- tags: { job_class: job_class, queue: @queue, source: "resque" },
46
- extra: {
47
- worker: @worker.to_s,
48
- args: @payload["args"]
49
- }
50
- )
45
+ tags: { job_class: job_class, queue: @queue, source: 'resque' },
46
+ extra: {
47
+ worker: @worker.to_s,
48
+ args: @payload['args']
49
+ })
51
50
  end
52
51
 
53
- if BrainzLab.configuration.flux_effectively_enabled?
54
- BrainzLab::Flux.increment("resque.job.failed", tags: { job_class: job_class, queue: @queue })
55
- end
52
+ return unless BrainzLab.configuration.flux_effectively_enabled?
53
+
54
+ BrainzLab::Flux.increment('resque.job.failed', tags: { job_class: job_class, queue: @queue })
56
55
  end
57
56
  end
58
57
 
59
58
  # Add our failure backend to the chain
60
- if defined?(::Resque::Failure)
61
- ::Resque::Failure.backend = ::Resque::Failure::Multiple.new(
62
- ::Resque::Failure.backend,
63
- failure_backend
64
- )
65
- end
59
+ return unless defined?(::Resque::Failure)
60
+
61
+ ::Resque::Failure.backend = ::Resque::Failure::Multiple.new(
62
+ ::Resque::Failure.backend,
63
+ failure_backend
64
+ )
66
65
  end
67
66
  end
68
67
 
@@ -73,9 +72,9 @@ module BrainzLab
73
72
  end
74
73
 
75
74
  module ClassMethods
76
- def around_perform_brainzlab(*args)
77
- job_class = self.name
78
- queue = Resque.queue_from_class(self) || "default"
75
+ def around_perform_brainzlab(*_args)
76
+ job_class = name
77
+ queue = Resque.queue_from_class(self) || 'default'
79
78
  started_at = Time.now
80
79
 
81
80
  BrainzLab::Context.current.set_context(
@@ -91,7 +90,7 @@ module BrainzLab
91
90
  if BrainzLab.configuration.pulse_effectively_enabled?
92
91
  BrainzLab::Pulse.record_trace(
93
92
  "job.#{job_class}",
94
- kind: "job",
93
+ kind: 'job',
95
94
  started_at: started_at,
96
95
  ended_at: Time.now,
97
96
  job_class: job_class,
@@ -101,8 +100,8 @@ module BrainzLab
101
100
 
102
101
  if BrainzLab.configuration.flux_effectively_enabled?
103
102
  tags = { job_class: job_class, queue: queue }
104
- BrainzLab::Flux.distribution("resque.job.duration_ms", duration_ms, tags: tags)
105
- BrainzLab::Flux.increment("resque.job.processed", tags: tags)
103
+ BrainzLab::Flux.distribution('resque.job.duration_ms', duration_ms, tags: tags)
104
+ BrainzLab::Flux.increment('resque.job.processed', tags: tags)
106
105
  end
107
106
 
108
107
  BrainzLab.clear_context!