Module: BrainzLab::Instrumentation::ExconInstrumentation::BrainzLabInstrumentor
- Defined in:
- lib/brainzlab/instrumentation/excon.rb
Overview
Excon Instrumentor for ActiveSupport-style notifications
Class Method Summary collapse
- .instrument(name, params = {}) ⇒ Object
- .skip_tracking?(params) ⇒ Boolean
- .track_request(_name, params, started_at, error) ⇒ Object
Class Method Details
.instrument(name, params = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/brainzlab/instrumentation/excon.rb', line 30 def self.instrument(name, params = {}) started_at = Time.now begin result = yield if block_given? track_request(name, params, started_at, nil) result rescue StandardError => e track_request(name, params, started_at, e) raise end end |
.skip_tracking?(params) ⇒ Boolean
85 86 87 88 89 90 91 |
# File 'lib/brainzlab/instrumentation/excon.rb', line 85 def self.skip_tracking?(params) host = params[:host] return true unless host ignore_hosts = BrainzLab.configuration.http_ignore_hosts || [] ignore_hosts.any? { |h| host.include?(h) } end |
.track_request(_name, params, started_at, error) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/brainzlab/instrumentation/excon.rb', line 43 def self.track_request(_name, params, started_at, error) return if skip_tracking?(params) duration_ms = ((Time.now - started_at) * 1000).round(2) host = params[:host] || 'unknown' method = (params[:method] || 'GET').to_s.upcase path = params[:path] || '/' status = params[:status] # Add breadcrumb BrainzLab::Reflex.( "HTTP #{method} #{host}#{path}", category: 'http', level: error ? :error : :info, data: { method: method, host: host, path: path, status: status, duration_ms: duration_ms } ) # Track with Pulse if BrainzLab.configuration.pulse_effectively_enabled? BrainzLab::Pulse.span('http.excon', kind: 'http') do # Already completed, just recording end end # Track with Flux return unless BrainzLab.configuration.flux_effectively_enabled? = { host: host, method: method, status: status.to_s } BrainzLab::Flux.distribution('http.excon.duration_ms', duration_ms, tags: ) BrainzLab::Flux.increment('http.excon.requests', tags: ) return unless error || (status && status >= 400) BrainzLab::Flux.increment('http.excon.errors', tags: ) end |