Module: UniversalRenderer::Instrumentation
- Defined in:
- lib/universal_renderer/instrumentation.rb
Overview
Every SSR failure falls back to client-side rendering silently, which is right for availability and useless for operations. These two hooks are the signal that SSR stopped working.
Constant Summary collapse
- NOTIFICATION =
ActiveSupport::Notifications event name. Subscribe to record hit rate and latency:
ActiveSupport::Notifications.subscribe("render.universal_renderer") do |event| StatsD.timing("ssr.duration", event.duration, tags: ["outcome:#{event.payload[:outcome]}"]) endPayload keys:
:url,:mode(:blockingor:streaming),:outcome(:ok,:not_configured,:http_error,:timeout, or:error), and:status/:errorwhere applicable. "render.universal_renderer"
Class Method Summary collapse
-
.instrument(url:, mode:) ⇒ Object
Instruments one render attempt.
-
.report(error, context) ⇒ Object
Hands an error to
config.on_error, if one is configured.
Class Method Details
.instrument(url:, mode:) ⇒ Object
Instruments one render attempt. The block receives the mutable payload so it can record the outcome it reached.
24 25 26 27 28 29 30 |
# File 'lib/universal_renderer/instrumentation.rb', line 24 def instrument(url:, mode:) payload = { url: url, mode: mode, outcome: :ok } ActiveSupport::Notifications.instrument(NOTIFICATION, payload) do yield payload end end |
.report(error, context) ⇒ Object
Hands an error to config.on_error, if one is configured. A raising
callback must not turn a degraded render into a failed request.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/universal_renderer/instrumentation.rb', line 34 def report(error, context) callback = UniversalRenderer.config.on_error return unless callback callback.call(error, context) rescue StandardError => e UniversalRenderer.log do |log| log.error( "on_error callback raised: #{e.class.name} - #{e.}" ) end end |