@@ -21,9 +21,10 @@ class Client
2121 extend Options
2222 extend Helpers
2323
24- attr_reader :statsd
24+ attr_reader :statsd , :logger
2525
26- def initialize ( statsd : nil , enabled : true , **_ )
26+ def initialize ( logger :, statsd : nil , enabled : true , **_ )
27+ @logger = logger
2728 @statsd =
2829 if supported?
2930 statsd || default_statsd_client
@@ -98,7 +99,7 @@ def count(stat, value = nil, options = nil, &block)
9899
99100 statsd . count ( stat , value , metric_options ( options ) )
100101 rescue StandardError => e
101- Datadog . logger . error (
102+ logger . error (
102103 "Failed to send count stat. Cause: #{ e . class . name } #{ e . message } Source: #{ Array ( e . backtrace ) . first } "
103104 )
104105 Telemetry ::Logger . report ( e , description : 'Failed to send count stat' )
@@ -112,7 +113,7 @@ def distribution(stat, value = nil, options = nil, &block)
112113
113114 statsd . distribution ( stat , value , metric_options ( options ) )
114115 rescue StandardError => e
115- Datadog . logger . error (
116+ logger . error (
116117 "Failed to send distribution stat. Cause: #{ e . class . name } #{ e . message } Source: #{ Array ( e . backtrace ) . first } "
117118 )
118119 Telemetry ::Logger . report ( e , description : 'Failed to send distribution stat' )
@@ -125,7 +126,7 @@ def increment(stat, options = nil)
125126
126127 statsd . increment ( stat , metric_options ( options ) )
127128 rescue StandardError => e
128- Datadog . logger . error (
129+ logger . error (
129130 "Failed to send increment stat. Cause: #{ e . class . name } #{ e . message } Source: #{ Array ( e . backtrace ) . first } "
130131 )
131132 Telemetry ::Logger . report ( e , description : 'Failed to send increment stat' )
@@ -139,7 +140,7 @@ def gauge(stat, value = nil, options = nil, &block)
139140
140141 statsd . gauge ( stat , value , metric_options ( options ) )
141142 rescue StandardError => e
142- Datadog . logger . error (
143+ logger . error (
143144 "Failed to send gauge stat. Cause: #{ e . class . name } #{ e . message } Source: #{ Array ( e . backtrace ) . first } "
144145 )
145146 Telemetry ::Logger . report ( e , description : 'Failed to send gauge stat' )
@@ -159,7 +160,7 @@ def time(stat, options = nil)
159160 end
160161 rescue StandardError => e
161162 # TODO: Likely to be redundant, since `distribution` handles its own errors.
162- Datadog . logger . error (
163+ logger . error (
163164 "Failed to send time stat. Cause: #{ e . class . name } #{ e . message } Source: #{ Array ( e . backtrace ) . first } "
164165 )
165166 Telemetry ::Logger . report ( e , description : 'Failed to send time stat' )
@@ -194,7 +195,7 @@ def dogstatsd_version
194195
195196 def ignored_statsd_warning
196197 IGNORED_STATSD_ONLY_ONCE . run do
197- Datadog . logger . warn (
198+ logger . warn (
198199 'Ignoring user-supplied statsd instance as currently-installed version of dogstastd-ruby is incompatible. ' \
199200 "To fix this, ensure that you have `gem 'dogstatsd-ruby', '~> 5.3'` on your Gemfile or gems.rb file."
200201 )
0 commit comments