Module: UniversalRenderer::Client::Stream::ErrorLogger

Defined in:
lib/universal_renderer/client/stream/error_logger.rb

Class Method Summary collapse

Class Method Details

.log_connection_error(error, target_uri_string, context = {}) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/universal_renderer/client/stream/error_logger.rb', line 16

def self.log_connection_error(error, target_uri_string, context = {})
  UniversalRenderer.log do |log|
    log.error(
      "SSR stream connection to #{target_uri_string} failed: #{error.class.name} - #{error.message}"
    )
  end
  report(error, target_uri_string, :connection, context)
end

.log_setup_error(error, target_uri_string, context = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/universal_renderer/client/stream/error_logger.rb', line 5

def self.log_setup_error(error, target_uri_string, context = {})
  backtrace_info = error.backtrace&.first || "No backtrace available"
  UniversalRenderer.log do |log|
    log.error(
      "Unexpected error during SSR stream setup for #{target_uri_string}: " \
        "#{error.class.name} - #{error.message} at #{backtrace_info}"
    )
  end
  report(error, target_uri_string, :setup, context)
end

.log_unexpected_error(error, target_uri_string, context_message, context = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/universal_renderer/client/stream/error_logger.rb', line 25

def self.log_unexpected_error(
  error,
  target_uri_string,
  context_message,
  context = {}
)
  backtrace_info = error.backtrace&.first || "No backtrace available"
  UniversalRenderer.log do |log|
    log.error(
      "#{context_message} for #{target_uri_string}: " \
        "#{error.class.name} - #{error.message} at #{backtrace_info}"
    )
  end
  report(error, target_uri_string, :unexpected, context)
end

.report(error, target_uri_string, stage, context = {}) ⇒ Object

Streaming failures fall back to client-side rendering just as blocking ones do, so they need the same escape hatch to an exception tracker.



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/universal_renderer/client/stream/error_logger.rb', line 43

def self.report(error, target_uri_string, stage, context = {})
  Instrumentation.report(
    error,
    context.merge(
      mode: :streaming,
      outcome: context.fetch(:outcome, :error),
      stage: stage,
      target: target_uri_string
    )
  )
end