Class: ReeAudit::Audit
- Inherits:
-
Object
- Object
- ReeAudit::Audit
- Includes:
- Ree::BeanDSL
- Defined in:
- lib/ree_lib/packages/ree_audit/package/ree_audit/beans/audit.rb
Constant Summary collapse
- MAX_ERROR_MESSAGE_LENGTH =
512
Instance Method Summary collapse
-
#around(event) ⇒ Object
Wraps one action call.
- #sink ⇒ Object
- #sink=(value) ⇒ Object
Instance Method Details
#around(event) ⇒ Object
Wraps one action call. Everything the trail needs that is only knowable here — how it ended, how long it took, what the code annotated on the way — is filled in around the yield.
The exception itself is never swallowed: an audited route must behave exactly like an unaudited one.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/beans/audit.rb', line 36 def around(event) return yield if !config.enabled event.params = filter_params(event.params || {}) event.started_at = Time.now started_monotonic = Process.clock_gettime(Process::CLOCK_MONOTONIC) ReeAudit::Context.push(event) begin result = yield event.status = :ok result rescue StandardError => e event.status = status_for(e) event.error_type = e.class.name event. = e..to_s[0, MAX_ERROR_MESSAGE_LENGTH] raise ensure event.duration_ms = ( (Process.clock_gettime(Process::CLOCK_MONOTONIC) - started_monotonic) * 1000 ).round ReeAudit::Context.pop write_safely(event) if event.recordable? end end |
#sink ⇒ Object
22 23 24 |
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/beans/audit.rb', line 22 def sink @sink ||= NullSink.new end |
#sink=(value) ⇒ Object
26 27 28 |
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/beans/audit.rb', line 26 def sink=(value) @sink = value end |