Class: Periskop::Client::ExceptionWithContext

Inherits:
Object
  • Object
show all
Defined in:
lib/periskop/client/models.rb

Overview

ExceptionWithContext represents a reported exception with HTTP context

Constant Summary collapse

NUM_HASH_CHARS =
8
MAX_TRACES =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception_instance, http_context, severity) ⇒ ExceptionWithContext

Returns a new instance of ExceptionWithContext.



86
87
88
89
90
91
92
# File 'lib/periskop/client/models.rb', line 86

def initialize(exception_instance, http_context, severity)
  @exception_instance = exception_instance
  @http_context = http_context
  @severity = severity
  @uuid = SecureRandom.uuid
  @timestamp = Time.now.utc.iso8601
end

Instance Attribute Details

#exception_instanceObject

Returns the value of attribute exception_instance.



81
82
83
# File 'lib/periskop/client/models.rb', line 81

def exception_instance
  @exception_instance
end

#http_contextObject

Returns the value of attribute http_context.



81
82
83
# File 'lib/periskop/client/models.rb', line 81

def http_context
  @http_context
end

Instance Method Details

#aggregation_keyObject

Generates the aggregation key with a hash using the last MAX_TRACES



95
96
97
98
99
# File 'lib/periskop/client/models.rb', line 95

def aggregation_key
  stacktrace_head = @exception_instance.stacktrace.first(MAX_TRACES).join('')
  error_hash = Digest::MD5.hexdigest(stacktrace_head)[0..NUM_HASH_CHARS - 1]
  "#{@exception_instance.class}@#{error_hash}"
end

#as_json(_options = {}) ⇒ Object



101
102
103
104
105
106
107
108
109
# File 'lib/periskop/client/models.rb', line 101

def as_json(_options = {})
  {
    error: @exception_instance,
    http_context: @http_context,
    severity: @severity,
    uuid: @uuid,
    timestamp: @timestamp
  }
end

#to_json(*options) ⇒ Object



111
112
113
# File 'lib/periskop/client/models.rb', line 111

def to_json(*options)
  as_json(*options).to_json(*options)
end