Class: InfluxReporter::ErrorMessage

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

Defined Under Namespace

Classes: Exception, HTTP, Stacktrace, User

Constant Summary collapse

DEFAULTS =
{
    level: :error,
    logger: 'root'
}.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:



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/influx_reporter/error_message.rb', line 20

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

  @message = message
  @timestamp = Util.nanos

  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.



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

def config
  @config
end

#culpritObject

Returns the value of attribute culprit.



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

def culprit
  @culprit
end

#databaseObject

Returns the value of attribute database.



48
49
50
# File 'lib/influx_reporter/error_message.rb', line 48

def database
  @database
end

#exceptionObject

Returns the value of attribute exception.



44
45
46
# File 'lib/influx_reporter/error_message.rb', line 44

def exception
  @exception
end

#extraObject

Returns the value of attribute extra.



42
43
44
# File 'lib/influx_reporter/error_message.rb', line 42

def extra
  @extra
end

#filterObject (readonly)

Returns the value of attribute filter.



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

def filter
  @filter
end

#httpObject

Returns the value of attribute http.



46
47
48
# File 'lib/influx_reporter/error_message.rb', line 46

def http
  @http
end

#levelObject

Returns the value of attribute level.



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

def level
  @level
end

#loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

#machineObject

Returns the value of attribute machine.



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

def machine
  @machine
end

#messageObject

Returns the value of attribute message.



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

def message
  @message
end

#param_messageObject

Returns the value of attribute param_message.



43
44
45
# File 'lib/influx_reporter/error_message.rb', line 43

def param_message
  @param_message
end

#stacktraceObject

Returns the value of attribute stacktrace.



45
46
47
# File 'lib/influx_reporter/error_message.rb', line 45

def stacktrace
  @stacktrace
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



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

def timestamp
  @timestamp
end

#userObject

Returns the value of attribute user.



47
48
49
# File 'lib/influx_reporter/error_message.rb', line 47

def user
  @user
end

Class Method Details

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



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/influx_reporter/error_message.rb', line 50

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&.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: error_message.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



82
83
84
85
# File 'lib/influx_reporter/error_message.rb', line 82

def add_extra(info)
  @extra ||= {}
  @extra.deep_merge! info
end