Class: FiberAudit::Runtime::SessionSummary

Inherits:
Data
  • Object
show all
Defined in:
lib/fiber_audit/runtime/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ended_at:, ended_monotonic_ns:, status:, **counters) ⇒ SessionSummary

Returns a new instance of SessionSummary.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/fiber_audit/runtime/session.rb', line 65

def initialize(ended_at:, ended_monotonic_ns:, status:, **counters)
  unknown = counters.keys - SessionSummary::COUNTERS
  missing = SessionSummary::COUNTERS - counters.keys
  raise RuntimeContractError, "unknown session summary field: #{unknown.first}" unless unknown.empty?
  raise RuntimeContractError, "missing session summary field: #{missing.first}" unless missing.empty?

  normalized_status = status.is_a?(String) || status.is_a?(Symbol) ? status.to_sym : nil
  unless SessionSummary::STATUSES.include?(normalized_status)
    raise RuntimeContractError, "status must be one of: #{SessionSummary::STATUSES.join(', ')}"
  end

  normalized_counters = counters.to_h do |name, value|
    [name, Validation.integer(value, name.to_s)]
  end
  accounted = %i[
    events_emitted
    sampled_out
    rate_limited
    session_event_limited
    session_byte_limited
    oversize
  ].sum { |name| normalized_counters.fetch(name) }
  if accounted > normalized_counters.fetch(:events_observed)
    raise RuntimeContractError, 'event accounting exceeds events_observed'
  end

  super(
    ended_at: Validation.utc_time(ended_at, 'ended_at'),
    ended_monotonic_ns: Validation.integer(ended_monotonic_ns, 'ended_monotonic_ns'),
    status: normalized_status,
    **normalized_counters
  )
end

Instance Attribute Details

#ended_atObject (readonly)

Returns the value of attribute ended_at

Returns:

  • (Object)

    the current value of ended_at



52
53
54
# File 'lib/fiber_audit/runtime/session.rb', line 52

def ended_at
  @ended_at
end

#ended_monotonic_nsObject (readonly)

Returns the value of attribute ended_monotonic_ns

Returns:

  • (Object)

    the current value of ended_monotonic_ns



52
53
54
# File 'lib/fiber_audit/runtime/session.rb', line 52

def ended_monotonic_ns
  @ended_monotonic_ns
end

#events_emittedObject (readonly)

Returns the value of attribute events_emitted

Returns:

  • (Object)

    the current value of events_emitted



52
53
54
# File 'lib/fiber_audit/runtime/session.rb', line 52

def events_emitted
  @events_emitted
end

#events_observedObject (readonly)

Returns the value of attribute events_observed

Returns:

  • (Object)

    the current value of events_observed



52
53
54
# File 'lib/fiber_audit/runtime/session.rb', line 52

def events_observed
  @events_observed
end

#internal_errorsObject (readonly)

Returns the value of attribute internal_errors

Returns:

  • (Object)

    the current value of internal_errors



52
53
54
# File 'lib/fiber_audit/runtime/session.rb', line 52

def internal_errors
  @internal_errors
end

#oversizeObject (readonly)

Returns the value of attribute oversize

Returns:

  • (Object)

    the current value of oversize



52
53
54
# File 'lib/fiber_audit/runtime/session.rb', line 52

def oversize
  @oversize
end

#rate_limitedObject (readonly)

Returns the value of attribute rate_limited

Returns:

  • (Object)

    the current value of rate_limited



52
53
54
# File 'lib/fiber_audit/runtime/session.rb', line 52

def rate_limited
  @rate_limited
end

#sampled_outObject (readonly)

Returns the value of attribute sampled_out

Returns:

  • (Object)

    the current value of sampled_out



52
53
54
# File 'lib/fiber_audit/runtime/session.rb', line 52

def sampled_out
  @sampled_out
end

#session_byte_limitedObject (readonly)

Returns the value of attribute session_byte_limited

Returns:

  • (Object)

    the current value of session_byte_limited



52
53
54
# File 'lib/fiber_audit/runtime/session.rb', line 52

def session_byte_limited
  @session_byte_limited
end

#session_event_limitedObject (readonly)

Returns the value of attribute session_event_limited

Returns:

  • (Object)

    the current value of session_event_limited



52
53
54
# File 'lib/fiber_audit/runtime/session.rb', line 52

def session_event_limited
  @session_event_limited
end

#statusObject (readonly)

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



52
53
54
# File 'lib/fiber_audit/runtime/session.rb', line 52

def status
  @status
end