brainzlab 0.1.2 → 0.1.4
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 +112 -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_cable.rb +351 -0
- data/lib/brainzlab/instrumentation/action_controller.rb +649 -0
- data/lib/brainzlab/instrumentation/action_dispatch.rb +259 -0
- data/lib/brainzlab/instrumentation/action_mailbox.rb +197 -0
- data/lib/brainzlab/instrumentation/action_mailer.rb +14 -13
- data/lib/brainzlab/instrumentation/action_view.rb +380 -0
- data/lib/brainzlab/instrumentation/active_job.rb +569 -0
- data/lib/brainzlab/instrumentation/active_record.rb +467 -36
- data/lib/brainzlab/instrumentation/active_storage.rb +541 -0
- data/lib/brainzlab/instrumentation/active_support_cache.rb +700 -0
- 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/rails_deprecation.rb +139 -0
- data/lib/brainzlab/instrumentation/railties.rb +134 -0
- 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 +111 -21
- 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 +11 -1
|
@@ -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)
|
|
@@ -11,17 +11,13 @@ module BrainzLab
|
|
|
11
11
|
return if @installed
|
|
12
12
|
|
|
13
13
|
# Install lifecycle hooks
|
|
14
|
-
if defined?(::Delayed::Worker)
|
|
15
|
-
install_lifecycle_hooks!
|
|
16
|
-
end
|
|
14
|
+
install_lifecycle_hooks! if defined?(::Delayed::Worker)
|
|
17
15
|
|
|
18
16
|
# Install plugin if Delayed::Plugin is available
|
|
19
|
-
if defined?(::Delayed::Plugin)
|
|
20
|
-
::Delayed::Worker.plugins << Plugin
|
|
21
|
-
end
|
|
17
|
+
::Delayed::Worker.plugins << Plugin if defined?(::Delayed::Plugin)
|
|
22
18
|
|
|
23
19
|
@installed = true
|
|
24
|
-
BrainzLab.debug_log(
|
|
20
|
+
BrainzLab.debug_log('Delayed::Job instrumentation installed')
|
|
25
21
|
end
|
|
26
22
|
|
|
27
23
|
def installed?
|
|
@@ -35,15 +31,15 @@ module BrainzLab
|
|
|
35
31
|
private
|
|
36
32
|
|
|
37
33
|
def install_lifecycle_hooks!
|
|
38
|
-
::Delayed::Worker.lifecycle.around(:invoke_job) do |job, *
|
|
34
|
+
::Delayed::Worker.lifecycle.around(:invoke_job) do |job, *_args, &block|
|
|
39
35
|
around_invoke(job, &block)
|
|
40
36
|
end
|
|
41
37
|
|
|
42
|
-
::Delayed::Worker.lifecycle.after(:error) do |
|
|
38
|
+
::Delayed::Worker.lifecycle.after(:error) do |_worker, job|
|
|
43
39
|
record_error(job)
|
|
44
40
|
end
|
|
45
41
|
|
|
46
|
-
::Delayed::Worker.lifecycle.after(:failure) do |
|
|
42
|
+
::Delayed::Worker.lifecycle.after(:failure) do |_worker, job|
|
|
47
43
|
record_failure(job)
|
|
48
44
|
end
|
|
49
45
|
rescue StandardError => e
|
|
@@ -53,7 +49,7 @@ module BrainzLab
|
|
|
53
49
|
def around_invoke(job, &block)
|
|
54
50
|
started_at = Time.now.utc
|
|
55
51
|
job_name = extract_job_name(job)
|
|
56
|
-
queue = job.queue ||
|
|
52
|
+
queue = job.queue || 'default'
|
|
57
53
|
|
|
58
54
|
# Calculate queue wait time
|
|
59
55
|
queue_wait_ms = job.created_at ? ((started_at - job.created_at) * 1000).round(2) : nil
|
|
@@ -64,7 +60,7 @@ module BrainzLab
|
|
|
64
60
|
# Add breadcrumb
|
|
65
61
|
BrainzLab::Reflex.add_breadcrumb(
|
|
66
62
|
"DelayedJob #{job_name}",
|
|
67
|
-
category:
|
|
63
|
+
category: 'job.delayed_job',
|
|
68
64
|
level: :info,
|
|
69
65
|
data: { job_id: job.id, queue: queue, attempts: job.attempts }
|
|
70
66
|
)
|
|
@@ -133,7 +129,7 @@ module BrainzLab
|
|
|
133
129
|
payload = {
|
|
134
130
|
trace_id: SecureRandom.uuid,
|
|
135
131
|
name: job_name,
|
|
136
|
-
kind:
|
|
132
|
+
kind: 'job',
|
|
137
133
|
started_at: started_at.utc.iso8601(3),
|
|
138
134
|
ended_at: ended_at.utc.iso8601(3),
|
|
139
135
|
duration_ms: duration_ms,
|
|
@@ -162,7 +158,7 @@ module BrainzLab
|
|
|
162
158
|
|
|
163
159
|
BrainzLab::Reflex.add_breadcrumb(
|
|
164
160
|
"DelayedJob error: #{extract_job_name(job)}",
|
|
165
|
-
category:
|
|
161
|
+
category: 'job.delayed_job.error',
|
|
166
162
|
level: :error,
|
|
167
163
|
data: {
|
|
168
164
|
job_id: job.id,
|
|
@@ -177,7 +173,7 @@ module BrainzLab
|
|
|
177
173
|
def record_failure(job)
|
|
178
174
|
BrainzLab::Reflex.add_breadcrumb(
|
|
179
175
|
"DelayedJob failed permanently: #{extract_job_name(job)}",
|
|
180
|
-
category:
|
|
176
|
+
category: 'job.delayed_job.failure',
|
|
181
177
|
level: :error,
|
|
182
178
|
data: {
|
|
183
179
|
job_id: job.id,
|
|
@@ -200,7 +196,7 @@ module BrainzLab
|
|
|
200
196
|
payload.class.name
|
|
201
197
|
end
|
|
202
198
|
rescue StandardError
|
|
203
|
-
job.name ||
|
|
199
|
+
job.name || 'Unknown'
|
|
204
200
|
end
|
|
205
201
|
|
|
206
202
|
def format_timestamp(ts)
|
|
@@ -216,21 +212,23 @@ module BrainzLab
|
|
|
216
212
|
end
|
|
217
213
|
|
|
218
214
|
# Delayed::Job Plugin (alternative installation method)
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
215
|
+
if defined?(::Delayed::Plugin)
|
|
216
|
+
class Plugin < ::Delayed::Plugin
|
|
217
|
+
callbacks do |lifecycle|
|
|
218
|
+
lifecycle.around(:invoke_job) do |job, *_args, &block|
|
|
219
|
+
DelayedJobInstrumentation.send(:around_invoke, job, &block)
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
lifecycle.after(:error) do |_worker, job|
|
|
223
|
+
DelayedJobInstrumentation.send(:record_error, job)
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
lifecycle.after(:failure) do |_worker, job|
|
|
227
|
+
DelayedJobInstrumentation.send(:record_failure, job)
|
|
228
|
+
end
|
|
231
229
|
end
|
|
232
230
|
end
|
|
233
|
-
end
|
|
231
|
+
end
|
|
234
232
|
end
|
|
235
233
|
end
|
|
236
234
|
end
|
|
@@ -32,7 +32,7 @@ module BrainzLab
|
|
|
32
32
|
return unless installed_any
|
|
33
33
|
|
|
34
34
|
@installed = true
|
|
35
|
-
BrainzLab.debug_log(
|
|
35
|
+
BrainzLab.debug_log('Elasticsearch instrumentation installed')
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
def installed?
|
|
@@ -64,14 +64,12 @@ module BrainzLab
|
|
|
64
64
|
return super unless should_track?
|
|
65
65
|
|
|
66
66
|
started_at = Time.now.utc
|
|
67
|
-
error_info = nil
|
|
68
67
|
|
|
69
68
|
begin
|
|
70
69
|
response = super
|
|
71
70
|
record_request(method, path, params, started_at, response.status)
|
|
72
71
|
response
|
|
73
72
|
rescue StandardError => e
|
|
74
|
-
error_info = e
|
|
75
73
|
record_request(method, path, params, started_at, nil, e)
|
|
76
74
|
raise
|
|
77
75
|
end
|
|
@@ -83,7 +81,7 @@ module BrainzLab
|
|
|
83
81
|
BrainzLab.configuration.instrument_elasticsearch
|
|
84
82
|
end
|
|
85
83
|
|
|
86
|
-
def record_request(method, path,
|
|
84
|
+
def record_request(method, path, _params, started_at, status, error = nil)
|
|
87
85
|
duration_ms = ((Time.now.utc - started_at) * 1000).round(2)
|
|
88
86
|
operation = extract_operation(method, path)
|
|
89
87
|
index = extract_index(path)
|
|
@@ -93,7 +91,7 @@ module BrainzLab
|
|
|
93
91
|
if BrainzLab.configuration.reflex_enabled
|
|
94
92
|
BrainzLab::Reflex.add_breadcrumb(
|
|
95
93
|
"ES #{operation}",
|
|
96
|
-
category:
|
|
94
|
+
category: 'elasticsearch',
|
|
97
95
|
level: level,
|
|
98
96
|
data: {
|
|
99
97
|
method: method.to_s.upcase,
|
|
@@ -143,7 +141,7 @@ module BrainzLab
|
|
|
143
141
|
span = {
|
|
144
142
|
span_id: SecureRandom.uuid,
|
|
145
143
|
name: "ES #{operation}",
|
|
146
|
-
kind:
|
|
144
|
+
kind: 'elasticsearch',
|
|
147
145
|
started_at: started_at,
|
|
148
146
|
ended_at: Time.now.utc,
|
|
149
147
|
duration_ms: duration_ms,
|
|
@@ -168,25 +166,25 @@ module BrainzLab
|
|
|
168
166
|
method_str = method.to_s.upcase
|
|
169
167
|
|
|
170
168
|
case path
|
|
171
|
-
when %r{/_search} then
|
|
172
|
-
when %r{/_bulk} then
|
|
173
|
-
when %r{/_count} then
|
|
174
|
-
when %r{/_mget} then
|
|
175
|
-
when %r{/_msearch} then
|
|
176
|
-
when %r{/_update_by_query} then
|
|
177
|
-
when %r{/_delete_by_query} then
|
|
178
|
-
when %r{/_refresh} then
|
|
179
|
-
when %r{/_mapping} then
|
|
180
|
-
when %r{/_settings} then
|
|
181
|
-
when %r{/_alias} then
|
|
182
|
-
when %r{/_analyze} then
|
|
169
|
+
when %r{/_search} then 'search'
|
|
170
|
+
when %r{/_bulk} then 'bulk'
|
|
171
|
+
when %r{/_count} then 'count'
|
|
172
|
+
when %r{/_mget} then 'mget'
|
|
173
|
+
when %r{/_msearch} then 'msearch'
|
|
174
|
+
when %r{/_update_by_query} then 'update_by_query'
|
|
175
|
+
when %r{/_delete_by_query} then 'delete_by_query'
|
|
176
|
+
when %r{/_refresh} then 'refresh'
|
|
177
|
+
when %r{/_mapping} then 'mapping'
|
|
178
|
+
when %r{/_settings} then 'settings'
|
|
179
|
+
when %r{/_alias} then 'alias'
|
|
180
|
+
when %r{/_analyze} then 'analyze'
|
|
183
181
|
else
|
|
184
182
|
case method_str
|
|
185
|
-
when
|
|
186
|
-
when
|
|
187
|
-
when
|
|
188
|
-
when
|
|
189
|
-
when
|
|
183
|
+
when 'GET' then 'get'
|
|
184
|
+
when 'POST' then 'index'
|
|
185
|
+
when 'PUT' then 'update'
|
|
186
|
+
when 'DELETE' then 'delete'
|
|
187
|
+
when 'HEAD' then 'exists'
|
|
190
188
|
else method_str.downcase
|
|
191
189
|
end
|
|
192
190
|
end
|
|
@@ -195,13 +193,14 @@ module BrainzLab
|
|
|
195
193
|
def extract_index(path)
|
|
196
194
|
# Extract index name from path like /my-index/_search
|
|
197
195
|
match = path.match(%r{^/([^/_]+)})
|
|
198
|
-
match[1] if match && !match[1].start_with?(
|
|
196
|
+
match[1] if match && !match[1].start_with?('_')
|
|
199
197
|
rescue StandardError
|
|
200
198
|
nil
|
|
201
199
|
end
|
|
202
200
|
|
|
203
201
|
def truncate_path(path)
|
|
204
202
|
return nil unless path
|
|
203
|
+
|
|
205
204
|
path.to_s[0, 200]
|
|
206
205
|
end
|
|
207
206
|
end
|
|
@@ -9,7 +9,7 @@ module BrainzLab
|
|
|
9
9
|
|
|
10
10
|
install_middleware!
|
|
11
11
|
|
|
12
|
-
BrainzLab.debug_log(
|
|
12
|
+
BrainzLab.debug_log('[Instrumentation] Excon instrumentation installed')
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
private
|
|
@@ -19,15 +19,15 @@ module BrainzLab
|
|
|
19
19
|
::Excon.defaults[:instrumentor] = BrainzLabInstrumentor
|
|
20
20
|
|
|
21
21
|
# Also set up middleware
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
return unless ::Excon.defaults[:middlewares]
|
|
23
|
+
|
|
24
|
+
::Excon.defaults[:middlewares] = [Middleware] + ::Excon.defaults[:middlewares]
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
# Excon Instrumentor for ActiveSupport-style notifications
|
|
29
29
|
module BrainzLabInstrumentor
|
|
30
|
-
def self.instrument(name, params = {}
|
|
30
|
+
def self.instrument(name, params = {})
|
|
31
31
|
started_at = Time.now
|
|
32
32
|
|
|
33
33
|
begin
|
|
@@ -40,19 +40,19 @@ module BrainzLab
|
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
def self.track_request(
|
|
43
|
+
def self.track_request(_name, params, started_at, error)
|
|
44
44
|
return if skip_tracking?(params)
|
|
45
45
|
|
|
46
46
|
duration_ms = ((Time.now - started_at) * 1000).round(2)
|
|
47
|
-
host = params[:host] ||
|
|
48
|
-
method = (params[:method] ||
|
|
49
|
-
path = params[:path] ||
|
|
47
|
+
host = params[:host] || 'unknown'
|
|
48
|
+
method = (params[:method] || 'GET').to_s.upcase
|
|
49
|
+
path = params[:path] || '/'
|
|
50
50
|
status = params[:status]
|
|
51
51
|
|
|
52
52
|
# Add breadcrumb
|
|
53
53
|
BrainzLab::Reflex.add_breadcrumb(
|
|
54
54
|
"HTTP #{method} #{host}#{path}",
|
|
55
|
-
category:
|
|
55
|
+
category: 'http',
|
|
56
56
|
level: error ? :error : :info,
|
|
57
57
|
data: {
|
|
58
58
|
method: method,
|
|
@@ -65,21 +65,21 @@ module BrainzLab
|
|
|
65
65
|
|
|
66
66
|
# Track with Pulse
|
|
67
67
|
if BrainzLab.configuration.pulse_effectively_enabled?
|
|
68
|
-
BrainzLab::Pulse.span(
|
|
68
|
+
BrainzLab::Pulse.span('http.excon', kind: 'http') do
|
|
69
69
|
# Already completed, just recording
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
# Track with Flux
|
|
74
|
-
|
|
75
|
-
tags = { host: host, method: method, status: status.to_s }
|
|
76
|
-
BrainzLab::Flux.distribution("http.excon.duration_ms", duration_ms, tags: tags)
|
|
77
|
-
BrainzLab::Flux.increment("http.excon.requests", tags: tags)
|
|
74
|
+
return unless BrainzLab.configuration.flux_effectively_enabled?
|
|
78
75
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
tags = { host: host, method: method, status: status.to_s }
|
|
77
|
+
BrainzLab::Flux.distribution('http.excon.duration_ms', duration_ms, tags: tags)
|
|
78
|
+
BrainzLab::Flux.increment('http.excon.requests', tags: tags)
|
|
79
|
+
|
|
80
|
+
return unless error || (status && status >= 400)
|
|
81
|
+
|
|
82
|
+
BrainzLab::Flux.increment('http.excon.errors', tags: tags)
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
def self.skip_tracking?(params)
|
|
@@ -122,22 +122,22 @@ module BrainzLab
|
|
|
122
122
|
return if skip_host?(host)
|
|
123
123
|
|
|
124
124
|
duration_ms = ((Time.now - started_at) * 1000).round(2)
|
|
125
|
-
method = (datum[:method] ||
|
|
126
|
-
path = datum[:path] ||
|
|
125
|
+
method = (datum[:method] || 'GET').to_s.upcase
|
|
126
|
+
path = datum[:path] || '/'
|
|
127
127
|
status = datum[:response]&.dig(:status)
|
|
128
128
|
|
|
129
129
|
BrainzLab::Reflex.add_breadcrumb(
|
|
130
130
|
"HTTP #{method} #{host}#{path} -> #{status || 'error'}",
|
|
131
|
-
category:
|
|
131
|
+
category: 'http',
|
|
132
132
|
level: error ? :error : :info,
|
|
133
133
|
data: { method: method, host: host, status: status, duration_ms: duration_ms }
|
|
134
134
|
)
|
|
135
135
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
return unless BrainzLab.configuration.flux_effectively_enabled?
|
|
137
|
+
|
|
138
|
+
tags = { host: host, method: method }
|
|
139
|
+
tags[:status] = status.to_s if status
|
|
140
|
+
BrainzLab::Flux.distribution('http.excon.duration_ms', duration_ms, tags: tags)
|
|
141
141
|
end
|
|
142
142
|
|
|
143
143
|
def skip_host?(host)
|
|
@@ -14,7 +14,7 @@ module BrainzLab
|
|
|
14
14
|
::Faraday::Middleware.register_middleware(brainzlab: Middleware)
|
|
15
15
|
|
|
16
16
|
@installed = true
|
|
17
|
-
BrainzLab.debug_log(
|
|
17
|
+
BrainzLab.debug_log('Faraday instrumentation installed')
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def installed?
|
|
@@ -46,7 +46,6 @@ module BrainzLab
|
|
|
46
46
|
inject_trace_context(env)
|
|
47
47
|
|
|
48
48
|
started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
49
|
-
error_info = nil
|
|
50
49
|
|
|
51
50
|
begin
|
|
52
51
|
response = @app.call(env)
|
|
@@ -98,7 +97,7 @@ module BrainzLab
|
|
|
98
97
|
if BrainzLab.configuration.reflex_enabled
|
|
99
98
|
BrainzLab::Reflex.add_breadcrumb(
|
|
100
99
|
"#{method} #{url}",
|
|
101
|
-
category:
|
|
100
|
+
category: 'http.faraday',
|
|
102
101
|
level: level,
|
|
103
102
|
data: {
|
|
104
103
|
method: method,
|
|
@@ -138,7 +137,7 @@ module BrainzLab
|
|
|
138
137
|
span = {
|
|
139
138
|
span_id: SecureRandom.uuid,
|
|
140
139
|
name: "HTTP #{method} #{host}",
|
|
141
|
-
kind:
|
|
140
|
+
kind: 'http',
|
|
142
141
|
started_at: Time.now.utc - (duration_ms / 1000.0),
|
|
143
142
|
ended_at: Time.now.utc,
|
|
144
143
|
duration_ms: duration_ms,
|