Class: Appsignal::EventFormatter Private

Inherits:
Object
  • Object
show all
Extended by:
Utils::DeprecationMessage
Defined in:
lib/appsignal/event_formatter.rb,
lib/appsignal/event_formatter/rom/sql_formatter.rb,
lib/appsignal/event_formatter/sequel/sql_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, Rom, Sequel

Constant Summary collapse

DEFAULT =
0
SQL_BODY_FORMAT =
1

Class Method Summary collapse

Methods included from Utils::DeprecationMessage

deprecation_message, message

Class Method Details

.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.



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

def format(name, payload)
  formatter = formatters[name]
  formatter&.format(payload)
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.



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

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

.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.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/appsignal/event_formatter.rb', line 27

def register(name, formatter = nil)
  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)


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

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.



39
40
41
42
43
44
# File 'lib/appsignal/event_formatter.rb', line 39

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

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