Class: Appsignal::EventFormatter Private

Inherits:
Object
  • Object
show all
Extended by:
Utils::DeprecationMessage
Defined in:
lib/appsignal/event_formatter.rb,
lib/appsignal/event_formatter/moped/query_formatter.rb,
lib/appsignal/event_formatter/faraday/request_formatter.rb,
lib/appsignal/event_formatter/active_record/sql_formatter.rb,
lib/appsignal/event_formatter/action_view/render_formatter.rb,
lib/appsignal/event_formatter/elastic_search/search_formatter.rb,
lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter.rb,
lib/appsignal/event_formatter/active_record/instantiation_formatter.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Keeps track of formatters for types event that we can use to get the title and body of an event. Formatters should inherit from this class and implement a format(payload) method which returns an array with the title and body.

When implementing a formatter remember that it cannot keep separate state per event, the same object will be called intermittently in a threaded environment. So only keep global configuration as state and pass the payload around as an argument if you need to use helper methods.

Defined Under Namespace

Modules: ActionView, ActiveRecord, ElasticSearch, Faraday, MongoRubyDriver, Moped

Constant Summary collapse

DEFAULT =
0
SQL_BODY_FORMAT =
1

Class Method Summary collapse

Methods included from Utils::DeprecationMessage

deprecation_message, message

Class Method Details

.deprecated_formatter_classesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


23
24
25
# File 'lib/appsignal/event_formatter.rb', line 23

def deprecated_formatter_classes
  @deprecated_formatter_classes ||= {}
end

.format(name, payload) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


69
70
71
72
# File 'lib/appsignal/event_formatter.rb', line 69

def format(name, payload)
  formatter = formatters[name]
  formatter.format(payload) unless formatter.nil?
end

.formatter_classesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


27
28
29
# File 'lib/appsignal/event_formatter.rb', line 27

def formatter_classes
  @formatter_classes ||= {}
end

.formattersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


19
20
21
# File 'lib/appsignal/event_formatter.rb', line 19

def formatters
  @formatters ||= {}
end

.initialize_deprecated_formattersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


48
49
50
51
52
# File 'lib/appsignal/event_formatter.rb', line 48

def initialize_deprecated_formatters
  deprecated_formatter_classes.each do |name, formatter|
    register(name, formatter)
  end
end

.register(name, formatter = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/appsignal/event_formatter.rb', line 31

def register(name, formatter = nil)
  unless formatter
    register_deprecated_formatter(name)
    return
  end

  if registered?(name, formatter)
    logger.warn(
      "Formatter for '#{name}' already registered, not registering "\
      "'#{formatter.name}'"
    )
    return
  end

  initialize_formatter name, formatter
end

.registered?(name, klass = nil) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

61
62
63
64
65
66
67
# File 'lib/appsignal/event_formatter.rb', line 61

def registered?(name, klass = nil)
  if klass
    formatter_classes[name] == klass
  else
    formatter_classes.include?(name)
  end
end

.unregister(name, formatter = self) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


54
55
56
57
58
59
# File 'lib/appsignal/event_formatter.rb', line 54

def unregister(name, formatter = self)
  return unless formatter_classes[name] == formatter

  formatter_classes.delete(name)
  formatters.delete(name)
end