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

[SDTEST-409] Automatically avoid webmock stubs when sending telemetry events #3758

Closed
wants to merge 4 commits into from

Conversation

anmarchenko
Copy link
Member

What does this PR do?
Configures telemetry transport to use the original ::Net::HTTP client even if it is stubbed by WebMock. We do this by using WebMock::HttpLibAdapters::NetHttpAdapter::OriginalNetHTTP in place of Net::HTTP (if OriginalNetHTTP is present).

One can see that WebMock stores the original Net::HTTP in this constant here:
https://github.com/bblimke/webmock/blob/fc6a2ab897a069d861adbc1c88e51b2cf8aa88ac/lib/webmock/http_lib_adapters/net_http.rb#L14

See the PR adding the same functionality to the datadog-ci gem:
DataDog/datadog-ci-rb#193

It was released in version 1.1 of datadog-ci.

Motivation:
WebMock is often used when running test suites, but we still need to report library telemetry.

Currently we recommend in our docs making an exception for Datadog endpoints when using datadog-ci gem but this exception is error-prone and leads to a lot of support version. Since v1.1 of datadog-ci we use this approach to send HTTP requests avoiding webmock stubs automatically, without user intervention. This PR adds the same capabilities to the telemetry transport.

How to test the change?
There is a unit with assertion that webmock is not raising even after WebMock.disable_net_connect! is called.

datadog-ci gem uses exactly the same approach for WebMock handling:
DataDog/datadog-ci-rb#193

Example project where we use test visibility without any custom configuration and webmock is enabled:

https://github.com/DataDog/fast_castle/blob/main/spec/spec_helper.rb#L5

https://github.com/DataDog/fast_castle/pull/6

@anmarchenko anmarchenko requested a review from a team as a code owner July 4, 2024 14:14
@github-actions github-actions bot added the core Involves Datadog core libraries label Jul 4, 2024
@anmarchenko anmarchenko marked this pull request as draft July 4, 2024 14:15
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.91%. Comparing base (849c60c) to head (6650e3f).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3758   +/-   ##
=======================================
  Coverage   97.91%   97.91%           
=======================================
  Files        1241     1241           
  Lines       74632    74652   +20     
  Branches     3605     3608    +3     
=======================================
+ Hits        73074    73095   +21     
+ Misses       1558     1557    -1     

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

@anmarchenko anmarchenko marked this pull request as ready for review July 4, 2024 14:49
@anmarchenko anmarchenko closed this Jul 4, 2024
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.

2 participants