Class: WaterDrop::Instrumentation::LoggerListener

Inherits:
Object
  • Object
show all
Defined in:
lib/waterdrop/instrumentation/logger_listener.rb

Overview

Note:

It is a module as we can use it then as a part of the Karafka framework listener as well as we can use it standalone

Default listener that hooks up to our instrumentation and uses its events for logging It can be removed/replaced or anything without any harm to the Waterdrop flow

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ LoggerListener

Returns a new instance of LoggerListener.

Parameters:

  • logger (Object)

    logger we want to use



12
13
14
# File 'lib/waterdrop/instrumentation/logger_listener.rb', line 12

def initialize(logger)
  @logger = logger
end

Instance Method Details

#on_buffer_flushed_async(event) ⇒ Object

Parameters:

  • event (Dry::Events::Event)

    event that happened with the details



67
68
69
70
71
72
# File 'lib/waterdrop/instrumentation/logger_listener.rb', line 67

def on_buffer_flushed_async(event)
  messages = event[:messages]

  info(event, "Async flushing of #{messages.size} messages from the buffer")
  debug(event, messages)
end

#on_buffer_flushed_sync(event) ⇒ Object

Parameters:

  • event (Dry::Events::Event)

    event that happened with the details



75
76
77
78
79
80
# File 'lib/waterdrop/instrumentation/logger_listener.rb', line 75

def on_buffer_flushed_sync(event)
  messages = event[:messages]

  info(event, "Sync flushing of #{messages.size} messages from the buffer")
  debug(event, messages)
end

#on_error_occurred(event) ⇒ Object

Parameters:

  • event (Dry::Events::Event)

    event that happened with the error details



88
89
90
91
92
93
# File 'lib/waterdrop/instrumentation/logger_listener.rb', line 88

def on_error_occurred(event)
  error = event[:error]
  type = event[:type]

  error(event, "Error occurred: #{error} - #{type}")
end

#on_message_buffered(event) ⇒ Object

Parameters:

  • event (Dry::Events::Event)

    event that happened with the details



51
52
53
54
55
56
# File 'lib/waterdrop/instrumentation/logger_listener.rb', line 51

def on_message_buffered(event)
  message = event[:message]

  info(event, "Buffering of a message to '#{message[:topic]}' topic")
  debug(event, [message])
end

#on_message_produced_async(event) ⇒ Object

Parameters:

  • event (Dry::Events::Event)

    event that happened with the details



17
18
19
20
21
22
# File 'lib/waterdrop/instrumentation/logger_listener.rb', line 17

def on_message_produced_async(event)
  message = event[:message]

  info(event, "Async producing of a message to '#{message[:topic]}' topic")
  debug(event, message)
end

#on_message_produced_sync(event) ⇒ Object

Parameters:

  • event (Dry::Events::Event)

    event that happened with the details



25
26
27
28
29
30
# File 'lib/waterdrop/instrumentation/logger_listener.rb', line 25

def on_message_produced_sync(event)
  message = event[:message]

  info(event, "Sync producing of a message to '#{message[:topic]}' topic")
  debug(event, message)
end

#on_messages_buffered(event) ⇒ Object

Parameters:

  • event (Dry::Events::Event)

    event that happened with the details



59
60
61
62
63
64
# File 'lib/waterdrop/instrumentation/logger_listener.rb', line 59

def on_messages_buffered(event)
  messages = event[:messages]

  info(event, "Buffering of #{messages.size} messages")
  debug(event, [messages, messages.size])
end

#on_messages_produced_async(event) ⇒ Object

Parameters:

  • event (Dry::Events::Event)

    event that happened with the details



33
34
35
36
37
38
39
# File 'lib/waterdrop/instrumentation/logger_listener.rb', line 33

def on_messages_produced_async(event)
  messages = event[:messages]
  topics_count = messages.map { |message| "'#{message[:topic]}'" }.uniq.count

  info(event, "Async producing of #{messages.size} messages to #{topics_count} topics")
  debug(event, messages)
end

#on_messages_produced_sync(event) ⇒ Object

Parameters:

  • event (Dry::Events::Event)

    event that happened with the details



42
43
44
45
46
47
48
# File 'lib/waterdrop/instrumentation/logger_listener.rb', line 42

def on_messages_produced_sync(event)
  messages = event[:messages]
  topics_count = messages.map { |message| "'#{message[:topic]}'" }.uniq.count

  info(event, "Sync producing of #{messages.size} messages to #{topics_count} topics")
  debug(event, messages)
end

#on_producer_closed(event) ⇒ Object

Parameters:

  • event (Dry::Events::Event)

    event that happened with the details



83
84
85
# File 'lib/waterdrop/instrumentation/logger_listener.rb', line 83

def on_producer_closed(event)
  info event, 'Closing producer'
end