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.
- checksums.yaml +4 -4
- data/LICENSE +6 -21
- data/README.md +16 -2
- data/lib/brainzlab/beacon/client.rb +38 -40
- data/lib/brainzlab/beacon/provisioner.rb +1 -1
- data/lib/brainzlab/beacon.rb +15 -15
- data/lib/brainzlab/configuration.rb +92 -90
- data/lib/brainzlab/context.rb +2 -3
- data/lib/brainzlab/cortex/client.rb +29 -31
- data/lib/brainzlab/cortex/provisioner.rb +1 -1
- data/lib/brainzlab/cortex.rb +7 -11
- data/lib/brainzlab/dendrite/client.rb +42 -44
- data/lib/brainzlab/dendrite/provisioner.rb +1 -1
- data/lib/brainzlab/dendrite.rb +4 -4
- data/lib/brainzlab/devtools/data/collector.rb +22 -22
- data/lib/brainzlab/devtools/middleware/asset_server.rb +14 -14
- data/lib/brainzlab/devtools/middleware/database_handler.rb +52 -55
- data/lib/brainzlab/devtools/middleware/debug_panel.rb +19 -19
- data/lib/brainzlab/devtools/middleware/error_page.rb +45 -44
- data/lib/brainzlab/devtools/renderers/debug_panel_renderer.rb +39 -35
- data/lib/brainzlab/devtools/renderers/error_page_renderer.rb +13 -9
- data/lib/brainzlab/devtools.rb +11 -11
- data/lib/brainzlab/flux/buffer.rb +3 -3
- data/lib/brainzlab/flux/client.rb +14 -16
- data/lib/brainzlab/flux/provisioner.rb +13 -13
- data/lib/brainzlab/flux.rb +8 -8
- data/lib/brainzlab/instrumentation/action_mailer.rb +14 -13
- data/lib/brainzlab/instrumentation/active_record.rb +13 -15
- data/lib/brainzlab/instrumentation/aws.rb +43 -39
- data/lib/brainzlab/instrumentation/dalli.rb +20 -20
- data/lib/brainzlab/instrumentation/delayed_job.rb +27 -29
- data/lib/brainzlab/instrumentation/elasticsearch.rb +23 -24
- data/lib/brainzlab/instrumentation/excon.rb +27 -27
- data/lib/brainzlab/instrumentation/faraday.rb +3 -4
- data/lib/brainzlab/instrumentation/good_job.rb +28 -28
- data/lib/brainzlab/instrumentation/grape.rb +24 -24
- data/lib/brainzlab/instrumentation/graphql.rb +24 -23
- data/lib/brainzlab/instrumentation/httparty.rb +13 -14
- data/lib/brainzlab/instrumentation/mongodb.rb +7 -7
- data/lib/brainzlab/instrumentation/net_http.rb +6 -6
- data/lib/brainzlab/instrumentation/redis.rb +14 -21
- data/lib/brainzlab/instrumentation/resque.rb +23 -24
- data/lib/brainzlab/instrumentation/sidekiq.rb +29 -28
- data/lib/brainzlab/instrumentation/solid_queue.rb +37 -41
- data/lib/brainzlab/instrumentation/stripe.rb +36 -37
- data/lib/brainzlab/instrumentation/typhoeus.rb +19 -17
- data/lib/brainzlab/instrumentation.rb +20 -20
- data/lib/brainzlab/nerve/client.rb +38 -40
- data/lib/brainzlab/nerve/provisioner.rb +1 -1
- data/lib/brainzlab/nerve.rb +6 -6
- data/lib/brainzlab/pulse/client.rb +15 -11
- data/lib/brainzlab/pulse/instrumentation.rb +61 -57
- data/lib/brainzlab/pulse/propagation.rb +28 -28
- data/lib/brainzlab/pulse/provisioner.rb +12 -12
- data/lib/brainzlab/pulse/tracer.rb +3 -3
- data/lib/brainzlab/pulse.rb +13 -13
- data/lib/brainzlab/rails/log_formatter.rb +127 -121
- data/lib/brainzlab/rails/log_subscriber.rb +70 -76
- data/lib/brainzlab/rails/railtie.rb +66 -89
- data/lib/brainzlab/recall/buffer.rb +1 -1
- data/lib/brainzlab/recall/client.rb +14 -10
- data/lib/brainzlab/recall/logger.rb +16 -18
- data/lib/brainzlab/recall/provisioner.rb +16 -16
- data/lib/brainzlab/recall.rb +11 -13
- data/lib/brainzlab/reflex/breadcrumbs.rb +2 -2
- data/lib/brainzlab/reflex/client.rb +14 -10
- data/lib/brainzlab/reflex/provisioner.rb +12 -12
- data/lib/brainzlab/reflex.rb +29 -29
- data/lib/brainzlab/sentinel/client.rb +40 -42
- data/lib/brainzlab/sentinel/provisioner.rb +1 -1
- data/lib/brainzlab/sentinel.rb +5 -5
- data/lib/brainzlab/signal/client.rb +12 -14
- data/lib/brainzlab/signal/provisioner.rb +12 -12
- data/lib/brainzlab/signal.rb +7 -7
- data/lib/brainzlab/synapse/client.rb +42 -44
- data/lib/brainzlab/synapse/provisioner.rb +1 -1
- data/lib/brainzlab/synapse.rb +6 -6
- data/lib/brainzlab/utilities/circuit_breaker.rb +37 -41
- data/lib/brainzlab/utilities/health_check.rb +53 -55
- data/lib/brainzlab/utilities/log_formatter.rb +38 -40
- data/lib/brainzlab/utilities/rate_limiter.rb +5 -5
- data/lib/brainzlab/utilities.rb +4 -4
- data/lib/brainzlab/vault/cache.rb +1 -1
- data/lib/brainzlab/vault/client.rb +39 -41
- data/lib/brainzlab/vault/provisioner.rb +1 -1
- data/lib/brainzlab/vault.rb +19 -25
- data/lib/brainzlab/version.rb +1 -1
- data/lib/brainzlab/vision/client.rb +20 -20
- data/lib/brainzlab/vision/provisioner.rb +21 -21
- data/lib/brainzlab/vision.rb +17 -19
- data/lib/brainzlab-sdk.rb +1 -1
- data/lib/brainzlab.rb +22 -24
- data/lib/generators/brainzlab/install/install_generator.rb +29 -27
- metadata +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
3
|
+
require 'net/http'
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'uri'
|
|
6
6
|
|
|
7
7
|
module BrainzLab
|
|
8
8
|
module Flux
|
|
@@ -12,23 +12,23 @@ module BrainzLab
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def send_event(event)
|
|
15
|
-
post(
|
|
15
|
+
post('/api/v1/events', event)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def send_events(events)
|
|
19
|
-
post(
|
|
19
|
+
post('/api/v1/events/batch', { events: events })
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def send_metric(metric)
|
|
23
|
-
post(
|
|
23
|
+
post('/api/v1/metrics', metric)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def send_metrics(metrics)
|
|
27
|
-
post(
|
|
27
|
+
post('/api/v1/metrics/batch', { metrics: metrics })
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def send_batch(events:, metrics:)
|
|
31
|
-
post(
|
|
31
|
+
post('/api/v1/flux/batch', { events: events, metrics: metrics })
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
private
|
|
@@ -36,24 +36,22 @@ module BrainzLab
|
|
|
36
36
|
def post(path, body)
|
|
37
37
|
uri = URI.parse("#{base_url}#{path}")
|
|
38
38
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
39
|
-
http.use_ssl = uri.scheme ==
|
|
39
|
+
http.use_ssl = uri.scheme == 'https'
|
|
40
40
|
http.open_timeout = 5
|
|
41
41
|
http.read_timeout = 10
|
|
42
42
|
|
|
43
43
|
request = Net::HTTP::Post.new(uri.path)
|
|
44
|
-
request[
|
|
45
|
-
request[
|
|
46
|
-
request[
|
|
44
|
+
request['Content-Type'] = 'application/json'
|
|
45
|
+
request['Authorization'] = "Bearer #{api_key}"
|
|
46
|
+
request['User-Agent'] = "brainzlab-sdk/#{BrainzLab::VERSION}"
|
|
47
47
|
request.body = body.to_json
|
|
48
48
|
|
|
49
49
|
response = http.request(request)
|
|
50
50
|
|
|
51
|
-
unless response.is_a?(Net::HTTPSuccess)
|
|
52
|
-
BrainzLab.debug("[Flux] Request failed: #{response.code} - #{response.body}")
|
|
53
|
-
end
|
|
51
|
+
BrainzLab.debug("[Flux] Request failed: #{response.code} - #{response.body}") unless response.is_a?(Net::HTTPSuccess)
|
|
54
52
|
|
|
55
53
|
response
|
|
56
|
-
rescue => e
|
|
54
|
+
rescue StandardError => e
|
|
57
55
|
BrainzLab.debug("[Flux] Request error: #{e.message}")
|
|
58
56
|
nil
|
|
59
57
|
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
3
|
+
require 'net/http'
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'uri'
|
|
6
6
|
|
|
7
7
|
module BrainzLab
|
|
8
8
|
module Flux
|
|
@@ -17,7 +17,7 @@ module BrainzLab
|
|
|
17
17
|
return unless @config.flux_url && !@config.flux_url.to_s.empty?
|
|
18
18
|
return unless @config.secret_key && !@config.secret_key.to_s.empty?
|
|
19
19
|
|
|
20
|
-
BrainzLab.debug_log(
|
|
20
|
+
BrainzLab.debug_log('[Flux] Auto-provisioning project...')
|
|
21
21
|
provision_project
|
|
22
22
|
end
|
|
23
23
|
|
|
@@ -26,16 +26,16 @@ module BrainzLab
|
|
|
26
26
|
def provision_project
|
|
27
27
|
uri = URI.parse("#{@config.flux_url}/api/v1/projects/provision")
|
|
28
28
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
29
|
-
http.use_ssl = uri.scheme ==
|
|
29
|
+
http.use_ssl = uri.scheme == 'https'
|
|
30
30
|
http.open_timeout = 10
|
|
31
31
|
http.read_timeout = 30
|
|
32
32
|
|
|
33
33
|
request = Net::HTTP::Post.new(uri.path)
|
|
34
|
-
request[
|
|
35
|
-
request[
|
|
36
|
-
request[
|
|
34
|
+
request['Content-Type'] = 'application/json'
|
|
35
|
+
request['Authorization'] = "Bearer #{@config.secret_key}"
|
|
36
|
+
request['User-Agent'] = "brainzlab-sdk/#{BrainzLab::VERSION}"
|
|
37
37
|
request.body = {
|
|
38
|
-
name: @config.service ||
|
|
38
|
+
name: @config.service || 'default',
|
|
39
39
|
environment: @config.environment
|
|
40
40
|
}.to_json
|
|
41
41
|
|
|
@@ -43,13 +43,13 @@ module BrainzLab
|
|
|
43
43
|
|
|
44
44
|
if response.is_a?(Net::HTTPSuccess)
|
|
45
45
|
data = JSON.parse(response.body)
|
|
46
|
-
@config.flux_ingest_key = data[
|
|
47
|
-
@config.flux_api_key = data[
|
|
48
|
-
BrainzLab.debug_log(
|
|
46
|
+
@config.flux_ingest_key = data['ingest_key']
|
|
47
|
+
@config.flux_api_key = data['api_key']
|
|
48
|
+
BrainzLab.debug_log('[Flux] Project provisioned successfully')
|
|
49
49
|
else
|
|
50
50
|
BrainzLab.debug_log("[Flux] Provisioning failed: #{response.code} - #{response.body}")
|
|
51
51
|
end
|
|
52
|
-
rescue => e
|
|
52
|
+
rescue StandardError => e
|
|
53
53
|
BrainzLab.debug_log("[Flux] Provisioning error: #{e.message}")
|
|
54
54
|
end
|
|
55
55
|
end
|
data/lib/brainzlab/flux.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative
|
|
4
|
-
require_relative
|
|
5
|
-
require_relative
|
|
3
|
+
require_relative 'flux/client'
|
|
4
|
+
require_relative 'flux/buffer'
|
|
5
|
+
require_relative 'flux/provisioner'
|
|
6
6
|
|
|
7
7
|
module BrainzLab
|
|
8
8
|
module Flux
|
|
@@ -49,7 +49,7 @@ module BrainzLab
|
|
|
49
49
|
return unless BrainzLab.configuration.flux_valid?
|
|
50
50
|
|
|
51
51
|
metric = {
|
|
52
|
-
type:
|
|
52
|
+
type: 'gauge',
|
|
53
53
|
name: name,
|
|
54
54
|
value: value,
|
|
55
55
|
tags: tags,
|
|
@@ -67,7 +67,7 @@ module BrainzLab
|
|
|
67
67
|
return unless BrainzLab.configuration.flux_valid?
|
|
68
68
|
|
|
69
69
|
metric = {
|
|
70
|
-
type:
|
|
70
|
+
type: 'counter',
|
|
71
71
|
name: name,
|
|
72
72
|
value: value,
|
|
73
73
|
tags: tags,
|
|
@@ -90,7 +90,7 @@ module BrainzLab
|
|
|
90
90
|
return unless BrainzLab.configuration.flux_valid?
|
|
91
91
|
|
|
92
92
|
metric = {
|
|
93
|
-
type:
|
|
93
|
+
type: 'distribution',
|
|
94
94
|
name: name,
|
|
95
95
|
value: value,
|
|
96
96
|
tags: tags,
|
|
@@ -108,7 +108,7 @@ module BrainzLab
|
|
|
108
108
|
return unless BrainzLab.configuration.flux_valid?
|
|
109
109
|
|
|
110
110
|
metric = {
|
|
111
|
-
type:
|
|
111
|
+
type: 'set',
|
|
112
112
|
name: name,
|
|
113
113
|
value: value.to_s,
|
|
114
114
|
tags: tags,
|
|
@@ -127,7 +127,7 @@ module BrainzLab
|
|
|
127
127
|
yield
|
|
128
128
|
ensure
|
|
129
129
|
duration_ms = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start) * 1000
|
|
130
|
-
distribution(name, duration_ms, tags: tags.merge(unit:
|
|
130
|
+
distribution(name, duration_ms, tags: tags.merge(unit: 'ms'))
|
|
131
131
|
end
|
|
132
132
|
end
|
|
133
133
|
|
|
@@ -11,19 +11,19 @@ module BrainzLab
|
|
|
11
11
|
return if @installed
|
|
12
12
|
|
|
13
13
|
# Subscribe to deliver notification
|
|
14
|
-
ActiveSupport::Notifications.subscribe(
|
|
14
|
+
ActiveSupport::Notifications.subscribe('deliver.action_mailer') do |*args|
|
|
15
15
|
event = ActiveSupport::Notifications::Event.new(*args)
|
|
16
16
|
record_delivery(event)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
# Subscribe to process notification (when mail is being prepared)
|
|
20
|
-
ActiveSupport::Notifications.subscribe(
|
|
20
|
+
ActiveSupport::Notifications.subscribe('process.action_mailer') do |*args|
|
|
21
21
|
event = ActiveSupport::Notifications::Event.new(*args)
|
|
22
22
|
record_process(event)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
@installed = true
|
|
26
|
-
BrainzLab.debug_log(
|
|
26
|
+
BrainzLab.debug_log('ActionMailer instrumentation installed')
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def installed?
|
|
@@ -46,13 +46,13 @@ module BrainzLab
|
|
|
46
46
|
mail = payload[:mail]
|
|
47
47
|
to = sanitize_recipients(mail&.to)
|
|
48
48
|
subject = mail&.subject
|
|
49
|
-
delivery_method = payload[:perform_deliveries] ?
|
|
49
|
+
delivery_method = payload[:perform_deliveries] ? 'delivered' : 'skipped'
|
|
50
50
|
|
|
51
51
|
# Add breadcrumb for Reflex
|
|
52
52
|
if BrainzLab.configuration.reflex_enabled
|
|
53
53
|
BrainzLab::Reflex.add_breadcrumb(
|
|
54
54
|
"Mail #{delivery_method}: #{mailer}",
|
|
55
|
-
category:
|
|
55
|
+
category: 'mailer.deliver',
|
|
56
56
|
level: :info,
|
|
57
57
|
data: {
|
|
58
58
|
mailer: mailer,
|
|
@@ -67,13 +67,13 @@ module BrainzLab
|
|
|
67
67
|
# Record span for Pulse
|
|
68
68
|
record_span(
|
|
69
69
|
name: "Mail deliver #{mailer}",
|
|
70
|
-
kind:
|
|
70
|
+
kind: 'mailer',
|
|
71
71
|
started_at: event.time,
|
|
72
72
|
ended_at: event.end,
|
|
73
73
|
duration_ms: duration_ms,
|
|
74
74
|
data: {
|
|
75
75
|
mailer: mailer,
|
|
76
|
-
action:
|
|
76
|
+
action: 'deliver',
|
|
77
77
|
to: to,
|
|
78
78
|
subject: truncate_subject(subject),
|
|
79
79
|
message_id: message_id,
|
|
@@ -106,7 +106,7 @@ module BrainzLab
|
|
|
106
106
|
if BrainzLab.configuration.reflex_enabled
|
|
107
107
|
BrainzLab::Reflex.add_breadcrumb(
|
|
108
108
|
"Mail process: #{mailer}##{action}",
|
|
109
|
-
category:
|
|
109
|
+
category: 'mailer.process',
|
|
110
110
|
level: :info,
|
|
111
111
|
data: {
|
|
112
112
|
mailer: mailer,
|
|
@@ -119,7 +119,7 @@ module BrainzLab
|
|
|
119
119
|
# Record span for Pulse
|
|
120
120
|
record_span(
|
|
121
121
|
name: "Mail process #{mailer}##{action}",
|
|
122
|
-
kind:
|
|
122
|
+
kind: 'mailer',
|
|
123
123
|
started_at: event.time,
|
|
124
124
|
ended_at: event.end,
|
|
125
125
|
duration_ms: duration_ms,
|
|
@@ -152,27 +152,28 @@ module BrainzLab
|
|
|
152
152
|
|
|
153
153
|
case recipients
|
|
154
154
|
when Array
|
|
155
|
-
recipients.map { |r| mask_email(r) }.join(
|
|
155
|
+
recipients.map { |r| mask_email(r) }.join(', ')
|
|
156
156
|
else
|
|
157
157
|
mask_email(recipients.to_s)
|
|
158
158
|
end
|
|
159
159
|
end
|
|
160
160
|
|
|
161
161
|
def mask_email(email)
|
|
162
|
-
return email unless email.include?(
|
|
162
|
+
return email unless email.include?('@')
|
|
163
163
|
|
|
164
|
-
local, domain = email.split(
|
|
164
|
+
local, domain = email.split('@', 2)
|
|
165
165
|
if local.length > 2
|
|
166
166
|
"#{local[0..1]}***@#{domain}"
|
|
167
167
|
else
|
|
168
168
|
"***@#{domain}"
|
|
169
169
|
end
|
|
170
170
|
rescue StandardError
|
|
171
|
-
|
|
171
|
+
'[email]'
|
|
172
172
|
end
|
|
173
173
|
|
|
174
174
|
def truncate_subject(subject)
|
|
175
175
|
return nil unless subject
|
|
176
|
+
|
|
176
177
|
subject.to_s[0, 100]
|
|
177
178
|
end
|
|
178
179
|
end
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module BrainzLab
|
|
4
4
|
module Instrumentation
|
|
5
5
|
class ActiveRecord
|
|
6
|
-
SCHEMA_QUERIES = [
|
|
6
|
+
SCHEMA_QUERIES = %w[SCHEMA EXPLAIN].freeze
|
|
7
7
|
INTERNAL_TABLES = %w[pg_ information_schema sqlite_ mysql.].freeze
|
|
8
8
|
|
|
9
9
|
class << self
|
|
@@ -11,7 +11,7 @@ module BrainzLab
|
|
|
11
11
|
return unless defined?(::ActiveRecord)
|
|
12
12
|
return if @installed
|
|
13
13
|
|
|
14
|
-
ActiveSupport::Notifications.subscribe(
|
|
14
|
+
ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
|
|
15
15
|
event = ActiveSupport::Notifications::Event.new(*args)
|
|
16
16
|
next if skip_query?(event.payload)
|
|
17
17
|
|
|
@@ -19,7 +19,7 @@ module BrainzLab
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
@installed = true
|
|
22
|
-
BrainzLab.debug_log(
|
|
22
|
+
BrainzLab.debug_log('ActiveRecord breadcrumbs installed')
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def installed?
|
|
@@ -31,7 +31,7 @@ module BrainzLab
|
|
|
31
31
|
def record_breadcrumb(event)
|
|
32
32
|
payload = event.payload
|
|
33
33
|
sql = payload[:sql]
|
|
34
|
-
name = payload[:name] ||
|
|
34
|
+
name = payload[:name] || 'SQL'
|
|
35
35
|
duration = event.duration.round(2)
|
|
36
36
|
|
|
37
37
|
# Extract operation type from SQL
|
|
@@ -69,15 +69,15 @@ module BrainzLab
|
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
def extract_operation(sql)
|
|
72
|
-
return
|
|
72
|
+
return 'query' unless sql
|
|
73
73
|
|
|
74
74
|
case sql.to_s.strip.upcase
|
|
75
|
-
when /\ASELECT/i then
|
|
76
|
-
when /\AINSERT/i then
|
|
77
|
-
when /\AUPDATE/i then
|
|
78
|
-
when /\ADELETE/i then
|
|
79
|
-
when /\ABEGIN/i, /\ACOMMIT/i, /\AROLLBACK/i then
|
|
80
|
-
else
|
|
75
|
+
when /\ASELECT/i then 'select'
|
|
76
|
+
when /\AINSERT/i then 'insert'
|
|
77
|
+
when /\AUPDATE/i then 'update'
|
|
78
|
+
when /\ADELETE/i then 'delete'
|
|
79
|
+
when /\ABEGIN/i, /\ACOMMIT/i, /\AROLLBACK/i then 'transaction'
|
|
80
|
+
else 'query'
|
|
81
81
|
end
|
|
82
82
|
end
|
|
83
83
|
|
|
@@ -102,9 +102,7 @@ module BrainzLab
|
|
|
102
102
|
# Older versions used connection_class but that's removed in Rails 8.1
|
|
103
103
|
if connection.respond_to?(:pool)
|
|
104
104
|
pool = connection.pool
|
|
105
|
-
if pool.respond_to?(:db_config) && pool.db_config.respond_to?(:name)
|
|
106
|
-
pool.db_config.name
|
|
107
|
-
end
|
|
105
|
+
pool.db_config.name if pool.respond_to?(:db_config) && pool.db_config.respond_to?(:name)
|
|
108
106
|
elsif connection.respond_to?(:db_config) && connection.db_config.respond_to?(:name)
|
|
109
107
|
connection.db_config.name
|
|
110
108
|
end
|
|
@@ -115,7 +113,7 @@ module BrainzLab
|
|
|
115
113
|
def truncate_sql(sql)
|
|
116
114
|
return nil unless sql
|
|
117
115
|
|
|
118
|
-
truncated = sql.to_s.gsub(/\s+/,
|
|
116
|
+
truncated = sql.to_s.gsub(/\s+/, ' ').strip
|
|
119
117
|
if truncated.length > 500
|
|
120
118
|
"#{truncated[0, 497]}..."
|
|
121
119
|
else
|
|
@@ -9,7 +9,7 @@ module BrainzLab
|
|
|
9
9
|
|
|
10
10
|
install_plugin!
|
|
11
11
|
|
|
12
|
-
BrainzLab.debug_log(
|
|
12
|
+
BrainzLab.debug_log('[Instrumentation] AWS SDK instrumentation installed')
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
private
|
|
@@ -22,16 +22,16 @@ module BrainzLab
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
# Also hook into Seahorse for lower-level tracking
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
return unless defined?(::Seahorse::Client::Base)
|
|
26
|
+
|
|
27
|
+
install_seahorse_handler!
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def install_seahorse_handler!
|
|
31
31
|
handler_class = Class.new(::Seahorse::Client::Handler) do
|
|
32
32
|
def call(context)
|
|
33
33
|
started_at = Time.now
|
|
34
|
-
service = context.client.class.name.split(
|
|
34
|
+
service = context.client.class.name.split('::')[1] || 'AWS'
|
|
35
35
|
operation = context.operation_name.to_s
|
|
36
36
|
|
|
37
37
|
begin
|
|
@@ -46,12 +46,12 @@ module BrainzLab
|
|
|
46
46
|
|
|
47
47
|
private
|
|
48
48
|
|
|
49
|
-
def track_success(service, operation, started_at, context,
|
|
49
|
+
def track_success(service, operation, started_at, context, _response)
|
|
50
50
|
duration_ms = ((Time.now - started_at) * 1000).round(2)
|
|
51
51
|
|
|
52
52
|
BrainzLab::Reflex.add_breadcrumb(
|
|
53
53
|
"AWS #{service}.#{operation}",
|
|
54
|
-
category:
|
|
54
|
+
category: 'aws',
|
|
55
55
|
level: :info,
|
|
56
56
|
data: {
|
|
57
57
|
service: service,
|
|
@@ -61,19 +61,19 @@ module BrainzLab
|
|
|
61
61
|
}
|
|
62
62
|
)
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
return unless BrainzLab.configuration.flux_effectively_enabled?
|
|
65
|
+
|
|
66
|
+
tags = { service: service, operation: operation, region: context.config.region }
|
|
67
|
+
BrainzLab::Flux.distribution('aws.duration_ms', duration_ms, tags: tags)
|
|
68
|
+
BrainzLab::Flux.increment('aws.requests', tags: tags)
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
-
def track_error(service, operation, started_at,
|
|
72
|
-
|
|
71
|
+
def track_error(service, operation, started_at, _context, error)
|
|
72
|
+
((Time.now - started_at) * 1000).round(2)
|
|
73
73
|
|
|
74
74
|
BrainzLab::Reflex.add_breadcrumb(
|
|
75
75
|
"AWS #{service}.#{operation} failed: #{error.message}",
|
|
76
|
-
category:
|
|
76
|
+
category: 'aws',
|
|
77
77
|
level: :error,
|
|
78
78
|
data: {
|
|
79
79
|
service: service,
|
|
@@ -82,16 +82,16 @@ module BrainzLab
|
|
|
82
82
|
}
|
|
83
83
|
)
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
return unless BrainzLab.configuration.flux_effectively_enabled?
|
|
86
|
+
|
|
87
|
+
tags = { service: service, operation: operation, error_class: error.class.name }
|
|
88
|
+
BrainzLab::Flux.increment('aws.errors', tags: tags)
|
|
89
89
|
end
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
::Seahorse::Client::Base.add_plugin(
|
|
93
93
|
Class.new(::Seahorse::Client::Plugin) do
|
|
94
|
-
define_method(:add_handlers) do |handlers,
|
|
94
|
+
define_method(:add_handlers) do |handlers, _config|
|
|
95
95
|
handlers.add(handler_class, step: :validate, priority: 0)
|
|
96
96
|
end
|
|
97
97
|
end
|
|
@@ -101,7 +101,7 @@ module BrainzLab
|
|
|
101
101
|
|
|
102
102
|
# Aws SDK Plugin
|
|
103
103
|
class BrainzLabPlugin
|
|
104
|
-
def self.add_handlers(handlers,
|
|
104
|
+
def self.add_handlers(handlers, _config)
|
|
105
105
|
handlers.add(Handler, step: :validate, priority: 0)
|
|
106
106
|
end
|
|
107
107
|
|
|
@@ -128,16 +128,20 @@ module BrainzLab
|
|
|
128
128
|
private
|
|
129
129
|
|
|
130
130
|
def extract_service(context)
|
|
131
|
-
context.client.class.name.to_s.split(
|
|
131
|
+
context.client.class.name.to_s.split('::')[1] || 'AWS'
|
|
132
132
|
end
|
|
133
133
|
|
|
134
|
-
def track_request(service, operation, started_at, context,
|
|
134
|
+
def track_request(service, operation, started_at, context, _response)
|
|
135
135
|
duration_ms = ((Time.now - started_at) * 1000).round(2)
|
|
136
|
-
region =
|
|
136
|
+
region = begin
|
|
137
|
+
context.config.region
|
|
138
|
+
rescue StandardError
|
|
139
|
+
'unknown'
|
|
140
|
+
end
|
|
137
141
|
|
|
138
142
|
BrainzLab::Reflex.add_breadcrumb(
|
|
139
143
|
"AWS #{service}.#{operation}",
|
|
140
|
-
category:
|
|
144
|
+
category: 'aws',
|
|
141
145
|
level: :info,
|
|
142
146
|
data: {
|
|
143
147
|
service: service,
|
|
@@ -148,29 +152,29 @@ module BrainzLab
|
|
|
148
152
|
}
|
|
149
153
|
)
|
|
150
154
|
|
|
151
|
-
|
|
152
|
-
tags = { service: service, operation: operation, region: region }
|
|
153
|
-
BrainzLab::Flux.distribution("aws.duration_ms", duration_ms, tags: tags)
|
|
154
|
-
BrainzLab::Flux.increment("aws.requests", tags: tags)
|
|
155
|
+
return unless BrainzLab.configuration.flux_effectively_enabled?
|
|
155
156
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
tags = { service: service, operation: operation, region: region }
|
|
158
|
+
BrainzLab::Flux.distribution('aws.duration_ms', duration_ms, tags: tags)
|
|
159
|
+
BrainzLab::Flux.increment('aws.requests', tags: tags)
|
|
160
|
+
|
|
161
|
+
return unless context.retries.positive?
|
|
162
|
+
|
|
163
|
+
BrainzLab::Flux.increment('aws.retries', value: context.retries, tags: tags)
|
|
160
164
|
end
|
|
161
165
|
|
|
162
|
-
def track_error(service, operation,
|
|
166
|
+
def track_error(service, operation, _started_at, _context, error)
|
|
163
167
|
BrainzLab::Reflex.add_breadcrumb(
|
|
164
168
|
"AWS #{service}.#{operation} failed",
|
|
165
|
-
category:
|
|
169
|
+
category: 'aws',
|
|
166
170
|
level: :error,
|
|
167
171
|
data: { service: service, operation: operation, error: error.class.name }
|
|
168
172
|
)
|
|
169
173
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
+
return unless BrainzLab.configuration.flux_effectively_enabled?
|
|
175
|
+
|
|
176
|
+
tags = { service: service, operation: operation, error_class: error.class.name }
|
|
177
|
+
BrainzLab::Flux.increment('aws.errors', tags: tags)
|
|
174
178
|
end
|
|
175
179
|
end
|
|
176
180
|
end
|
|
@@ -11,7 +11,7 @@ module BrainzLab
|
|
|
11
11
|
|
|
12
12
|
install_client_instrumentation!
|
|
13
13
|
|
|
14
|
-
BrainzLab.debug_log(
|
|
14
|
+
BrainzLab.debug_log('[Instrumentation] Dalli/Memcached instrumentation installed')
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
private
|
|
@@ -54,42 +54,42 @@ module BrainzLab
|
|
|
54
54
|
# Add breadcrumb
|
|
55
55
|
BrainzLab::Reflex.add_breadcrumb(
|
|
56
56
|
"Memcached #{command.upcase}",
|
|
57
|
-
category:
|
|
57
|
+
category: 'cache',
|
|
58
58
|
level: :info,
|
|
59
59
|
data: { command: command, key: key, duration_ms: duration_ms }
|
|
60
60
|
)
|
|
61
61
|
|
|
62
62
|
# Track with Flux
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
63
|
+
return unless BrainzLab.configuration.flux_effectively_enabled?
|
|
64
|
+
|
|
65
|
+
tags = { command: command }
|
|
66
|
+
BrainzLab::Flux.distribution('memcached.duration_ms', duration_ms, tags: tags)
|
|
67
|
+
BrainzLab::Flux.increment('memcached.commands', tags: tags)
|
|
68
|
+
|
|
69
|
+
# Track cache hits/misses for get commands
|
|
70
|
+
return unless command == 'get'
|
|
71
|
+
|
|
72
|
+
if result.nil?
|
|
73
|
+
BrainzLab::Flux.increment('memcached.miss', tags: tags)
|
|
74
|
+
else
|
|
75
|
+
BrainzLab::Flux.increment('memcached.hit', tags: tags)
|
|
76
76
|
end
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
def self.track_error(command, args, started_at, error)
|
|
80
|
-
|
|
80
|
+
((Time.now - started_at) * 1000).round(2)
|
|
81
81
|
key = extract_key(args)
|
|
82
82
|
|
|
83
83
|
BrainzLab::Reflex.add_breadcrumb(
|
|
84
84
|
"Memcached #{command.upcase} failed: #{error.message}",
|
|
85
|
-
category:
|
|
85
|
+
category: 'cache',
|
|
86
86
|
level: :error,
|
|
87
87
|
data: { command: command, key: key, error: error.class.name }
|
|
88
88
|
)
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
return unless BrainzLab.configuration.flux_effectively_enabled?
|
|
91
|
+
|
|
92
|
+
BrainzLab::Flux.increment('memcached.errors', tags: { command: command })
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
def self.extract_key(args)
|