Class: Appsignal::EventFormatter::Moped::QueryFormatter

Inherits:
Appsignal::EventFormatter show all
Defined in:
lib/appsignal/event_formatter/moped/query_formatter.rb

Instance Method Summary collapse

Methods inherited from Appsignal::EventFormatter

format, formatter_classes, formatters, initialize_formatters, register, registered?, unregister

Instance Method Details

#format(payload) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/appsignal/event_formatter/moped/query_formatter.rb', line 7

def format(payload)
  if payload[:ops] && payload[:ops].length > 0
    op = payload[:ops].first
    case op.class.to_s
    when 'Moped::Protocol::Command'
      return ['Command', {
        :database => op.full_collection_name,
        :selector => Appsignal::Utils.sanitize(op.selector, true, :mongodb)
      }.inspect]
    when 'Moped::Protocol::Query'
      return ['Query', {
        :database => op.full_collection_name,
        :selector => Appsignal::Utils.sanitize(op.selector, false, :mongodb),
        :flags    => op.flags,
        :limit    => op.limit,
        :skip     => op.skip,
        :fields   => op.fields
      }.inspect]
    when 'Moped::Protocol::Delete'
      return ['Delete', {
        :database => op.full_collection_name,
        :selector => Appsignal::Utils.sanitize(op.selector, false, :mongodb),
        :flags    => op.flags,
      }.inspect]
    when 'Moped::Protocol::Insert'
      return ['Insert', {
        :database   => op.full_collection_name,
        :documents  => Appsignal::Utils.sanitize(op.documents, true, :mongodb),
        :count      => op.documents.count,
        :flags      => op.flags,
      }.inspect]
    when 'Moped::Protocol::Update'
      return ['Update', {
        :database => op.full_collection_name,
        :selector => Appsignal::Utils.sanitize(op.selector, false, :mongodb),
        :update   => Appsignal::Utils.sanitize(op.update, true, :mongodb),
        :flags    => op.flags,
      }.inspect]
    when 'Moped::Protocol::KillCursors'
      return ['KillCursors', {
        :number_of_cursor_ids => op.number_of_cursor_ids
      }.inspect]
    else
      return [op.class.to_s.sub('Moped::Protocol::', ''), {
        :database => op.full_collection_name
      }.inspect]
    end
  end
end