diff --git a/lib/datadog/core/telemetry/emitter.rb b/lib/datadog/core/telemetry/emitter.rb index 1bf1dca8333..c4a18c264ce 100644 --- a/lib/datadog/core/telemetry/emitter.rb +++ b/lib/datadog/core/telemetry/emitter.rb @@ -26,7 +26,7 @@ def request(event) seq_id = self.class.sequence.next payload = Request.build_payload(event, seq_id) res = @http_transport.request(request_type: event.type, payload: payload.to_json) - Datadog.logger.debug { "Telemetry sent for event `#{event.type}` (status code: #{res.code})" } + Datadog.logger.debug { "Telemetry sent for event `#{event.type}` (code: #{res.code.inspect})" } res rescue => e Datadog.logger.debug("Unable to send telemetry request for event `#{event.type rescue 'unknown'}`: #{e}") diff --git a/lib/datadog/core/telemetry/http/response.rb b/lib/datadog/core/telemetry/http/response.rb index 81a1025647b..696ecd1432d 100644 --- a/lib/datadog/core/telemetry/http/response.rb +++ b/lib/datadog/core/telemetry/http/response.rb @@ -34,6 +34,10 @@ def internal_error? nil end + def code + nil + end + def inspect "#{self.class} ok?:#{ok?} unsupported?:#{unsupported?}, " \ "not_found?:#{not_found?}, client_error?:#{client_error?}, " \ diff --git a/spec/datadog/core/telemetry/emitter_spec.rb b/spec/datadog/core/telemetry/emitter_spec.rb index 3aedf0cb1e3..e7373a5874f 100644 --- a/spec/datadog/core/telemetry/emitter_spec.rb +++ b/spec/datadog/core/telemetry/emitter_spec.rb @@ -74,6 +74,21 @@ expect(emitter.class.sequence.instance_variable_get(:@current)).to be(original_seq_id + 1) end end + + context 'when call is not successful and debug logging is enabled' do + let(:response) do + Datadog::Core::Telemetry::Http::InternalErrorResponse.new(StandardError.new('Failed call')) + end + + it 'logs the request correctly' do + log_message = nil + expect(Datadog.logger).to receive(:debug) { |&message| log_message = message.call } + + request + + expect(log_message).to match('Telemetry sent for event') + end + end end end