Class: Opbeat::ErrorMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/opbeat/error_message.rb,
lib/opbeat/error_message/http.rb,
lib/opbeat/error_message/user.rb,
lib/opbeat/error_message/exception.rb,
lib/opbeat/error_message/stacktrace.rb

Defined Under Namespace

Classes: Exception, HTTP, Stacktrace, User

Constant Summary collapse

DEFAULTS =
{
  level: :error,
  logger: 'root'.freeze
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, message, attrs = {}) {|_self| ... } ⇒ ErrorMessage

Returns a new instance of ErrorMessage.

Yields:

  • (_self)

Yield Parameters:



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/opbeat/error_message.rb', line 16

def initialize config, message, attrs = {}
  @config = config

  @message = message
  @timestamp = Time.now.utc.to_i
  DEFAULTS.merge(attrs).each do |k,v|
    send(:"#{k}=", v)
  end
  @filter = Filter.new config

  yield self if block_given?
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



29
30
31
# File 'lib/opbeat/error_message.rb', line 29

def config
  @config
end

#culpritObject

Returns the value of attribute culprit.



34
35
36
# File 'lib/opbeat/error_message.rb', line 34

def culprit
  @culprit
end

#exceptionObject

Returns the value of attribute exception.



38
39
40
# File 'lib/opbeat/error_message.rb', line 38

def exception
  @exception
end

#extraObject

Returns the value of attribute extra.



36
37
38
# File 'lib/opbeat/error_message.rb', line 36

def extra
  @extra
end

#httpObject

Returns the value of attribute http.



40
41
42
# File 'lib/opbeat/error_message.rb', line 40

def http
  @http
end

#levelObject

Returns the value of attribute level.



32
33
34
# File 'lib/opbeat/error_message.rb', line 32

def level
  @level
end

#loggerObject

Returns the value of attribute logger.



33
34
35
# File 'lib/opbeat/error_message.rb', line 33

def logger
  @logger
end

#machineObject

Returns the value of attribute machine.



35
36
37
# File 'lib/opbeat/error_message.rb', line 35

def machine
  @machine
end

#messageObject

Returns the value of attribute message.



30
31
32
# File 'lib/opbeat/error_message.rb', line 30

def message
  @message
end

#param_messageObject

Returns the value of attribute param_message.



37
38
39
# File 'lib/opbeat/error_message.rb', line 37

def param_message
  @param_message
end

#stacktraceObject

Returns the value of attribute stacktrace.



39
40
41
# File 'lib/opbeat/error_message.rb', line 39

def stacktrace
  @stacktrace
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



31
32
33
# File 'lib/opbeat/error_message.rb', line 31

def timestamp
  @timestamp
end

#userObject

Returns the value of attribute user.



41
42
43
# File 'lib/opbeat/error_message.rb', line 41

def user
  @user
end

Class Method Details

.from_exception(config, exception, opts = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/opbeat/error_message.rb', line 43

def self.from_exception config, exception, opts = {}
  message = "#{exception.class}: #{exception.message}"

  if config.excluded_exceptions.include? exception.class.to_s
    info "Skipping excluded exception #{exception.class}"
    return nil
  end

  error_message = new(config, message) do |msg|
    msg.level = :error
    msg.exception = Exception.from(exception)
    msg.stacktrace = Stacktrace.from(config, exception)
  end

  if frames = error_message.stacktrace && error_message.stacktrace.frames
    if first_frame = frames.last
      error_message.culprit = "#{first_frame.filename}:#{first_frame.lineno}:in `#{first_frame.function}'"
    end
  end

  if env = opts[:rack_env]
    error_message.http = HTTP.from_rack_env env, filter: @filter
    error_message.user = User.from_rack_env config, env
  end

  if extra = opts[:extra]
    error_message.extra = extra
  end

  error_message
end

Instance Method Details

#add_extra(info) ⇒ Object



75
76
77
78
# File 'lib/opbeat/error_message.rb', line 75

def add_extra info
  @extra ||= {}
  @extra.merge! info
end