Class: Lamian::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/lamian/engine.rb

Overview

This engine is automatically loaded by Rails

See Also:

Instance Method Summary collapse

Instance Method Details

#build_default_lambdaProc

Builds a callback, which does nothing.

Returns:

  • (Proc)

    empty callback.



44
45
46
# File 'lib/lamian/engine.rb', line 44

def build_default_lambda
  -> (event, _hint) { event }
end

#build_lamian_callbackProc

Builds a callback that adds logs to the event.

Returns:

  • (Proc)

    callback.



51
52
53
54
55
56
57
58
59
# File 'lib/lamian/engine.rb', line 51

def build_lamian_callback
  lambda do |event|
    event.tap do |event|
      extra = event&.extra or return
      log = Lamian.dump_limited
      extra[Lamian::SENTRY_EXTRA_KEY] = log if log
    end
  end
end

#rebuild_before_sendProc

Reassembles the callback that runs before sending the event to the Sentry: connects the user callback with the callback that adds lamian logs to the event.

Returns:

  • (Proc)

    final callback.



34
35
36
37
38
39
# File 'lib/lamian/engine.rb', line 34

def rebuild_before_send
  defined_callback = Sentry.configuration.before_send || build_default_lambda
  lamian_callback = build_lamian_callback

  proc { |*args, **kwargs| lamian_callback.call(defined_callback.call(*args, **kwargs)) }
end