v5.2.0 / 2021.07.01
You can use this mode to avoid spawning a companion thread while using v5.x versions:
# Import the library
require 'datadog/statsd'
# Create a DogStatsD client instance.
statsd = Datadog::Statsd.new('localhost', 8125, single_thread: true)
...
# release resources used by the client instance and flush last metrics
statsd.close()
Note that if you want to restore the behavior of v4.x versions, you can also configure the buffer to flush on every metric submission:
# Import the library
require 'datadog/statsd'
# Create a DogStatsD client instance using UDP
statsd = Datadog::Statsd.new('localhost', 8125, single_thread: true, buffer_max_pool_size: 1)
...
# to close the instance is not necessary in this case since metrics are flushed on submission
# but it is still a good practice and it explicitely closes the socket
statsd.close()