Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NO-TICKET] Fix error during telemetry debug logging attempt #3617

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/datadog/core/telemetry/emitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
4 changes: 4 additions & 0 deletions lib/datadog/core/telemetry/http/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?}, " \
Expand Down
15 changes: 15 additions & 0 deletions spec/datadog/core/telemetry/emitter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading