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

Backport "[NO-TICKET] Fix error during telemetry debug logging attempt" to 1.x-stable #3618

Merged
merged 1 commit into from
May 7, 2024

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented May 1, 2024

What does this PR do?

This PR backports #3617 to the 1.x-stable branch. See original PR for more details.

Motivation:

This fix also makes sense to apply on the 1.x-stable series.

Additional Notes:

I cherry-picked the upstream commit with no other changes.

How to test the change?

See original PR for details.

**What does this PR do?**

This PR fixes the following debug error log that would happen when
enabling debug logging + not having an agent running locally.

```
$ DD_TRACE_DEBUG=true bundle exec ruby -e "require 'datadog'; Datadog.configure {}; sleep 1"
...
DEBUG -- datadog: [datadog] (lib/datadog/core/telemetry/http/adapters/net.rb:47:in `rescue in post') Unable to send telemetry event to agent: Failed to open TCP connection to 127.0.0.1:8126 (Connection refused - connect(2) for "127.0.0.1" port 8126)
DEBUG -- datadog: [datadog] (lib/datadog/core/telemetry/emitter.rb:32:in `rescue in request') Unable to send telemetry request for event `app-started`: undefined method `code' for Datadog::Core::Telemetry::Http::InternalErrorResponse ok?: unsupported?:, not_found?:, client_error?:, server_error?:, internal_error?:true, payload:, error_type:Errno::ECONNREFUSED error:Failed to open TCP connection to 127.0.0.1:8126 (Connection refused - connect(2) for "127.0.0.1" port 8126):Datadog::Core::Telemetry::Http::InternalErrorResponse

            Datadog.logger.debug { "Telemetry sent for event `#{event.type}` (status code: #{res.code})" }
                                                                                                ^^^^^
```

Specifically, the class used to communicate errors
(`Datadog::Core::Telemetry::Http::Response::InternalErrorResponse`)
did not define a `#code` accessor, thus making the log message that
tries to debug the response code fail.

**Motivation:**

Fix this error.

**Additional Notes:**

The error itself was annoying, but harmless, as we did catch
the exception anyway.

I think the current approach of having a `Response` module that then
gets inserted into a few classes is a bit error prone.

And this is one where we definitely would've been saved by having
type signatures for this part of the code.

**How to test the change?**

I've added unit coverage + you can use the example above to
confirm it no longer happens manually.
@ivoanjo ivoanjo added this to the 1.23.0 milestone May 1, 2024
@ivoanjo ivoanjo requested a review from a team as a code owner May 1, 2024 14:27
@github-actions github-actions bot added the core Involves Datadog core libraries label May 1, 2024
@ivoanjo ivoanjo requested a review from a team May 1, 2024 14:29
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.24%. Comparing base (09ba2b0) to head (fb04d2d).
Report is 1 commits behind head on 1.x-stable.

Additional details and impacted files
@@             Coverage Diff             @@
##           1.x-stable    #3618   +/-   ##
===========================================
  Coverage       98.24%   98.24%           
===========================================
  Files            1255     1255           
  Lines           74569    74579   +10     
  Branches         3540     3540           
===========================================
+ Hits            73262    73272   +10     
  Misses           1307     1307           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ivoanjo ivoanjo merged commit dec0c3c into 1.x-stable May 7, 2024
195 checks passed
@ivoanjo ivoanjo deleted the ivoanjo/backport-pr3617 branch May 7, 2024 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Involves Datadog core libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants