datadog-ci 1.11.0 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -2
  3. data/lib/datadog/ci/configuration/components.rb +27 -15
  4. data/lib/datadog/ci/configuration/settings.rb +12 -0
  5. data/lib/datadog/ci/contrib/cucumber/instrumentation.rb +5 -2
  6. data/lib/datadog/ci/contrib/cuprite/configuration/settings.rb +34 -0
  7. data/lib/datadog/ci/contrib/cuprite/driver.rb +94 -0
  8. data/lib/datadog/ci/contrib/cuprite/ext.rb +15 -0
  9. data/lib/datadog/ci/contrib/cuprite/integration.rb +44 -0
  10. data/lib/datadog/ci/contrib/cuprite/patcher.rb +24 -0
  11. data/lib/datadog/ci/contrib/cuprite/script_executor.rb +32 -0
  12. data/lib/datadog/ci/contrib/minitest/test.rb +3 -3
  13. data/lib/datadog/ci/contrib/rspec/example.rb +3 -3
  14. data/lib/datadog/ci/contrib/selenium/capybara_driver.rb +4 -4
  15. data/lib/datadog/ci/contrib/selenium/configuration/settings.rb +3 -1
  16. data/lib/datadog/ci/contrib/selenium/driver.rb +4 -4
  17. data/lib/datadog/ci/contrib/selenium/ext.rb +0 -15
  18. data/lib/datadog/ci/contrib/selenium/navigation.rb +2 -2
  19. data/lib/datadog/ci/ext/app_types.rb +1 -1
  20. data/lib/datadog/ci/ext/environment/providers/github_actions.rb +3 -0
  21. data/lib/datadog/ci/ext/environment.rb +4 -0
  22. data/lib/datadog/ci/ext/rum.rb +26 -0
  23. data/lib/datadog/ci/ext/settings.rb +2 -0
  24. data/lib/datadog/ci/ext/telemetry.rb +17 -5
  25. data/lib/datadog/ci/ext/test.rb +42 -4
  26. data/lib/datadog/ci/ext/transport.rb +6 -0
  27. data/lib/datadog/ci/remote/component.rb +11 -1
  28. data/lib/datadog/ci/remote/library_settings.rb +31 -0
  29. data/lib/datadog/ci/remote/library_settings_client.rb +2 -1
  30. data/lib/datadog/ci/test.rb +67 -9
  31. data/lib/datadog/ci/test_management/component.rb +61 -0
  32. data/lib/datadog/ci/test_management/null_component.rb +25 -0
  33. data/lib/datadog/ci/test_management/tests_properties.rb +128 -0
  34. data/lib/datadog/ci/test_optimisation/component.rb +5 -3
  35. data/lib/datadog/ci/test_retries/component.rb +37 -7
  36. data/lib/datadog/ci/test_retries/driver/base.rb +5 -0
  37. data/lib/datadog/ci/test_retries/driver/retry_failed.rb +4 -0
  38. data/lib/datadog/ci/test_retries/driver/retry_flaky_fixed.rb +38 -0
  39. data/lib/datadog/ci/test_retries/driver/retry_new.rb +2 -7
  40. data/lib/datadog/ci/test_retries/strategy/retry_flaky_fixed.rb +43 -0
  41. data/lib/datadog/ci/test_retries/strategy/retry_new.rb +4 -46
  42. data/lib/datadog/ci/test_suite.rb +21 -2
  43. data/lib/datadog/ci/test_visibility/capabilities.rb +36 -0
  44. data/lib/datadog/ci/test_visibility/component.rb +70 -2
  45. data/lib/datadog/ci/test_visibility/context.rb +0 -4
  46. data/lib/datadog/ci/{test_retries/unique_tests_client.rb → test_visibility/known_tests.rb} +10 -10
  47. data/lib/datadog/ci/test_visibility/null_component.rb +3 -0
  48. data/lib/datadog/ci/test_visibility/serializers/factories/test_level.rb +1 -1
  49. data/lib/datadog/ci/test_visibility/telemetry.rb +11 -2
  50. data/lib/datadog/ci/test_visibility/transport.rb +29 -3
  51. data/lib/datadog/ci/utils/rum.rb +42 -0
  52. data/lib/datadog/ci/version.rb +1 -1
  53. data/lib/datadog/ci.rb +14 -5
  54. metadata +20 -10
  55. data/lib/datadog/ci/contrib/selenium/rum.rb +0 -43
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da95176899cf1e2427fadba7e177e85a5906c8c8131026e4b6e7fd3ec7ffae91
4
- data.tar.gz: 1e948e2a734e658b9cbff55c9e1d0a57164d422a921124d17e73879a8da96361
3
+ metadata.gz: bc134bf501f298c7803572320d3c82d93b64b0dbfc59b2d8219d42fd5fed24e6
4
+ data.tar.gz: 4714f599fef9eae12cb3dc99dfb17dc0431a9dfee7d9337da9fada542429c6c5
5
5
  SHA512:
6
- metadata.gz: 4bbc47cd1af4024c4822f3c3686f728d50a87b729c8316b3e80648e370fc3c274bcd551644aad0a17203927d2ca08957af400447000ee25485a6f17f1cbaec62
7
- data.tar.gz: f8b0fb90d93076341c88a44d4e08f867318996b350c10a498101d5893de32b70811110b78c093a8ba13b88ea6d53ba011013995fd0a11e5ba61b035d84950063
6
+ metadata.gz: e54fa5b48885accd1c304fca925292470930f6c916e318c5a02eed24989d089e431b99aa56c3eab75f1ed4445c3ab8bd14b1783baa01c32e52bf3d0df5f3813b
7
+ data.tar.gz: 0f42913850d53736f3b058db3c7bea7e2f4cc0c5ccf511545d052afb142967084185075888511887185dbf5b82ee4b6931b7da76f91b91fe0c99760efb1b9574
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.13.0] - 2025-02-25
4
+
5
+ ### Added
6
+
7
+ * Flaky test management support ([#289][])
8
+ * Always request the list of known tests and mark new tests ([#286][])
9
+
10
+ ## [1.12.0] - 2025-01-23
11
+
12
+ ### Added
13
+
14
+ * Add Datadog RUM integration support for browser tests with cuprite driver ([#283][])
15
+
3
16
  ## [1.11.0] - 2025-01-02
4
17
 
5
18
  ### Changed
@@ -380,7 +393,9 @@ Currently test suite level visibility is not used by our instrumentation: it wil
380
393
 
381
394
  - Ruby versions < 2.7 no longer supported ([#8][])
382
395
 
383
- [Unreleased]: https://github.com/DataDog/datadog-ci-rb/compare/v1.11.0...main
396
+ [Unreleased]: https://github.com/DataDog/datadog-ci-rb/compare/v1.13.0...main
397
+ [1.13.0]: https://github.com/DataDog/datadog-ci-rb/compare/v1.12.0...v1.13.0
398
+ [1.12.0]: https://github.com/DataDog/datadog-ci-rb/compare/v1.11.0...v1.12.0
384
399
  [1.11.0]: https://github.com/DataDog/datadog-ci-rb/compare/v1.10.0...v1.11.0
385
400
  [1.10.0]: https://github.com/DataDog/datadog-ci-rb/compare/v1.9.0...v1.10.0
386
401
  [1.9.0]: https://github.com/DataDog/datadog-ci-rb/compare/v1.8.1...v1.9.0
@@ -546,4 +561,7 @@ Currently test suite level visibility is not used by our instrumentation: it wil
546
561
  [#267]: https://github.com/DataDog/datadog-ci-rb/issues/267
547
562
  [#271]: https://github.com/DataDog/datadog-ci-rb/issues/271
548
563
  [#272]: https://github.com/DataDog/datadog-ci-rb/issues/272
549
- [#275]: https://github.com/DataDog/datadog-ci-rb/issues/275
564
+ [#275]: https://github.com/DataDog/datadog-ci-rb/issues/275
565
+ [#283]: https://github.com/DataDog/datadog-ci-rb/issues/283
566
+ [#286]: https://github.com/DataDog/datadog-ci-rb/issues/286
567
+ [#289]: https://github.com/DataDog/datadog-ci-rb/issues/289
@@ -6,14 +6,17 @@ require_relative "../ext/settings"
6
6
  require_relative "../git/tree_uploader"
7
7
  require_relative "../remote/component"
8
8
  require_relative "../remote/library_settings_client"
9
+ require_relative "../test_management/component"
10
+ require_relative "../test_management/null_component"
11
+ require_relative "../test_management/tests_properties"
9
12
  require_relative "../test_optimisation/component"
10
13
  require_relative "../test_optimisation/coverage/transport"
11
14
  require_relative "../test_optimisation/coverage/writer"
12
15
  require_relative "../test_retries/component"
13
16
  require_relative "../test_retries/null_component"
14
- require_relative "../test_retries/unique_tests_client"
15
17
  require_relative "../test_visibility/component"
16
18
  require_relative "../test_visibility/flush"
19
+ require_relative "../test_visibility/known_tests"
17
20
  require_relative "../test_visibility/null_component"
18
21
  require_relative "../test_visibility/serializers/factories/test_level"
19
22
  require_relative "../test_visibility/serializers/factories/test_suite_level"
@@ -30,7 +33,7 @@ module Datadog
30
33
  module Configuration
31
34
  # Adds CI behavior to Datadog trace components
32
35
  module Components
33
- attr_reader :test_visibility, :test_optimisation, :git_tree_upload_worker, :ci_remote, :test_retries
36
+ attr_reader :test_visibility, :test_optimisation, :git_tree_upload_worker, :ci_remote, :test_retries, :test_management
34
37
 
35
38
  def initialize(settings)
36
39
  @test_optimisation = nil
@@ -38,6 +41,7 @@ module Datadog
38
41
  @git_tree_upload_worker = DummyWorker.new
39
42
  @ci_remote = nil
40
43
  @test_retries = TestRetries::NullComponent.new
44
+ @test_management = TestManagement::NullComponent.new
41
45
 
42
46
  # Activate CI mode if enabled
43
47
  if settings.ci.enabled
@@ -58,7 +62,7 @@ module Datadog
58
62
  def activate_ci!(settings)
59
63
  unless settings.tracing.enabled
60
64
  Datadog.logger.error(
61
- "CI visibility requires tracing to be enabled. Disabling CI visibility. " \
65
+ "Test Optimization requires tracing to be enabled. Disabling Test Optimization. " \
62
66
  "NOTE: if you didn't disable tracing intentionally, add `c.tracing.enabled = true` to " \
63
67
  "your Datadog.configure block."
64
68
  )
@@ -111,13 +115,21 @@ module Datadog
111
115
  retry_failed_tests_max_attempts: settings.ci.retry_failed_tests_max_attempts,
112
116
  retry_failed_tests_total_limit: settings.ci.retry_failed_tests_total_limit,
113
117
  retry_new_tests_enabled: settings.ci.retry_new_tests_enabled,
114
- unique_tests_client: build_unique_tests_client(settings, test_visibility_api)
118
+ retry_flaky_fixed_tests_enabled: settings.ci.test_management_enabled,
119
+ retry_flaky_fixed_tests_max_attempts: settings.ci.test_management_attempt_to_fix_retries_count
115
120
  )
121
+
122
+ @test_management = TestManagement::Component.new(
123
+ enabled: settings.ci.test_management_enabled,
124
+ tests_properties_client: TestManagement::TestsProperties.new(api: test_visibility_api)
125
+ )
126
+
116
127
  # @type ivar @test_optimisation: Datadog::CI::TestOptimisation::Component
117
128
  @test_optimisation = build_test_optimisation(settings, test_visibility_api)
118
129
  @test_visibility = TestVisibility::Component.new(
119
130
  test_suite_level_visibility_enabled: !settings.ci.force_test_level_visibility,
120
- logical_test_session_name: settings.ci.test_session_name
131
+ logical_test_session_name: settings.ci.test_session_name,
132
+ known_tests_client: build_known_tests_client(settings, test_visibility_api)
121
133
  )
122
134
  end
123
135
 
@@ -125,7 +137,7 @@ module Datadog
125
137
  if settings.ci.itr_code_coverage_use_single_threaded_mode &&
126
138
  settings.ci.itr_test_impact_analysis_use_allocation_tracing
127
139
  Datadog.logger.warn(
128
- "Intelligent test runner: Single threaded coverage mode is incompatible with allocation tracing. " \
140
+ "Test Impact Analysis: Single threaded coverage mode is incompatible with allocation tracing. " \
129
141
  "Allocation tracing will be disabled. It means that test impact analysis will not be able to detect " \
130
142
  "instantiations of objects in your code, which is important for ActiveRecord models. " \
131
143
  "Please add your app/model folder to the list of tracked files or disable single threaded coverage mode."
@@ -137,7 +149,7 @@ module Datadog
137
149
  if RUBY_VERSION.start_with?("3.2.") && RUBY_VERSION < "3.2.3" &&
138
150
  settings.ci.itr_test_impact_analysis_use_allocation_tracing
139
151
  Datadog.logger.warn(
140
- "Intelligent test runner: Allocation tracing is not supported in Ruby versions 3.2.0, 3.2.1 and 3.2.2 and will be forcibly " \
152
+ "Test Impact Analysis: Allocation tracing is not supported in Ruby versions 3.2.0, 3.2.1 and 3.2.2 and will be forcibly " \
141
153
  "disabled. This is due to a VM bug that can lead to crashes (https://bugs.ruby-lang.org/issues/19482). " \
142
154
  "Please update your Ruby version or add your app/model folder to the list of tracked files." \
143
155
  "Set env variable DD_CIVISIBILITY_ITR_TEST_IMPACT_ANALYSIS_USE_ALLOCATION_TRACING to 0 to disable this warning."
@@ -161,21 +173,21 @@ module Datadog
161
173
  if settings.ci.agentless_mode_enabled
162
174
  check_dd_site(settings)
163
175
 
164
- Datadog.logger.debug("CI visibility configured to use agentless transport")
176
+ Datadog.logger.debug("Test Optimization configured to use agentless transport")
165
177
 
166
178
  api = Transport::Api::Builder.build_agentless_api(settings)
167
179
  if api.nil?
168
180
  Datadog.logger.error do
169
- "DATADOG CONFIGURATION - CI VISIBILITY - ATTENTION - " \
170
- "Agentless mode was enabled but DD_API_KEY is not set: CI visibility is disabled. " \
181
+ "DATADOG CONFIGURATION - TEST OPTIMIZATION - ATTENTION - " \
182
+ "Agentless mode was enabled but DD_API_KEY is not set: Test Optimization is disabled. " \
171
183
  "Please make sure to set valid api key in DD_API_KEY environment variable"
172
184
  end
173
185
 
174
- # Tests are running without CI visibility enabled
186
+ # Tests are running without Test Optimization enabled
175
187
  settings.ci.enabled = false
176
188
  end
177
189
  else
178
- Datadog.logger.debug("CI visibility configured to use agent transport via EVP proxy")
190
+ Datadog.logger.debug("Test Optimization configured to use agent transport via EVP proxy")
179
191
 
180
192
  api = Transport::Api::Builder.build_evp_proxy_api(settings)
181
193
  if api.nil?
@@ -235,8 +247,8 @@ module Datadog
235
247
  )
236
248
  end
237
249
 
238
- def build_unique_tests_client(settings, api)
239
- TestRetries::UniqueTestsClient.new(
250
+ def build_known_tests_client(settings, api)
251
+ TestVisibility::KnownTests.new(
240
252
  api: api,
241
253
  dd_env: settings.env,
242
254
  config_tags: custom_configuration(settings)
@@ -262,7 +274,7 @@ module Datadog
262
274
  return if Ext::Settings::DD_SITE_ALLOWLIST.include?(settings.site)
263
275
 
264
276
  Datadog.logger.warn do
265
- "CI VISIBILITY CONFIGURATION " \
277
+ "TEST OPTIMIZATION CONFIGURATION " \
266
278
  "Agentless mode was enabled but DD_SITE is not set to one of the following: #{Ext::Settings::DD_SITE_ALLOWLIST.join(", ")}. " \
267
279
  "Please make sure to set valid site in DD_SITE environment variable"
268
280
  end
@@ -116,6 +116,18 @@ module Datadog
116
116
  o.default true
117
117
  end
118
118
 
119
+ option :test_management_enabled do |o|
120
+ o.type :bool
121
+ o.env CI::Ext::Settings::ENV_TEST_MANAGEMENT_ENABLED
122
+ o.default true
123
+ end
124
+
125
+ option :test_management_attempt_to_fix_retries_count do |o|
126
+ o.type :int
127
+ o.env CI::Ext::Settings::ENV_TEST_MANAGEMENT_ATTEMPT_TO_FIX_RETRIES
128
+ o.default 20
129
+ end
130
+
119
131
  # internal only
120
132
  option :discard_traces do |o|
121
133
  o.type :bool
@@ -37,8 +37,11 @@ module Datadog
37
37
  end
38
38
 
39
39
  def begin_scenario(test_case)
40
- if Datadog::CI.active_test&.skipped_by_itr?
41
- raise ::Cucumber::Core::Test::Result::Skipped, CI::Ext::Test::ITR_TEST_SKIP_REASON
40
+ datadog_test = Datadog::CI.active_test
41
+
42
+ # special case for cucumber-ruby: we skip quarantined tests, thus for cucumber quarantined is the same as disabled
43
+ if datadog_test&.should_skip? || datadog_test&.quarantined?
44
+ raise ::Cucumber::Core::Test::Result::Skipped, datadog_test.datadog_skip_reason
42
45
  end
43
46
 
44
47
  super
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "datadog/core"
4
+
5
+ require_relative "../ext"
6
+ require_relative "../../settings"
7
+
8
+ require_relative "../../../ext/rum"
9
+
10
+ module Datadog
11
+ module CI
12
+ module Contrib
13
+ module Cuprite
14
+ module Configuration
15
+ # Custom settings for the Cuprite integration
16
+ # @public_api
17
+ class Settings < Datadog::CI::Contrib::Settings
18
+ option :enabled do |o|
19
+ o.type :bool
20
+ o.env Ext::ENV_ENABLED
21
+ o.default true
22
+ end
23
+
24
+ option :rum_flush_wait_millis do |o|
25
+ o.type :int
26
+ o.env CI::Ext::RUM::ENV_RUM_FLUSH_WAIT_MILLIS
27
+ o.default 500
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "script_executor"
4
+ require_relative "../patcher"
5
+
6
+ require_relative "../../ext/rum"
7
+ require_relative "../../ext/test"
8
+ require_relative "../../utils/rum"
9
+
10
+ module Datadog
11
+ module CI
12
+ module Contrib
13
+ module Cuprite
14
+ # instruments Capybara::Cuprite::Driver
15
+ module Driver
16
+ def self.included(base)
17
+ base.prepend(InstanceMethods)
18
+ end
19
+
20
+ module InstanceMethods
21
+ def visit(url)
22
+ result = super
23
+
24
+ return result unless datadog_configuration[:enabled]
25
+
26
+ Datadog.logger.debug("[Cuprite] Navigation to #{url}")
27
+
28
+ # on session reset Capybara navigates to about:blank
29
+ return result if url == "about:blank"
30
+
31
+ active_test = Datadog::CI.active_test
32
+ Datadog.logger.debug("[Cuprite] Active test: #{active_test}")
33
+
34
+ return result unless active_test
35
+
36
+ # Set the test's trace id as a cookie in browser session
37
+ Datadog.logger.debug do
38
+ "[Cuprite] Setting cookie #{CI::Ext::RUM::COOKIE_TEST_EXECUTION_ID} to #{active_test.trace_id}"
39
+ end
40
+ set_cookie(CI::Ext::RUM::COOKIE_TEST_EXECUTION_ID, active_test.trace_id.to_s)
41
+
42
+ # set the test type to browser
43
+ active_test.set_tag(CI::Ext::Test::TAG_TYPE, CI::Ext::Test::Type::BROWSER)
44
+
45
+ # set the tags specific to the browser test
46
+ active_test.set_tag(CI::Ext::Test::TAG_BROWSER_DRIVER, "cuprite")
47
+ active_test.set_tag(CI::Ext::Test::TAG_BROWSER_DRIVER_VERSION, datadog_integration.version)
48
+ active_test.set_tag(CI::Ext::Test::TAG_BROWSER_NAME, browser.options.browser_name || "chrome")
49
+ active_test.set_tag(CI::Ext::Test::TAG_BROWSER_VERSION, browser.version.product)
50
+
51
+ result
52
+ end
53
+
54
+ def reset!
55
+ Datadog.logger.debug("[Cuprite] Driver reset! event")
56
+
57
+ datadog_end_rum_session
58
+
59
+ super
60
+ end
61
+
62
+ def quit
63
+ Datadog.logger.debug("[Cuprite] Driver quit event")
64
+
65
+ datadog_end_rum_session
66
+
67
+ super
68
+ end
69
+
70
+ private
71
+
72
+ def datadog_integration
73
+ CI::Contrib::Instrumentation.fetch_integration(:cuprite)
74
+ end
75
+
76
+ def datadog_configuration
77
+ Datadog.configuration.ci[:cuprite]
78
+ end
79
+
80
+ def datadog_end_rum_session
81
+ return unless datadog_configuration[:enabled]
82
+
83
+ executor = ScriptExecutor.new(browser)
84
+ Utils::RUM.stop_rum_session(executor, rum_flush_wait_millis: datadog_configuration[:rum_flush_wait_millis])
85
+
86
+ Datadog.logger.debug("[Cuprite] Deleting Datadog cookie")
87
+ remove_cookie(CI::Ext::RUM::COOKIE_TEST_EXECUTION_ID)
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datadog
4
+ module CI
5
+ module Contrib
6
+ module Cuprite
7
+ # Cuprite integration constants
8
+ # @public_api
9
+ module Ext
10
+ ENV_ENABLED = "DD_CIVISIBILITY_CUPRITE_ENABLED"
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../integration"
4
+ require_relative "configuration/settings"
5
+ require_relative "patcher"
6
+
7
+ module Datadog
8
+ module CI
9
+ module Contrib
10
+ module Cuprite
11
+ # Description of Cuprite integration
12
+ class Integration < Contrib::Integration
13
+ MINIMUM_VERSION = Gem::Version.new("0.15.0")
14
+
15
+ def version
16
+ Gem.loaded_specs["cuprite"]&.version
17
+ end
18
+
19
+ def loaded?
20
+ !defined?(::Capybara).nil? && !defined?(::Capybara::Cuprite).nil? &&
21
+ !defined?(::Capybara::Cuprite::Driver).nil?
22
+ end
23
+
24
+ def compatible?
25
+ super && version >= MINIMUM_VERSION
26
+ end
27
+
28
+ # additional instrumentations for test libraries are late instrumented on test session start
29
+ def late_instrument?
30
+ true
31
+ end
32
+
33
+ def new_configuration
34
+ Configuration::Settings.new
35
+ end
36
+
37
+ def patcher
38
+ Patcher
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../patcher"
4
+
5
+ require_relative "driver"
6
+
7
+ module Datadog
8
+ module CI
9
+ module Contrib
10
+ module Cuprite
11
+ # Patcher enables patching of 'Capybara::Cuprite::Driver' class.
12
+ module Patcher
13
+ include Datadog::CI::Contrib::Patcher
14
+
15
+ module_function
16
+
17
+ def patch
18
+ ::Capybara::Cuprite::Driver.include(Driver)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../ext/rum"
4
+
5
+ module Datadog
6
+ module CI
7
+ module Contrib
8
+ module Cuprite
9
+ class ScriptExecutor
10
+ # Ferrum::Browser requires a JS script to be wrapped in a function() { ... } block
11
+ WRAPPED_SCRIPTS = {
12
+ CI::Ext::RUM::SCRIPT_IS_RUM_ACTIVE => "function() { #{CI::Ext::RUM::SCRIPT_IS_RUM_ACTIVE}; }",
13
+ CI::Ext::RUM::SCRIPT_STOP_RUM_SESSION => <<~JS
14
+ function() {
15
+ #{CI::Ext::RUM::SCRIPT_STOP_RUM_SESSION}
16
+ }
17
+ JS
18
+ }.freeze
19
+
20
+ def initialize(ferrum_browser)
21
+ @ferrum_browser = ferrum_browser
22
+ end
23
+
24
+ def execute_script(script)
25
+ script = WRAPPED_SCRIPTS.fetch(script, script)
26
+ @ferrum_browser.evaluate_func(script)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -44,7 +44,7 @@ module Datadog
44
44
  service: datadog_configuration[:service_name]
45
45
  )
46
46
  test_span&.itr_unskippable! if self.class.dd_suite_unskippable? || self.class.dd_test_unskippable?(name)
47
- skip(CI::Ext::Test::ITR_TEST_SKIP_REASON) if test_span&.skipped_by_itr?
47
+ skip(test_span&.datadog_skip_reason) if test_span&.should_skip?
48
48
  end
49
49
 
50
50
  def after_teardown
@@ -53,8 +53,8 @@ module Datadog
53
53
 
54
54
  finish_with_result(test_span, result_code)
55
55
 
56
- # remove failures if test passed at least once on retries
57
- self.failures = [] if test_span.any_retry_passed?
56
+ # remove failures if test passed at least once on retries or quarantined
57
+ self.failures = [] if test_span.should_ignore_failures?
58
58
 
59
59
  if Helpers.parallel?(self.class)
60
60
  finish_with_result(test_span.test_suite, result_code)
@@ -41,7 +41,7 @@ module Datadog
41
41
  ) do |test_span|
42
42
  test_span&.itr_unskippable! if datadog_unskippable?
43
43
 
44
- metadata[:skip] = CI::Ext::Test::ITR_TEST_SKIP_REASON if test_span&.skipped_by_itr?
44
+ metadata[:skip] = test_span&.datadog_skip_reason if test_span&.should_skip?
45
45
 
46
46
  # before each run remove any previous exception
47
47
  @exception = nil
@@ -58,8 +58,8 @@ module Datadog
58
58
  test_span&.passed!
59
59
  when :failed
60
60
  test_span&.failed!(exception: execution_result.exception)
61
- # if any of the retries passed, we don't fail the test run
62
- @exception = nil if test_span&.any_retry_passed?
61
+ # if any of the retries passed or test is quarantined, we don't fail the test run
62
+ @exception = nil if test_span&.should_ignore_failures?
63
63
  else
64
64
  # :pending or nil
65
65
  test_span&.skipped!(
@@ -2,9 +2,9 @@
2
2
 
3
3
  require_relative "../patcher"
4
4
 
5
- require_relative "ext"
6
- require_relative "rum"
5
+ require_relative "../../ext/rum"
7
6
  require_relative "../../ext/test"
7
+ require_relative "../../utils/rum"
8
8
 
9
9
  module Datadog
10
10
  module CI
@@ -22,10 +22,10 @@ module Datadog
22
22
 
23
23
  Datadog.logger.debug("[Selenium] Capybara session reset event")
24
24
 
25
- RUM.stop_rum_session(@browser)
25
+ Utils::RUM.stop_rum_session(@browser, rum_flush_wait_millis: datadog_configuration[:rum_flush_wait_millis])
26
26
 
27
27
  Datadog.logger.debug("[Selenium] RUM session stopped, deleting cookie")
28
- @browser.manage.delete_cookie(Ext::COOKIE_TEST_EXECUTION_ID)
28
+ @browser.manage.delete_cookie(CI::Ext::RUM::COOKIE_TEST_EXECUTION_ID)
29
29
  rescue ::Selenium::WebDriver::Error::WebDriverError => e
30
30
  Datadog.logger.debug("[Selenium] Error while resetting Capybara session: #{e.message}")
31
31
  ensure
@@ -5,6 +5,8 @@ require "datadog/core"
5
5
  require_relative "../ext"
6
6
  require_relative "../../settings"
7
7
 
8
+ require_relative "../../../ext/rum"
9
+
8
10
  module Datadog
9
11
  module CI
10
12
  module Contrib
@@ -21,7 +23,7 @@ module Datadog
21
23
 
22
24
  option :rum_flush_wait_millis do |o|
23
25
  o.type :int
24
- o.env Ext::ENV_RUM_FLUSH_WAIT_MILLIS
26
+ o.env CI::Ext::RUM::ENV_RUM_FLUSH_WAIT_MILLIS
25
27
  o.default 500
26
28
  end
27
29
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  require_relative "../patcher"
4
4
 
5
- require_relative "ext"
6
- require_relative "rum"
5
+ require_relative "../../utils/rum"
6
+ require_relative "../../ext/rum"
7
7
  require_relative "../../ext/test"
8
8
 
9
9
  module Datadog
@@ -22,10 +22,10 @@ module Datadog
22
22
 
23
23
  Datadog.logger.debug("[Selenium] Driver quit event")
24
24
 
25
- RUM.stop_rum_session(@bridge)
25
+ Utils::RUM.stop_rum_session(@bridge, rum_flush_wait_millis: datadog_configuration[:rum_flush_wait_millis])
26
26
 
27
27
  Datadog.logger.debug("[Selenium] RUM session stopped, deleting cookie")
28
- @bridge.manage.delete_cookie(Ext::COOKIE_TEST_EXECUTION_ID)
28
+ @bridge.manage.delete_cookie(CI::Ext::RUM::COOKIE_TEST_EXECUTION_ID)
29
29
  rescue ::Selenium::WebDriver::Error::WebDriverError => e
30
30
  Datadog.logger.debug("[Selenium] Error while quitting Selenium driver: #{e.message}")
31
31
  ensure
@@ -8,21 +8,6 @@ module Datadog
8
8
  # @public_api
9
9
  module Ext
10
10
  ENV_ENABLED = "DD_CIVISIBILITY_SELENIUM_ENABLED"
11
- ENV_RUM_FLUSH_WAIT_MILLIS = "DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS"
12
-
13
- COOKIE_TEST_EXECUTION_ID = "datadog-ci-visibility-test-execution-id"
14
-
15
- SCRIPT_IS_RUM_ACTIVE = <<~JS
16
- return !!window.DD_RUM
17
- JS
18
- SCRIPT_STOP_RUM_SESSION = <<~JS
19
- if (window.DD_RUM && window.DD_RUM.stopSession) {
20
- window.DD_RUM.stopSession();
21
- return true;
22
- } else {
23
- return false;
24
- }
25
- JS
26
11
  end
27
12
  end
28
13
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative "../patcher"
4
4
 
5
- require_relative "ext"
5
+ require_relative "../../ext/rum"
6
6
  require_relative "../../ext/test"
7
7
 
8
8
  module Datadog
@@ -32,7 +32,7 @@ module Datadog
32
32
  return result unless active_test
33
33
 
34
34
  # Set the test's trace id as a cookie in browser session
35
- cookie_hash = {name: Ext::COOKIE_TEST_EXECUTION_ID, value: active_test.trace_id.to_s}
35
+ cookie_hash = {name: CI::Ext::RUM::COOKIE_TEST_EXECUTION_ID, value: active_test.trace_id.to_s}
36
36
  Datadog.logger.debug { "[Selenium] Setting cookie: #{cookie_hash}" }
37
37
  @bridge.manage.add_cookie(cookie_hash)
38
38
 
@@ -3,7 +3,7 @@
3
3
  module Datadog
4
4
  module CI
5
5
  module Ext
6
- # Defines span types for CI visibility
6
+ # Defines span types for Test Optimization
7
7
  # @public_api
8
8
  module AppTypes
9
9
  TYPE_TEST = "test"
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "json"
4
4
 
5
+ require "datadog/core/telemetry/logging"
5
6
  require "datadog/core/utils/url"
6
7
 
7
8
  require_relative "base"
@@ -96,6 +97,8 @@ module Datadog
96
97
  result
97
98
  rescue => e
98
99
  Datadog.logger.error("Failed to extract additional tags from GitHub Actions: #{e}")
100
+ Core::Telemetry::Logger.report(e, description: "Failed to extract additional tags from GitHub Actions")
101
+
99
102
  {}
100
103
  end
101
104