Skip to content

Commit

Permalink
Update sidekiq example
Browse files Browse the repository at this point in the history
Commit e2b9c7a in PR 180 updated `Datadog::Statsd#close` to also invoke `flush(sync: true)` automatically.
So the first `client.flush(sync: true)` in this example was redundant.
  • Loading branch information
jordan-brough authored Jul 23, 2022
1 parent bbeb5d7 commit 25ed9c9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions examples/sidekiq_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
# This Sidekiq worker uses a DogStatsD instance created every time this worker job
# is executed. Because of that, it is important to close this created client to
# free the resources it is using (a socket and a thread).
# It is important to manually flush the metrics calling the #flush method because
# the client instance internal buffer may not be full and the DogStatsD client is
# not flushing the metrics until that.
# Closing the client will also invoke "flush(sync: true)" to ensure metrics are
# flushed even if the client instance internal buffer is not full.
class ExampleEphemeralInstance
include Sidekiq::Worker
def perform()
client = Datadog::Statsd.new('localhost', 8125)
client.increment('example_metric.sample', tags: ['environment:dev'])
client.flush(sync: true) # flush all metrics created during the job execution
client.close() # free resources used by this ephemeral dogstatsd client instance
# flush all metrics created during the job execution and free resources used by
# this ephemeral dogstatsd client instance:
client.close()
puts("Metrics flushed and client closed")
end
end
Expand Down

0 comments on commit 25ed9c9

Please sign in to comment.