Class: WaterDrop::Instrumentation::StdoutListener

Inherits:
Object
  • Object
show all
Defined in:
lib/water_drop/instrumentation/stdout_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) ⇒ StdoutListener

Returns a new instance of StdoutListener.

Parameters:

  • logger (Object)

    stdout logger we want to use



11
12
13
# File 'lib/water_drop/instrumentation/stdout_listener.rb', line 11

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



66
67
68
69
70
71
# File 'lib/water_drop/instrumentation/stdout_listener.rb', line 66

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_async_error(event) ⇒ Object

Parameters:

  • event (Dry::Events::Event)

    event that happened with the details



74
75
76
77
78
79
80
# File 'lib/water_drop/instrumentation/stdout_listener.rb', line 74

def on_buffer_flushed_async_error(event)
  messages = event[:messages]
  error = event[:error]

  error(event, "Async flushing of #{messages.size} failed due to: #{error}")
  debug(event, messages)
end

#on_buffer_flushed_sync(event) ⇒ Object

Parameters:

  • event (Dry::Events::Event)

    event that happened with the details



83
84
85
86
87
88
# File 'lib/water_drop/instrumentation/stdout_listener.rb', line 83

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_buffer_flushed_sync_error(event) ⇒ Object

Parameters:

  • event (Dry::Events::Event)

    event that happened with the details



91
92
93
94
95
96
97
# File 'lib/water_drop/instrumentation/stdout_listener.rb', line 91

def on_buffer_flushed_sync_error(event)
  messages = event[:dispatched]
  error = event[:error]

  error(event, "Sync flushing of #{messages.size} failed due to: #{error}")
  debug(event, messages)
end

#on_message_buffered(event) ⇒ Object

Parameters:

  • event (Dry::Events::Event)

    event that happened with the details



50
51
52
53
54
55
# File 'lib/water_drop/instrumentation/stdout_listener.rb', line 50

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

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

#on_message_produced_async(event) ⇒ Object

Parameters:

  • event (Dry::Events::Event)

    event that happened with the details



16
17
18
19
20
21
# File 'lib/water_drop/instrumentation/stdout_listener.rb', line 16

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



24
25
26
27
28
29
# File 'lib/water_drop/instrumentation/stdout_listener.rb', line 24

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



58
59
60
61
62
63
# File 'lib/water_drop/instrumentation/stdout_listener.rb', line 58

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

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

#on_messages_produced_async(event) ⇒ Object

Parameters:

  • event (Dry::Events::Event)

    event that happened with the details



32
33
34
35
36
37
38
# File 'lib/water_drop/instrumentation/stdout_listener.rb', line 32

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



41
42
43
44
45
46
47
# File 'lib/water_drop/instrumentation/stdout_listener.rb', line 41

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



100
101
102
103
# File 'lib/water_drop/instrumentation/stdout_listener.rb', line 100

def on_producer_closed(event)
  info event, 'Closing producer'
  debug event, event[:producer].messages.size
end