Sha256: 34a683c653e3b983ade2e1af74e488853ff6fe22aad124fbdb4fb9062d9b7fe5

Contents?: true

Size: 1015 Bytes

Versions: 16

Compression:

Stored size: 1015 Bytes

Contents

# frozen_string_literal: true
require 'twirp_rails/routes'

module TwirpRails
  module LoggingAdapter # :nodoc:
    def self.install
      return unless defined?(ActiveSupport::Notifications)

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

    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
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
twirp_rails-0.4.11 lib/twirp_rails/logging_adapter.rb
twirp_rails-0.4.10 lib/twirp_rails/logging_adapter.rb
twirp_rails-0.4.9 lib/twirp_rails/logging_adapter.rb
twirp_rails-0.4.8 lib/twirp_rails/logging_adapter.rb
twirp_rails-0.4.7 lib/twirp_rails/logging_adapter.rb
twirp_rails-0.4.6 lib/twirp_rails/logging_adapter.rb
twirp_rails-0.4.5 lib/twirp_rails/logging_adapter.rb
twirp_rails-0.4.4 lib/twirp_rails/logging_adapter.rb
twirp_rails-0.4.3 lib/twirp_rails/logging_adapter.rb
twirp_rails-0.4.2 lib/twirp_rails/logging_adapter.rb
twirp_rails-0.4.1 lib/twirp_rails/logging_adapter.rb
twirp_rails-0.4.0 lib/twirp_rails/logging_adapter.rb
twirp_rails-0.3.2 lib/twirp_rails/logging_adapter.rb
twirp_rails-0.3.1 lib/twirp_rails/logging_adapter.rb
twirp_rails-0.3.0 lib/twirp_rails/logging_adapter.rb
twirp_rails-0.2.1 lib/twirp_rails/logging_adapter.rb