Module: TwirpRails::LoggingAdapter

Defined in:
lib/twirp_rails/logging_adapter.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.installObject



6
7
8
9
10
11
12
# File 'lib/twirp_rails/logging_adapter.rb', line 6

def self.install
  return unless defined?(ActiveSupport::Notifications)

  TwirpRails::Routes::Helper.on_create_service do |service|
    LoggingAdapter.instrument service
  end
end

.instrument(service) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/twirp_rails/logging_adapter.rb', line 14

def self.instrument(service)
  instrumenter = ActiveSupport::Notifications.instrumenter

  service.before do |rack_env, env|
    payload = {
      rack_env: rack_env,
      env: env
    }
    instrumenter.start 'instrumenter.twirp', payload
  end

  service.on_error do |_twerr, _env|
    instrumenter.finish 'instrumenter.twirp', {}
  end

  service.on_success do |_env|
    instrumenter.finish 'instrumenter.twirp', {}
  end

  service.exception_raised do |e, env|
    env[:exception] = {
      class: e.class,
      message: e.message,
      backtrace: e.backtrace.join("\n")
    }
  end
end