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
|
@@ -10,7 +10,7 @@ module BrainzLab
|
|
|
10
10
|
install_job_instrumentation!
|
|
11
11
|
install_worker_instrumentation!
|
|
12
12
|
|
|
13
|
-
BrainzLab.debug_log(
|
|
13
|
+
BrainzLab.debug_log('[Instrumentation] SolidQueue instrumentation installed')
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
private
|
|
@@ -31,10 +31,10 @@ module BrainzLab
|
|
|
31
31
|
|
|
32
32
|
def install_worker_instrumentation!
|
|
33
33
|
# Subscribe to ActiveSupport notifications for SolidQueue
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
return unless defined?(::ActiveSupport::Notifications)
|
|
35
|
+
|
|
36
|
+
::ActiveSupport::Notifications.subscribe(/solid_queue/) do |name, start, finish, _id, payload|
|
|
37
|
+
handle_notification(name, start, finish, payload)
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
|
|
@@ -42,26 +42,26 @@ module BrainzLab
|
|
|
42
42
|
duration_ms = ((finish - start) * 1000).round(2)
|
|
43
43
|
|
|
44
44
|
case name
|
|
45
|
-
when
|
|
45
|
+
when 'perform.solid_queue'
|
|
46
46
|
track_job_perform(payload, duration_ms)
|
|
47
|
-
when
|
|
47
|
+
when 'enqueue.solid_queue'
|
|
48
48
|
track_job_enqueue(payload)
|
|
49
|
-
when
|
|
49
|
+
when 'discard.solid_queue'
|
|
50
50
|
track_job_discard(payload)
|
|
51
|
-
when
|
|
51
|
+
when 'retry.solid_queue'
|
|
52
52
|
track_job_retry(payload)
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
def track_job_perform(payload, duration_ms)
|
|
57
57
|
job_class = payload[:job]&.class&.name || payload[:job_class]
|
|
58
|
-
queue = payload[:queue] ||
|
|
58
|
+
queue = payload[:queue] || 'default'
|
|
59
59
|
|
|
60
60
|
# Track with Pulse
|
|
61
61
|
if BrainzLab.configuration.pulse_effectively_enabled?
|
|
62
62
|
BrainzLab::Pulse.record_trace(
|
|
63
63
|
"job.#{job_class}",
|
|
64
|
-
kind:
|
|
64
|
+
kind: 'job',
|
|
65
65
|
started_at: Time.now - (duration_ms / 1000.0),
|
|
66
66
|
ended_at: Time.now,
|
|
67
67
|
job_class: job_class,
|
|
@@ -77,18 +77,16 @@ module BrainzLab
|
|
|
77
77
|
# Track with Flux
|
|
78
78
|
if BrainzLab.configuration.flux_effectively_enabled?
|
|
79
79
|
tags = { job_class: job_class, queue: queue }
|
|
80
|
-
BrainzLab::Flux.distribution(
|
|
81
|
-
BrainzLab::Flux.increment(
|
|
80
|
+
BrainzLab::Flux.distribution('solid_queue.job.duration_ms', duration_ms, tags: tags)
|
|
81
|
+
BrainzLab::Flux.increment('solid_queue.job.processed', tags: tags)
|
|
82
82
|
|
|
83
|
-
if payload[:error]
|
|
84
|
-
BrainzLab::Flux.increment("solid_queue.job.failed", tags: tags)
|
|
85
|
-
end
|
|
83
|
+
BrainzLab::Flux.increment('solid_queue.job.failed', tags: tags) if payload[:error]
|
|
86
84
|
end
|
|
87
85
|
|
|
88
86
|
# Add breadcrumb for Reflex
|
|
89
87
|
BrainzLab::Reflex.add_breadcrumb(
|
|
90
88
|
"Job #{job_class} completed in #{duration_ms}ms",
|
|
91
|
-
category:
|
|
89
|
+
category: 'job',
|
|
92
90
|
level: payload[:error] ? :error : :info,
|
|
93
91
|
data: { queue: queue, job_id: payload[:job_id], duration_ms: duration_ms }
|
|
94
92
|
)
|
|
@@ -96,33 +94,33 @@ module BrainzLab
|
|
|
96
94
|
|
|
97
95
|
def track_job_enqueue(payload)
|
|
98
96
|
job_class = payload[:job]&.class&.name || payload[:job_class]
|
|
99
|
-
queue = payload[:queue] ||
|
|
97
|
+
queue = payload[:queue] || 'default'
|
|
100
98
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
return unless BrainzLab.configuration.flux_effectively_enabled?
|
|
100
|
+
|
|
101
|
+
BrainzLab::Flux.increment('solid_queue.job.enqueued', tags: { job_class: job_class, queue: queue })
|
|
104
102
|
end
|
|
105
103
|
|
|
106
104
|
def track_job_discard(payload)
|
|
107
105
|
job_class = payload[:job]&.class&.name || payload[:job_class]
|
|
108
106
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
107
|
+
return unless BrainzLab.configuration.flux_effectively_enabled?
|
|
108
|
+
|
|
109
|
+
BrainzLab::Flux.increment('solid_queue.job.discarded', tags: { job_class: job_class })
|
|
112
110
|
end
|
|
113
111
|
|
|
114
112
|
def track_job_retry(payload)
|
|
115
113
|
job_class = payload[:job]&.class&.name || payload[:job_class]
|
|
116
114
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
115
|
+
return unless BrainzLab.configuration.flux_effectively_enabled?
|
|
116
|
+
|
|
117
|
+
BrainzLab::Flux.increment('solid_queue.job.retried', tags: { job_class: job_class })
|
|
120
118
|
end
|
|
121
119
|
end
|
|
122
120
|
|
|
123
121
|
def self.around_perform(job)
|
|
124
122
|
job_class = job.class.name
|
|
125
|
-
queue = job.queue_name ||
|
|
123
|
+
queue = job.queue_name || 'default'
|
|
126
124
|
started_at = Time.now
|
|
127
125
|
|
|
128
126
|
# Set context for the job
|
|
@@ -138,13 +136,12 @@ module BrainzLab
|
|
|
138
136
|
# Capture error with Reflex
|
|
139
137
|
if BrainzLab.configuration.reflex_effectively_enabled?
|
|
140
138
|
BrainzLab::Reflex.capture(e,
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
)
|
|
139
|
+
tags: { job_class: job_class, queue: queue },
|
|
140
|
+
extra: {
|
|
141
|
+
job_id: job.job_id,
|
|
142
|
+
arguments: safe_arguments(job),
|
|
143
|
+
executions: job.executions
|
|
144
|
+
})
|
|
148
145
|
end
|
|
149
146
|
raise
|
|
150
147
|
ensure
|
|
@@ -154,7 +151,7 @@ module BrainzLab
|
|
|
154
151
|
if BrainzLab.configuration.pulse_effectively_enabled?
|
|
155
152
|
BrainzLab::Pulse.record_trace(
|
|
156
153
|
"job.#{job_class}",
|
|
157
|
-
kind:
|
|
154
|
+
kind: 'job',
|
|
158
155
|
started_at: started_at,
|
|
159
156
|
ended_at: Time.now,
|
|
160
157
|
job_class: job_class,
|
|
@@ -167,7 +164,7 @@ module BrainzLab
|
|
|
167
164
|
# Record metrics
|
|
168
165
|
if BrainzLab.configuration.flux_effectively_enabled?
|
|
169
166
|
tags = { job_class: job_class, queue: queue }
|
|
170
|
-
BrainzLab::Flux.distribution(
|
|
167
|
+
BrainzLab::Flux.distribution('solid_queue.job.duration_ms', duration_ms, tags: tags)
|
|
171
168
|
end
|
|
172
169
|
|
|
173
170
|
# Clear context
|
|
@@ -180,9 +177,8 @@ module BrainzLab
|
|
|
180
177
|
rescue StandardError => e
|
|
181
178
|
if BrainzLab.configuration.reflex_effectively_enabled?
|
|
182
179
|
BrainzLab::Reflex.capture(e,
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
)
|
|
180
|
+
tags: { job_class: job.class.name, queue: job.queue_name },
|
|
181
|
+
extra: { job_id: job.job_id, arguments: safe_arguments(job) })
|
|
186
182
|
end
|
|
187
183
|
raise
|
|
188
184
|
end
|
|
@@ -191,7 +187,7 @@ module BrainzLab
|
|
|
191
187
|
args = job.arguments
|
|
192
188
|
BrainzLab::Reflex.send(:filter_params, args) if args
|
|
193
189
|
rescue StandardError
|
|
194
|
-
|
|
190
|
+
'[Unable to serialize]'
|
|
195
191
|
end
|
|
196
192
|
end
|
|
197
193
|
end
|
|
@@ -9,7 +9,7 @@ module BrainzLab
|
|
|
9
9
|
|
|
10
10
|
install_instrumentation!
|
|
11
11
|
|
|
12
|
-
BrainzLab.debug_log(
|
|
12
|
+
BrainzLab.debug_log('[Instrumentation] Stripe instrumentation installed')
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
private
|
|
@@ -63,8 +63,8 @@ module BrainzLab
|
|
|
63
63
|
|
|
64
64
|
def extract_resource(path)
|
|
65
65
|
# /v1/customers/cus_xxx -> customers
|
|
66
|
-
parts = path.to_s.split(
|
|
67
|
-
parts[1] ||
|
|
66
|
+
parts = path.to_s.split('/').reject(&:empty?)
|
|
67
|
+
parts[1] || 'unknown'
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
70
|
end
|
|
@@ -73,11 +73,11 @@ module BrainzLab
|
|
|
73
73
|
def track_event(event)
|
|
74
74
|
duration_ms = (event[:duration] * 1000).round(2) if event[:duration]
|
|
75
75
|
method = event[:method].to_s.upcase
|
|
76
|
-
resource = event[:path].to_s.split(
|
|
76
|
+
resource = event[:path].to_s.split('/')[2] || 'unknown'
|
|
77
77
|
|
|
78
78
|
BrainzLab::Reflex.add_breadcrumb(
|
|
79
79
|
"Stripe #{method} #{resource}",
|
|
80
|
-
category:
|
|
80
|
+
category: 'payment',
|
|
81
81
|
level: event[:error] ? :error : :info,
|
|
82
82
|
data: {
|
|
83
83
|
method: method,
|
|
@@ -88,24 +88,24 @@ module BrainzLab
|
|
|
88
88
|
}
|
|
89
89
|
)
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
tags = { method: method, resource: resource }
|
|
93
|
-
BrainzLab::Flux.distribution("stripe.duration_ms", duration_ms, tags: tags) if duration_ms
|
|
94
|
-
BrainzLab::Flux.increment("stripe.requests", tags: tags)
|
|
91
|
+
return unless BrainzLab.configuration.flux_effectively_enabled?
|
|
95
92
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
tags = { method: method, resource: resource }
|
|
94
|
+
BrainzLab::Flux.distribution('stripe.duration_ms', duration_ms, tags: tags) if duration_ms
|
|
95
|
+
BrainzLab::Flux.increment('stripe.requests', tags: tags)
|
|
96
|
+
|
|
97
|
+
return unless event[:error]
|
|
98
|
+
|
|
99
|
+
BrainzLab::Flux.increment('stripe.errors', tags: tags.merge(error_type: event[:error_type]))
|
|
100
100
|
end
|
|
101
101
|
end
|
|
102
102
|
|
|
103
|
-
def self.track_success(method, resource, path, started_at,
|
|
103
|
+
def self.track_success(method, resource, path, started_at, _response)
|
|
104
104
|
duration_ms = ((Time.now - started_at) * 1000).round(2)
|
|
105
105
|
|
|
106
106
|
BrainzLab::Reflex.add_breadcrumb(
|
|
107
107
|
"Stripe #{method.to_s.upcase} #{resource}",
|
|
108
|
-
category:
|
|
108
|
+
category: 'payment',
|
|
109
109
|
level: :info,
|
|
110
110
|
data: {
|
|
111
111
|
method: method.to_s.upcase,
|
|
@@ -115,28 +115,28 @@ module BrainzLab
|
|
|
115
115
|
}
|
|
116
116
|
)
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
return unless BrainzLab.configuration.flux_effectively_enabled?
|
|
119
|
+
|
|
120
|
+
tags = { method: method.to_s.upcase, resource: resource }
|
|
121
|
+
BrainzLab::Flux.distribution('stripe.duration_ms', duration_ms, tags: tags)
|
|
122
|
+
BrainzLab::Flux.increment('stripe.requests', tags: tags)
|
|
123
123
|
end
|
|
124
124
|
|
|
125
|
-
def self.track_error(method, resource,
|
|
126
|
-
|
|
125
|
+
def self.track_error(method, resource, _path, started_at, error)
|
|
126
|
+
((Time.now - started_at) * 1000).round(2)
|
|
127
127
|
error_type = case error
|
|
128
|
-
when Stripe::CardError then
|
|
129
|
-
when Stripe::RateLimitError then
|
|
130
|
-
when Stripe::InvalidRequestError then
|
|
131
|
-
when Stripe::AuthenticationError then
|
|
132
|
-
when Stripe::APIConnectionError then
|
|
133
|
-
when Stripe::StripeError then
|
|
134
|
-
else
|
|
128
|
+
when Stripe::CardError then 'card_error'
|
|
129
|
+
when Stripe::RateLimitError then 'rate_limit'
|
|
130
|
+
when Stripe::InvalidRequestError then 'invalid_request'
|
|
131
|
+
when Stripe::AuthenticationError then 'authentication'
|
|
132
|
+
when Stripe::APIConnectionError then 'connection'
|
|
133
|
+
when Stripe::StripeError then 'stripe_error'
|
|
134
|
+
else 'unknown'
|
|
135
135
|
end
|
|
136
136
|
|
|
137
137
|
BrainzLab::Reflex.add_breadcrumb(
|
|
138
138
|
"Stripe #{method.to_s.upcase} #{resource} failed: #{error.message}",
|
|
139
|
-
category:
|
|
139
|
+
category: 'payment',
|
|
140
140
|
level: :error,
|
|
141
141
|
data: {
|
|
142
142
|
method: method.to_s.upcase,
|
|
@@ -148,16 +148,15 @@ module BrainzLab
|
|
|
148
148
|
|
|
149
149
|
if BrainzLab.configuration.flux_effectively_enabled?
|
|
150
150
|
tags = { method: method.to_s.upcase, resource: resource, error_type: error_type }
|
|
151
|
-
BrainzLab::Flux.increment(
|
|
151
|
+
BrainzLab::Flux.increment('stripe.errors', tags: tags)
|
|
152
152
|
end
|
|
153
153
|
|
|
154
154
|
# Capture with Reflex (but filter sensitive data)
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
end
|
|
155
|
+
return unless BrainzLab.configuration.reflex_effectively_enabled?
|
|
156
|
+
|
|
157
|
+
BrainzLab::Reflex.capture(error,
|
|
158
|
+
tags: { source: 'stripe', resource: resource },
|
|
159
|
+
extra: { error_type: error_type })
|
|
161
160
|
end
|
|
162
161
|
end
|
|
163
162
|
end
|
|
@@ -9,7 +9,7 @@ module BrainzLab
|
|
|
9
9
|
|
|
10
10
|
install_callbacks!
|
|
11
11
|
|
|
12
|
-
BrainzLab.debug_log(
|
|
12
|
+
BrainzLab.debug_log('[Instrumentation] Typhoeus instrumentation installed')
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
private
|
|
@@ -24,21 +24,25 @@ module BrainzLab
|
|
|
24
24
|
request = response.request
|
|
25
25
|
return unless request
|
|
26
26
|
|
|
27
|
-
uri =
|
|
27
|
+
uri = begin
|
|
28
|
+
URI.parse(request.base_url)
|
|
29
|
+
rescue StandardError
|
|
30
|
+
nil
|
|
31
|
+
end
|
|
28
32
|
return unless uri
|
|
29
33
|
|
|
30
34
|
host = uri.host
|
|
31
35
|
return if skip_host?(host)
|
|
32
36
|
|
|
33
37
|
method = (request.options[:method] || :get).to_s.upcase
|
|
34
|
-
path = uri.path.empty? ?
|
|
38
|
+
path = uri.path.empty? ? '/' : uri.path
|
|
35
39
|
status = response.response_code
|
|
36
40
|
duration_ms = (response.total_time * 1000).round(2)
|
|
37
41
|
|
|
38
42
|
# Add breadcrumb
|
|
39
43
|
BrainzLab::Reflex.add_breadcrumb(
|
|
40
44
|
"HTTP #{method} #{host}#{path} -> #{status}",
|
|
41
|
-
category:
|
|
45
|
+
category: 'http',
|
|
42
46
|
level: response.success? ? :info : :error,
|
|
43
47
|
data: {
|
|
44
48
|
method: method,
|
|
@@ -50,19 +54,17 @@ module BrainzLab
|
|
|
50
54
|
)
|
|
51
55
|
|
|
52
56
|
# Track with Flux
|
|
53
|
-
|
|
54
|
-
tags = { host: host, method: method, status: status.to_s }
|
|
55
|
-
BrainzLab::Flux.distribution("http.typhoeus.duration_ms", duration_ms, tags: tags)
|
|
56
|
-
BrainzLab::Flux.increment("http.typhoeus.requests", tags: tags)
|
|
57
|
+
return unless BrainzLab.configuration.flux_effectively_enabled?
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
tags = { host: host, method: method, status: status.to_s }
|
|
60
|
+
BrainzLab::Flux.distribution('http.typhoeus.duration_ms', duration_ms, tags: tags)
|
|
61
|
+
BrainzLab::Flux.increment('http.typhoeus.requests', tags: tags)
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
BrainzLab::Flux.increment('http.typhoeus.errors', tags: tags) unless response.success?
|
|
64
|
+
|
|
65
|
+
return unless response.timed_out?
|
|
66
|
+
|
|
67
|
+
BrainzLab::Flux.increment('http.typhoeus.timeouts', tags: { host: host })
|
|
66
68
|
end
|
|
67
69
|
|
|
68
70
|
def skip_host?(host)
|
|
@@ -90,8 +92,8 @@ module BrainzLab
|
|
|
90
92
|
duration_ms = ((Time.now - started_at) * 1000).round(2)
|
|
91
93
|
|
|
92
94
|
if BrainzLab.configuration.flux_effectively_enabled?
|
|
93
|
-
BrainzLab::Flux.distribution(
|
|
94
|
-
BrainzLab::Flux.distribution(
|
|
95
|
+
BrainzLab::Flux.distribution('http.typhoeus.hydra.duration_ms', duration_ms)
|
|
96
|
+
BrainzLab::Flux.distribution('http.typhoeus.hydra.request_count', request_count)
|
|
95
97
|
end
|
|
96
98
|
|
|
97
99
|
result
|
|
@@ -31,9 +31,17 @@ module BrainzLab
|
|
|
31
31
|
# Elasticsearch instrumentation
|
|
32
32
|
install_elasticsearch! if config.instrument_elasticsearch
|
|
33
33
|
|
|
34
|
-
#
|
|
34
|
+
# Rails MVC instrumentation
|
|
35
|
+
install_action_controller! if config.instrument_action_controller
|
|
36
|
+
install_action_view! if config.instrument_action_view
|
|
35
37
|
install_action_mailer! if config.instrument_action_mailer
|
|
36
38
|
|
|
39
|
+
# ActiveJob instrumentation (covers all job backends)
|
|
40
|
+
install_active_job! if config.instrument_active_job
|
|
41
|
+
|
|
42
|
+
# ActiveSupport::Cache instrumentation
|
|
43
|
+
install_active_support_cache! if config.instrument_active_support_cache
|
|
44
|
+
|
|
37
45
|
# Delayed::Job instrumentation
|
|
38
46
|
install_delayed_job! if config.instrument_delayed_job
|
|
39
47
|
|
|
@@ -55,144 +63,226 @@ module BrainzLab
|
|
|
55
63
|
# Cloud & Payment
|
|
56
64
|
install_aws! if config.instrument_aws
|
|
57
65
|
install_stripe! if config.instrument_stripe
|
|
66
|
+
|
|
67
|
+
# File storage
|
|
68
|
+
install_active_storage! if config.instrument_active_storage
|
|
69
|
+
|
|
70
|
+
# WebSocket
|
|
71
|
+
install_action_cable! if config.instrument_action_cable
|
|
72
|
+
|
|
73
|
+
# Rails framework events
|
|
74
|
+
install_action_dispatch! if config.instrument_action_dispatch
|
|
75
|
+
install_rails_deprecation! if config.instrument_rails_deprecation
|
|
76
|
+
install_action_mailbox! if config.instrument_action_mailbox
|
|
77
|
+
install_railties! if config.instrument_railties
|
|
58
78
|
end
|
|
59
79
|
|
|
60
80
|
def install_net_http!
|
|
61
|
-
require_relative
|
|
81
|
+
require_relative 'instrumentation/net_http'
|
|
62
82
|
NetHttp.install!
|
|
63
83
|
end
|
|
64
84
|
|
|
65
85
|
def install_faraday!
|
|
66
86
|
return unless defined?(::Faraday)
|
|
67
87
|
|
|
68
|
-
require_relative
|
|
88
|
+
require_relative 'instrumentation/faraday'
|
|
69
89
|
FaradayMiddleware.install!
|
|
70
90
|
end
|
|
71
91
|
|
|
72
92
|
def install_httparty!
|
|
73
93
|
return unless defined?(::HTTParty)
|
|
74
94
|
|
|
75
|
-
require_relative
|
|
95
|
+
require_relative 'instrumentation/httparty'
|
|
76
96
|
HTTPartyInstrumentation.install!
|
|
77
97
|
end
|
|
78
98
|
|
|
79
99
|
def install_active_record!
|
|
80
|
-
require_relative
|
|
100
|
+
require_relative 'instrumentation/active_record'
|
|
81
101
|
ActiveRecord.install!
|
|
82
102
|
end
|
|
83
103
|
|
|
84
104
|
def install_redis!
|
|
85
105
|
return unless defined?(::Redis)
|
|
86
106
|
|
|
87
|
-
require_relative
|
|
107
|
+
require_relative 'instrumentation/redis'
|
|
88
108
|
RedisInstrumentation.install!
|
|
89
109
|
end
|
|
90
110
|
|
|
91
111
|
def install_sidekiq!
|
|
92
112
|
return unless defined?(::Sidekiq)
|
|
93
113
|
|
|
94
|
-
require_relative
|
|
114
|
+
require_relative 'instrumentation/sidekiq'
|
|
95
115
|
SidekiqInstrumentation.install!
|
|
96
116
|
end
|
|
97
117
|
|
|
98
118
|
def install_graphql!
|
|
99
119
|
return unless defined?(::GraphQL)
|
|
100
120
|
|
|
101
|
-
require_relative
|
|
121
|
+
require_relative 'instrumentation/graphql'
|
|
102
122
|
GraphQLInstrumentation.install!
|
|
103
123
|
end
|
|
104
124
|
|
|
105
125
|
def install_mongodb!
|
|
106
126
|
return unless defined?(::Mongo) || defined?(::Mongoid)
|
|
107
127
|
|
|
108
|
-
require_relative
|
|
128
|
+
require_relative 'instrumentation/mongodb'
|
|
109
129
|
MongoDBInstrumentation.install!
|
|
110
130
|
end
|
|
111
131
|
|
|
112
132
|
def install_elasticsearch!
|
|
113
133
|
return unless defined?(::Elasticsearch) || defined?(::OpenSearch)
|
|
114
134
|
|
|
115
|
-
require_relative
|
|
135
|
+
require_relative 'instrumentation/elasticsearch'
|
|
116
136
|
ElasticsearchInstrumentation.install!
|
|
117
137
|
end
|
|
118
138
|
|
|
139
|
+
def install_action_controller!
|
|
140
|
+
return unless defined?(::ActionController)
|
|
141
|
+
|
|
142
|
+
require_relative 'instrumentation/action_controller'
|
|
143
|
+
ActionController.install!
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def install_action_view!
|
|
147
|
+
return unless defined?(::ActionView)
|
|
148
|
+
|
|
149
|
+
require_relative 'instrumentation/action_view'
|
|
150
|
+
ActionView.install!
|
|
151
|
+
end
|
|
152
|
+
|
|
119
153
|
def install_action_mailer!
|
|
120
154
|
return unless defined?(::ActionMailer)
|
|
121
155
|
|
|
122
|
-
require_relative
|
|
156
|
+
require_relative 'instrumentation/action_mailer'
|
|
123
157
|
ActionMailerInstrumentation.install!
|
|
124
158
|
end
|
|
125
159
|
|
|
160
|
+
def install_active_job!
|
|
161
|
+
return unless defined?(::ActiveJob)
|
|
162
|
+
|
|
163
|
+
require_relative 'instrumentation/active_job'
|
|
164
|
+
ActiveJob.install!
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def install_active_support_cache!
|
|
168
|
+
return unless defined?(::ActiveSupport::Cache)
|
|
169
|
+
|
|
170
|
+
require_relative 'instrumentation/active_support_cache'
|
|
171
|
+
ActiveSupportCache.install!
|
|
172
|
+
end
|
|
173
|
+
|
|
126
174
|
def install_delayed_job!
|
|
127
175
|
return unless defined?(::Delayed::Job) || defined?(::Delayed::Backend)
|
|
128
176
|
|
|
129
|
-
require_relative
|
|
177
|
+
require_relative 'instrumentation/delayed_job'
|
|
130
178
|
DelayedJobInstrumentation.install!
|
|
131
179
|
end
|
|
132
180
|
|
|
133
181
|
def install_grape!
|
|
134
182
|
return unless defined?(::Grape::API)
|
|
135
183
|
|
|
136
|
-
require_relative
|
|
184
|
+
require_relative 'instrumentation/grape'
|
|
137
185
|
GrapeInstrumentation.install!
|
|
138
186
|
end
|
|
139
187
|
|
|
140
188
|
def install_solid_queue!
|
|
141
189
|
return unless defined?(::SolidQueue)
|
|
142
190
|
|
|
143
|
-
require_relative
|
|
191
|
+
require_relative 'instrumentation/solid_queue'
|
|
144
192
|
SolidQueueInstrumentation.install!
|
|
145
193
|
end
|
|
146
194
|
|
|
147
195
|
def install_good_job!
|
|
148
196
|
return unless defined?(::GoodJob)
|
|
149
197
|
|
|
150
|
-
require_relative
|
|
198
|
+
require_relative 'instrumentation/good_job'
|
|
151
199
|
GoodJobInstrumentation.install!
|
|
152
200
|
end
|
|
153
201
|
|
|
154
202
|
def install_resque!
|
|
155
203
|
return unless defined?(::Resque)
|
|
156
204
|
|
|
157
|
-
require_relative
|
|
205
|
+
require_relative 'instrumentation/resque'
|
|
158
206
|
ResqueInstrumentation.install!
|
|
159
207
|
end
|
|
160
208
|
|
|
161
209
|
def install_excon!
|
|
162
210
|
return unless defined?(::Excon)
|
|
163
211
|
|
|
164
|
-
require_relative
|
|
212
|
+
require_relative 'instrumentation/excon'
|
|
165
213
|
ExconInstrumentation.install!
|
|
166
214
|
end
|
|
167
215
|
|
|
168
216
|
def install_typhoeus!
|
|
169
217
|
return unless defined?(::Typhoeus)
|
|
170
218
|
|
|
171
|
-
require_relative
|
|
219
|
+
require_relative 'instrumentation/typhoeus'
|
|
172
220
|
TyphoeusInstrumentation.install!
|
|
173
221
|
end
|
|
174
222
|
|
|
175
223
|
def install_dalli!
|
|
176
224
|
return unless defined?(::Dalli::Client)
|
|
177
225
|
|
|
178
|
-
require_relative
|
|
226
|
+
require_relative 'instrumentation/dalli'
|
|
179
227
|
DalliInstrumentation.install!
|
|
180
228
|
end
|
|
181
229
|
|
|
182
230
|
def install_aws!
|
|
183
231
|
return unless defined?(::Aws)
|
|
184
232
|
|
|
185
|
-
require_relative
|
|
233
|
+
require_relative 'instrumentation/aws'
|
|
186
234
|
AWSInstrumentation.install!
|
|
187
235
|
end
|
|
188
236
|
|
|
189
237
|
def install_stripe!
|
|
190
238
|
return unless defined?(::Stripe)
|
|
191
239
|
|
|
192
|
-
require_relative
|
|
240
|
+
require_relative 'instrumentation/stripe'
|
|
193
241
|
StripeInstrumentation.install!
|
|
194
242
|
end
|
|
195
243
|
|
|
244
|
+
def install_active_storage!
|
|
245
|
+
return unless defined?(::ActiveStorage)
|
|
246
|
+
|
|
247
|
+
require_relative 'instrumentation/active_storage'
|
|
248
|
+
ActiveStorage.install!
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def install_action_cable!
|
|
252
|
+
return unless defined?(::ActionCable)
|
|
253
|
+
|
|
254
|
+
require_relative 'instrumentation/action_cable'
|
|
255
|
+
ActionCable.install!
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
def install_action_dispatch!
|
|
259
|
+
return unless defined?(::ActionDispatch)
|
|
260
|
+
|
|
261
|
+
require_relative 'instrumentation/action_dispatch'
|
|
262
|
+
ActionDispatch.install!
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
def install_rails_deprecation!
|
|
266
|
+
return unless defined?(::Rails)
|
|
267
|
+
|
|
268
|
+
require_relative 'instrumentation/rails_deprecation'
|
|
269
|
+
RailsDeprecation.install!
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
def install_action_mailbox!
|
|
273
|
+
return unless defined?(::ActionMailbox)
|
|
274
|
+
|
|
275
|
+
require_relative 'instrumentation/action_mailbox'
|
|
276
|
+
ActionMailbox.install!
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
def install_railties!
|
|
280
|
+
return unless defined?(::Rails)
|
|
281
|
+
|
|
282
|
+
require_relative 'instrumentation/railties'
|
|
283
|
+
Railties.install!
|
|
284
|
+
end
|
|
285
|
+
|
|
196
286
|
# Manual installation methods for lazy-loaded libraries
|
|
197
287
|
def install_http!
|
|
198
288
|
install_net_http!
|