Class: StackifyRubyAPM::Spies::YellSpy Private

Inherits:
Object
  • Object
show all
Defined in:
lib/stackify_apm/spies/yell.rb

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.

Constant Summary collapse

SEVERITIES =

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

['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL', 'UNKNOWN'].freeze

Instance Method Summary collapse

Instance Method Details

#installObject

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.



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
56
57
58
59
60
# File 'lib/stackify_apm/spies/yell.rb', line 12

def install
  Yell::Logger.module_eval do
    alias_method 'add_without_apm', 'add'

    # Log messages
    def add(options, *messages, &block)
      return add_without_apm(options, *messages, &block) unless StackifyRubyAPM.current_transaction

      begin
        name = 'yell;'
        type = 'ext.yell'
        log_message = []
        exception = []

        messages.each { |msg|
          case msg
          when ::String
            log_message.push(msg)
          when ::Exception
            log_message.push(msg.message)
            exception.push("(#{ msg.class })\n#{ msg.backtrace.join("\n") if msg.backtrace }")
          else
            log_message.push(msg.inspect)
          end
        }

        ctx = Span::Context.new(
          CATEGORY: 'Log',
          SUBCATEGORY: 'Yell',
          LEVEL: SEVERITIES[options.severity],
          MESSAGE: log_message.to_s,
          PREFIX: 'TRUE'
        )

        if exception.length > 0
          ctx.EXCEPTION = exception.to_s
        end
      rescue Exception => e
        StackifyRubyAPM.agent.error "[YellSpy] Error: creating span context."
        StackifyRubyAPM.agent.error "[YellSpy] #{e.inspect}"
        return add_without_apm(options, *messages, &block)
      end

      StackifyRubyAPM.span name, type, context: ctx do
        add_without_apm(options, *messages, &block)
      end
    end
  end
end