Module: BrainzLab::Instrumentation::StripeInstrumentation
- Defined in:
- lib/brainzlab/instrumentation/stripe.rb
Class Method Summary collapse
- .install! ⇒ Object
- .track_error(method, resource, _path, started_at, error) ⇒ Object
- .track_success(method, resource, path, started_at, _response) ⇒ Object
Class Method Details
.install! ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/brainzlab/instrumentation/stripe.rb', line 7 def install! return unless defined?(::Stripe) install_instrumentation! BrainzLab.debug_log('[Instrumentation] Stripe instrumentation installed') end |
.track_error(method, resource, _path, started_at, error) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/brainzlab/instrumentation/stripe.rb', line 125 def self.track_error(method, resource, _path, started_at, error) ((Time.now - started_at) * 1000).round(2) error_type = case error when Stripe::CardError then 'card_error' when Stripe::RateLimitError then 'rate_limit' when Stripe::InvalidRequestError then 'invalid_request' when Stripe::AuthenticationError then 'authentication' when Stripe::APIConnectionError then 'connection' when Stripe::StripeError then 'stripe_error' else 'unknown' end BrainzLab::Reflex.( "Stripe #{method.to_s.upcase} #{resource} failed: #{error.}", category: 'payment', level: :error, data: { method: method.to_s.upcase, resource: resource, error_type: error_type, error: error.class.name } ) if BrainzLab.configuration.flux_effectively_enabled? = { method: method.to_s.upcase, resource: resource, error_type: error_type } BrainzLab::Flux.increment('stripe.errors', tags: ) end # Capture with Reflex (but filter sensitive data) return unless BrainzLab.configuration.reflex_effectively_enabled? BrainzLab::Reflex.capture(error, tags: { source: 'stripe', resource: resource }, extra: { error_type: error_type }) end |
.track_success(method, resource, path, started_at, _response) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/brainzlab/instrumentation/stripe.rb', line 103 def self.track_success(method, resource, path, started_at, _response) duration_ms = ((Time.now - started_at) * 1000).round(2) BrainzLab::Reflex.( "Stripe #{method.to_s.upcase} #{resource}", category: 'payment', level: :info, data: { method: method.to_s.upcase, resource: resource, path: path, duration_ms: duration_ms } ) return unless BrainzLab.configuration.flux_effectively_enabled? = { method: method.to_s.upcase, resource: resource } BrainzLab::Flux.distribution('stripe.duration_ms', duration_ms, tags: ) BrainzLab::Flux.increment('stripe.requests', tags: ) end |