datadog-ci 0.3.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +89 -1
  3. data/README.md +57 -34
  4. data/lib/datadog/ci/concurrent_span.rb +59 -0
  5. data/lib/datadog/ci/configuration/components.rb +40 -1
  6. data/lib/datadog/ci/configuration/extensions.rb +21 -0
  7. data/lib/datadog/ci/configuration/settings.rb +7 -1
  8. data/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +12 -1
  9. data/lib/datadog/ci/contrib/cucumber/formatter.rb +22 -29
  10. data/lib/datadog/ci/contrib/minitest/configuration/settings.rb +10 -1
  11. data/lib/datadog/ci/contrib/minitest/hooks.rb +15 -25
  12. data/lib/datadog/ci/contrib/rspec/configuration/settings.rb +10 -1
  13. data/lib/datadog/ci/contrib/rspec/example.rb +13 -18
  14. data/lib/datadog/ci/contrib/settings.rb +2 -0
  15. data/lib/datadog/ci/ext/app_types.rb +5 -0
  16. data/lib/datadog/ci/ext/environment/extractor.rb +5 -10
  17. data/lib/datadog/ci/ext/environment/providers/github_actions.rb +13 -4
  18. data/lib/datadog/ci/ext/settings.rb +11 -0
  19. data/lib/datadog/ci/ext/test.rb +12 -1
  20. data/lib/datadog/ci/null_span.rb +63 -0
  21. data/lib/datadog/ci/span.rb +117 -0
  22. data/lib/datadog/ci/test.rb +25 -0
  23. data/lib/datadog/ci/test_module.rb +23 -0
  24. data/lib/datadog/ci/test_session.rb +36 -0
  25. data/lib/datadog/ci/test_suite.rb +25 -0
  26. data/lib/datadog/ci/test_visibility/context/global.rb +82 -0
  27. data/lib/datadog/ci/test_visibility/context/local.rb +52 -0
  28. data/lib/datadog/ci/test_visibility/recorder.rb +293 -0
  29. data/lib/datadog/ci/test_visibility/serializers/base.rb +100 -12
  30. data/lib/datadog/ci/test_visibility/serializers/factories/test_suite_level.rb +37 -0
  31. data/lib/datadog/ci/test_visibility/serializers/span.rb +2 -16
  32. data/lib/datadog/ci/test_visibility/serializers/test_module.rb +46 -0
  33. data/lib/datadog/ci/test_visibility/serializers/test_session.rb +46 -0
  34. data/lib/datadog/ci/test_visibility/serializers/test_suite.rb +46 -0
  35. data/lib/datadog/ci/test_visibility/serializers/test_v1.rb +3 -17
  36. data/lib/datadog/ci/test_visibility/serializers/test_v2.rb +38 -0
  37. data/lib/datadog/ci/test_visibility/transport.rb +4 -4
  38. data/lib/datadog/ci/utils/test_run.rb +15 -0
  39. data/lib/datadog/ci/utils/url.rb +15 -0
  40. data/lib/datadog/ci/version.rb +2 -2
  41. data/lib/datadog/ci.rb +378 -7
  42. data/sig/datadog/ci/concurrent_span.rbs +23 -0
  43. data/sig/datadog/ci/configuration/components.rbs +6 -0
  44. data/sig/datadog/ci/configuration/extensions.rbs +9 -0
  45. data/sig/datadog/ci/ext/app_types.rbs +6 -1
  46. data/sig/datadog/ci/ext/environment/extractor.rbs +0 -2
  47. data/sig/datadog/ci/ext/environment/providers/github_actions.rbs +5 -0
  48. data/sig/datadog/ci/ext/settings.rbs +3 -0
  49. data/sig/datadog/ci/ext/test.rbs +15 -0
  50. data/sig/datadog/ci/null_span.rbs +37 -0
  51. data/sig/datadog/ci/span.rbs +39 -0
  52. data/sig/datadog/ci/test.rbs +7 -0
  53. data/sig/datadog/ci/test_module.rbs +6 -0
  54. data/sig/datadog/ci/test_session.rbs +9 -0
  55. data/sig/datadog/ci/test_suite.rbs +6 -0
  56. data/sig/datadog/ci/test_visibility/context/global.rbs +39 -0
  57. data/sig/datadog/ci/test_visibility/context/local.rbs +23 -0
  58. data/sig/datadog/ci/test_visibility/recorder.rbs +85 -0
  59. data/sig/datadog/ci/test_visibility/serializers/base.rbs +26 -5
  60. data/sig/datadog/ci/test_visibility/serializers/factories/test_suite_level.rbs +13 -0
  61. data/sig/datadog/ci/test_visibility/serializers/test_module.rbs +26 -0
  62. data/sig/datadog/ci/test_visibility/serializers/test_session.rbs +26 -0
  63. data/sig/datadog/ci/test_visibility/serializers/test_suite.rbs +26 -0
  64. data/sig/datadog/ci/test_visibility/serializers/test_v1.rbs +1 -1
  65. data/sig/datadog/ci/test_visibility/serializers/test_v2.rbs +25 -0
  66. data/sig/datadog/ci/test_visibility/transport.rbs +3 -3
  67. data/sig/datadog/ci/utils/test_run.rbs +11 -0
  68. data/sig/datadog/ci/utils/url.rbs +9 -0
  69. data/sig/datadog/ci.rbs +31 -3
  70. metadata +38 -6
  71. data/lib/datadog/ci/extensions.rb +0 -19
  72. data/lib/datadog/ci/recorder.rb +0 -83
  73. data/sig/datadog/ci/extensions.rbs +0 -7
  74. data/sig/datadog/ci/recorder.rbs +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce3b4502404f6faa6b05421763ced6582071c9ad025937219b59ba8c63c39175
4
- data.tar.gz: 7a341aa75161299cb04a29f745e172ef5ca4fec3a24f536ec96e08119de11a97
3
+ metadata.gz: 85bb3584dc8081e8f6e8531d2a600e3948f4f9ea23d551dd99df0eab9daf2a3c
4
+ data.tar.gz: b6f686d49d3dbb1695c0f6e20b434b77648a118c32e1691f4a0f30b13d38dc62
5
5
  SHA512:
6
- metadata.gz: 6058fbf497f43040a588018a2104055a303849d5616d063412dae4dab1e5247098e9ecd1b0b718776a51bc090f137d2bcf19cc78d252c7968c9cd6e4723ad902
7
- data.tar.gz: 3c8d8eb9a34266a690a0dd5103d344b80df5175c703a414b1bc8255dc3c2732d723960e786765f2686fdcaaff5f009b675942c5e39dbd4a6fc9e58a38653051e
6
+ metadata.gz: 8e8ae716ea7c7408c59c11efa5a3bc30e0767a02c659e231f1cec2a02d5494d451c1e2b43c7c16240cbe7c9418f004ead32faa09b08c83bcd878156fa1062ae9
7
+ data.tar.gz: 15bdfb45e32660356fcc4c5726c4a640c78cfc2d5007807623f532a0b7c321f0b11a32d0a75f571a64ae263159d4b86b0a750dda5d7e8a5c33f9c110bf7682a0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,70 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.1] - 2023-12-11
4
+
5
+ ### Fixed
6
+
7
+ * do not collect environment tags when CI is not enabled ([#87][])
8
+
9
+ ### Changed
10
+
11
+ * Move private classes and modules deeper in module hierarchy ([#85][])
12
+ * update appraisal dependencies ([#84][])
13
+
14
+ ## [0.5.0] - 2023-12-06
15
+
16
+ ### Test suite level visibility
17
+
18
+ This release includes experimental manual API for [test suite level visibility](https://docs.datadoghq.com/continuous_integration/explorer/?tab=testruns#sessions) in Ruby.
19
+
20
+ Currently test suite level visibility is not used by our instrumentation: it will be released in v0.6.
21
+
22
+ ### Added
23
+
24
+ * Test suite level visibility: add test session public API ([#72][])
25
+ * Test suite level visibility: test module support ([#76][])
26
+ * Test suite level visibility: test suites support ([#77][])
27
+ * add YARD documentation ([#82][])
28
+ * support validation errors for CI spans ([#78][])
29
+
30
+ ### Changed
31
+
32
+ * Validate DD_SITE variable ([#79][])
33
+ * Document how to use WebMock with datadog-ci ([#80][])
34
+
35
+ ### Fixed
36
+
37
+ * Datadog::CI.trace_test always starts a new trace ([#74][])
38
+ * Skip tracing when CI mode disabled and manual API is used ([#75][])
39
+
40
+ ### Removed
41
+
42
+ * Deprecate operation name setting, change service_name to service in public API ([#81][])
43
+
44
+ ## [0.4.1] - 2023-11-22
45
+
46
+ ### Fixed
47
+
48
+ * disable 128-bit trace id generation in CI mode ([#70][])
49
+
50
+ ## [0.4.0] - 2023-11-21
51
+
52
+ ### Added
53
+
54
+ * Public API for manual test instrumentation ([#64][]) ([#61][])
55
+
56
+ ### Changed
57
+
58
+ * fix tracing instrumentation example in readme ([#60][])
59
+
60
+ ### Fixed
61
+
62
+ * Remove user credentials from ssh URLs and from GITHUB_REPO_URL environment variable ([#66][])
63
+
64
+ ### Removed
65
+
66
+ * Remove _dd.measured tag from spans ([#65][])
67
+
3
68
  ## [0.3.0] - 2023-10-25
4
69
 
5
70
  ### Added
@@ -47,7 +112,11 @@
47
112
 
48
113
  * Ruby versions < 2.7 no longer supported ([#8][])
49
114
 
50
- [Unreleased]: https://github.com/DataDog/datadog-ci-rb/compare/v0.3.0...main
115
+ [Unreleased]: https://github.com/DataDog/datadog-ci-rb/compare/v0.5.1...main
116
+ [0.5.1]: https://github.com/DataDog/datadog-ci-rb/compare/v0.5.0...v0.5.1
117
+ [0.5.0]: https://github.com/DataDog/datadog-ci-rb/compare/v0.4.1...v0.5.0
118
+ [0.4.1]: https://github.com/DataDog/datadog-ci-rb/compare/v0.4.0...v0.4.1
119
+ [0.4.0]: https://github.com/DataDog/datadog-ci-rb/compare/v0.3.0...v0.4.0
51
120
  [0.3.0]: https://github.com/DataDog/datadog-ci-rb/compare/v0.2.0...v0.3.0
52
121
  [0.2.0]: https://github.com/DataDog/datadog-ci-rb/compare/v0.1.1...v0.2.0
53
122
  [0.1.1]: https://github.com/DataDog/datadog-ci-rb/compare/v0.1.0...v0.1.1
@@ -66,3 +135,22 @@
66
135
  [#49]: https://github.com/DataDog/datadog-ci-rb/issues/49
67
136
  [#51]: https://github.com/DataDog/datadog-ci-rb/issues/51
68
137
  [#54]: https://github.com/DataDog/datadog-ci-rb/issues/54
138
+ [#60]: https://github.com/DataDog/datadog-ci-rb/issues/60
139
+ [#61]: https://github.com/DataDog/datadog-ci-rb/issues/61
140
+ [#64]: https://github.com/DataDog/datadog-ci-rb/issues/64
141
+ [#65]: https://github.com/DataDog/datadog-ci-rb/issues/65
142
+ [#66]: https://github.com/DataDog/datadog-ci-rb/issues/66
143
+ [#70]: https://github.com/DataDog/datadog-ci-rb/issues/70
144
+ [#72]: https://github.com/DataDog/datadog-ci-rb/issues/72
145
+ [#74]: https://github.com/DataDog/datadog-ci-rb/issues/74
146
+ [#75]: https://github.com/DataDog/datadog-ci-rb/issues/75
147
+ [#76]: https://github.com/DataDog/datadog-ci-rb/issues/76
148
+ [#77]: https://github.com/DataDog/datadog-ci-rb/issues/77
149
+ [#78]: https://github.com/DataDog/datadog-ci-rb/issues/78
150
+ [#79]: https://github.com/DataDog/datadog-ci-rb/issues/79
151
+ [#80]: https://github.com/DataDog/datadog-ci-rb/issues/80
152
+ [#81]: https://github.com/DataDog/datadog-ci-rb/issues/81
153
+ [#82]: https://github.com/DataDog/datadog-ci-rb/issues/82
154
+ [#84]: https://github.com/DataDog/datadog-ci-rb/issues/84
155
+ [#85]: https://github.com/DataDog/datadog-ci-rb/issues/85
156
+ [#87]: https://github.com/DataDog/datadog-ci-rb/issues/87
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Datadog CI Visibility for Ruby
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/datadog-ci.svg)](https://badge.fury.io/rb/datadog-ci)
4
+ [![YARD documentation](https://img.shields.io/badge/YARD-documentation-blue)](https://datadoghq.dev/datadog-ci-rb/)
4
5
  [![codecov](https://codecov.io/gh/DataDog/datadog-ci-rb/branch/main/graph/badge.svg)](https://app.codecov.io/gh/DataDog/datadog-ci-rb/branch/main)
5
6
  [![CircleCI](https://dl.circleci.com/status-badge/img/gh/DataDog/datadog-ci-rb/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/DataDog/datadog-ci-rb/tree/main)
6
7
 
@@ -30,18 +31,18 @@ To activate `RSpec` integration, add this to the `spec_helper.rb` file:
30
31
  require 'rspec'
31
32
  require 'datadog/ci'
32
33
 
33
- Datadog.configure do |c|
34
- # Only activates test instrumentation on CI
35
- c.tracing.enabled = (ENV["DD_ENV"] == "ci")
36
-
37
- # Configures the tracer to ensure results delivery
38
- c.ci.enabled = true
34
+ # Only activates test instrumentation on CI
35
+ if ENV["DD_ENV"] == "ci"
36
+ Datadog.configure do |c|
37
+ # Configures the tracer to ensure results delivery
38
+ c.ci.enabled = true
39
39
 
40
- # The name of the service or library under test
41
- c.service = 'my-ruby-app'
40
+ # The name of the service or library under test
41
+ c.service = 'my-ruby-app'
42
42
 
43
- # Enables the RSpec instrumentation
44
- c.ci.instrument :rspec, **options
43
+ # Enables the RSpec instrumentation
44
+ c.ci.instrument :rspec, **options
45
+ end
45
46
  end
46
47
  ```
47
48
 
@@ -51,7 +52,7 @@ end
51
52
  | --- | ----------- | ------- |
52
53
  | `enabled` | Defines whether RSpec tests should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` |
53
54
  | `service_name` | Service name used for `rspec` instrumentation. | `'rspec'` |
54
- | `operation_name` | Operation name used for `rspec` instrumentation. Useful if you want rename automatic trace metrics e.g. `trace.#{operation_name}.errors`. | `'rspec.example'` |
55
+ | `operation_name` | *DEPRECATED, to be removed in 1.0* Operation name used for `rspec` instrumentation (has no effect in agentless mode or when using newer agent versions). | `'rspec.example'` |
55
56
 
56
57
  ### Minitest
57
58
 
@@ -63,18 +64,18 @@ To activate your integration, use the `Datadog.configure` method:
63
64
  require 'minitest'
64
65
  require 'datadog/ci'
65
66
 
67
+ # Only activates test instrumentation on CI
68
+ if ENV["DD_ENV"] == "ci"
66
69
  # Configure default Minitest integration
67
- Datadog.configure do |c|
68
- # Only activates test instrumentation on CI
69
- c.tracing.enabled = (ENV["DD_ENV"] == "ci")
70
-
71
- # Configures the tracer to ensure results delivery
72
- c.ci.enabled = true
70
+ Datadog.configure do |c|
71
+ # Configures the tracer to ensure results delivery
72
+ c.ci.enabled = true
73
73
 
74
- # The name of the service or library under test
75
- c.service = 'my-ruby-app'
74
+ # The name of the service or library under test
75
+ c.service = 'my-ruby-app'
76
76
 
77
- c.ci.instrument :minitest, **options
77
+ c.ci.instrument :minitest, **options
78
+ end
78
79
  end
79
80
  ```
80
81
 
@@ -84,7 +85,7 @@ end
84
85
  | --- | ----------- | ------- |
85
86
  | `enabled` | Defines whether Minitest tests should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` |
86
87
  | `service_name` | Service name used for `minitest` instrumentation. | `'minitest'` |
87
- | `operation_name` | Operation name used for `minitest` instrumentation. Useful if you want rename automatic trace metrics e.g. `trace.#{operation_name}.errors`. | `'minitest.test'` |
88
+ | `operation_name` | *DEPRECATED, to be removed in 1.0* Operation name used for `minitest` instrumentation (has no effect in agentless mode or when using newer agent versions). | `'minitest.test'` |
88
89
 
89
90
  ### Cucumber
90
91
 
@@ -94,18 +95,18 @@ Activate `Cucumber` integration with configuration
94
95
  require 'cucumber'
95
96
  require 'datadog/ci'
96
97
 
97
- Datadog.configure do |c|
98
- # Only activates test instrumentation on CI
99
- c.tracing.enabled = (ENV["DD_ENV"] == "ci")
100
-
101
- # Configures the tracer to ensure results delivery
102
- c.ci.enabled = true
98
+ # Only activates test instrumentation on CI
99
+ if ENV["DD_ENV"] == "ci"
100
+ Datadog.configure do |c|
101
+ # Configures the tracer to ensure results delivery
102
+ c.ci.enabled = true
103
103
 
104
- # The name of the service or library under test
105
- c.service = 'my-ruby-app'
104
+ # The name of the service or library under test
105
+ c.service = 'my-ruby-app'
106
106
 
107
- # Enables the Cucumber instrumentation
108
- c.ci.instrument :cucumber, **options
107
+ # Enables the Cucumber instrumentation
108
+ c.ci.instrument :cucumber, **options
109
+ end
109
110
  end
110
111
  ```
111
112
 
@@ -115,7 +116,7 @@ end
115
116
  | --- | ----------- | ------- |
116
117
  | `enabled` | Defines whether Cucumber tests should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` |
117
118
  | `service_name` | Service name used for `cucumber` instrumentation. | `'cucumber'` |
118
- | `operation_name` | Operation name used for `cucumber` instrumentation. Useful if you want rename automatic trace metrics e.g. `trace.#{operation_name}.errors`. | `'cucumber.test'` |
119
+ | `operation_name` | *DEPRECATED, to be removed in 1.0* Operation name used for `cucumber` instrumentation (has no effect in agentless mode or when using newer agent versions). | `'cucumber.test'` |
119
120
 
120
121
  ## Agentless mode
121
122
 
@@ -145,8 +146,8 @@ In order to achieve this you can configure ddtrace instrumentations in your conf
145
146
  ```ruby
146
147
  Datadog.configure do |c|
147
148
  # ... ci configs and instrumentation here ...
148
- c.instrument :redis
149
- c.instrument :pg
149
+ c.tracing.instrument :redis
150
+ c.tracing.instrument :pg
150
151
  end
151
152
  ```
152
153
 
@@ -161,6 +162,28 @@ they will **not** show up in Datadog APM.
161
162
 
162
163
  For the full list of available instrumentations see [ddtrace documentation](https://github.com/DataDog/dd-trace-rb/blob/master/docs/GettingStarted.md)
163
164
 
165
+ ### WebMock
166
+
167
+ [WebMock](https://github.com/bblimke/webmock)
168
+ is a popular Ruby library that stubs HTTP requests when running tests.
169
+ By default it fails when used together with datadog-ci as traces are being sent
170
+ to Datadog via HTTP calls.
171
+
172
+ In order to allow HTTP connections for Datadog backend you would need to configure
173
+ Webmock accordingly.
174
+
175
+ ```ruby
176
+ # when using agentless mode
177
+ # note to use the correct datadog site (e.g. datadoghq.eu, etc)
178
+ WebMock.disable_net_connect!(:allow => "citestcycle-intake.datadoghq.com")
179
+
180
+ # when using agent
181
+ WebMock.disable_net_connect!(:allow_localhost => true)
182
+
183
+ # or for more granular setting set your agent URL
184
+ WebMock.disable_net_connect!(:allow => "localhost:8126")
185
+ ```
186
+
164
187
  ### Disabling startup logs
165
188
 
166
189
  Startup logs produce a report of tracing state when the application is initially configured.
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "span"
4
+
5
+ module Datadog
6
+ module CI
7
+ # Represents a single part of a test run that can be safely shared between threads.
8
+ # Examples of shared objects are: TestSession, TestModule, TestSpan.
9
+ #
10
+ # @public_api
11
+ class ConcurrentSpan < Span
12
+ def initialize(tracer_span)
13
+ super
14
+
15
+ @mutex = Mutex.new
16
+ end
17
+
18
+ # Gets tag value by key. This method is thread-safe.
19
+ # @param [String] key the key of the tag.
20
+ # @return [String] the value of the tag.
21
+ def get_tag(key)
22
+ synchronize { super }
23
+ end
24
+
25
+ # Sets tag value by key. This method is thread-safe.
26
+ # @param [String] key the key of the tag.
27
+ # @param [String] value the value of the tag.
28
+ # @return [void]
29
+ def set_tag(key, value)
30
+ synchronize { super }
31
+ end
32
+
33
+ # Sets metric value by key. This method is thread-safe.
34
+ # @param [String] key the key of the metric.
35
+ # @param [Numeric] value the value of the metric.
36
+ # @return [void]
37
+ def set_metric(key, value)
38
+ synchronize { super }
39
+ end
40
+
41
+ # Finishes the span. This method is thread-safe.
42
+ # @return [void]
43
+ def finish
44
+ synchronize { super }
45
+ end
46
+
47
+ # Sets multiple tags at once. This method is thread-safe.
48
+ # @param [Hash[String, String]] tags the tags to set.
49
+ # @return [void]
50
+ def set_tags(tags)
51
+ synchronize { super }
52
+ end
53
+
54
+ def synchronize
55
+ @mutex.synchronize { yield }
56
+ end
57
+ end
58
+ end
59
+ end
@@ -4,7 +4,11 @@ require "datadog/core/configuration/agent_settings_resolver"
4
4
  require "datadog/core/remote/negotiation"
5
5
 
6
6
  require_relative "../ext/transport"
7
+ require_relative "../ext/settings"
7
8
  require_relative "../test_visibility/flush"
9
+ require_relative "../test_visibility/recorder"
10
+ require_relative "../test_visibility/serializers/factories/test_level"
11
+ require_relative "../test_visibility/serializers/factories/test_suite_level"
8
12
  require_relative "../test_visibility/transport"
9
13
  require_relative "../transport/api/builder"
10
14
 
@@ -13,10 +17,17 @@ module Datadog
13
17
  module Configuration
14
18
  # Adds CI behavior to Datadog trace components
15
19
  module Components
20
+ attr_reader :ci_recorder
21
+
16
22
  def initialize(settings)
17
23
  # Activate CI mode if enabled
18
24
  activate_ci!(settings) if settings.ci.enabled
19
25
 
26
+ @ci_recorder = TestVisibility::Recorder.new(
27
+ enabled: settings.ci.enabled,
28
+ test_suite_level_visibility_enabled: settings.ci.experimental_test_suite_level_visibility_enabled
29
+ )
30
+
20
31
  # Initialize normally
21
32
  super
22
33
  end
@@ -26,9 +37,12 @@ module Datadog
26
37
  agent_settings = Datadog::Core::Configuration::AgentSettingsResolver.call(settings)
27
38
 
28
39
  if settings.ci.agentless_mode_enabled
40
+ check_dd_site(settings)
29
41
  test_visibility_transport = build_agentless_transport(settings)
30
42
  elsif can_use_evp_proxy?(settings, agent_settings)
31
43
  test_visibility_transport = build_evp_proxy_transport(settings, agent_settings)
44
+ else
45
+ settings.ci.experimental_test_suite_level_visibility_enabled = false
32
46
  end
33
47
 
34
48
  # Deactivate telemetry
@@ -37,11 +51,15 @@ module Datadog
37
51
  # Deactivate remote configuration
38
52
  settings.remote.enabled = false
39
53
 
54
+ # do not use 128-bit trace ids for CI visibility
55
+ # they are used for OTEL compatibility in Datadog tracer
56
+ settings.tracing.trace_id_128_bit_generation_enabled = false
57
+
40
58
  # Activate underlying tracing test mode
41
59
  settings.tracing.test_mode.enabled = true
42
60
 
43
61
  # Choose user defined TraceFlush or default to CI TraceFlush
44
- settings.tracing.test_mode.trace_flush = settings.ci.trace_flush || CI::TestVisibility::Flush::Finished.new
62
+ settings.tracing.test_mode.trace_flush = settings.ci.trace_flush || CI::TestVisibility::Flush::Partial.new
45
63
 
46
64
  writer_options = settings.ci.writer_options
47
65
  if test_visibility_transport
@@ -80,6 +98,7 @@ module Datadog
80
98
 
81
99
  Datadog::CI::TestVisibility::Transport.new(
82
100
  api: Transport::Api::Builder.build_ci_test_cycle_api(settings),
101
+ serializers_factory: serializers_factory(settings),
83
102
  dd_env: settings.env
84
103
  )
85
104
  end
@@ -90,9 +109,29 @@ module Datadog
90
109
 
91
110
  Datadog::CI::TestVisibility::Transport.new(
92
111
  api: Transport::Api::Builder.build_evp_proxy_api(agent_settings),
112
+ serializers_factory: serializers_factory(settings),
93
113
  dd_env: settings.env
94
114
  )
95
115
  end
116
+
117
+ def serializers_factory(settings)
118
+ if settings.ci.experimental_test_suite_level_visibility_enabled
119
+ Datadog::CI::TestVisibility::Serializers::Factories::TestSuiteLevel
120
+ else
121
+ Datadog::CI::TestVisibility::Serializers::Factories::TestLevel
122
+ end
123
+ end
124
+
125
+ def check_dd_site(settings)
126
+ return if settings.site.nil?
127
+ return if Ext::Settings::DD_SITE_ALLOWLIST.include?(settings.site)
128
+
129
+ Datadog.logger.warn(
130
+ "CI VISIBILITY CONFIGURATION " \
131
+ "Agentless mode was enabled but DD_SITE is not set to one of the following: #{Ext::Settings::DD_SITE_ALLOWLIST.join(", ")}. " \
132
+ "Please make sure to set valid site in DD_SITE environment variable"
133
+ )
134
+ end
96
135
  end
97
136
  end
98
137
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "datadog/core/configuration/settings"
4
+ require "datadog/core/configuration/components"
5
+
6
+ require_relative "settings"
7
+ require_relative "components"
8
+
9
+ module Datadog
10
+ module CI
11
+ module Configuration
12
+ # Extends Datadog tracing with CI features
13
+ module Extensions
14
+ def self.activate!
15
+ Core::Configuration::Settings.extend(CI::Configuration::Settings)
16
+ Core::Configuration::Components.prepend(CI::Configuration::Components)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -34,6 +34,12 @@ module Datadog
34
34
  o.env CI::Ext::Settings::ENV_AGENTLESS_URL
35
35
  end
36
36
 
37
+ option :experimental_test_suite_level_visibility_enabled do |o|
38
+ o.type :bool
39
+ o.env CI::Ext::Settings::ENV_EXPERIMENTAL_TEST_SUITE_LEVEL_VISIBILITY_ENABLED
40
+ o.default false
41
+ end
42
+
37
43
  define_method(:instrument) do |integration_name, options = {}, &block|
38
44
  return unless enabled
39
45
 
@@ -56,7 +62,7 @@ module Datadog
56
62
  fetch_integration(integration_name).configuration
57
63
  end
58
64
 
59
- # TODO: Deprecate in the next major version, as `instrument` better describes this method's purpose
65
+ # @deprecated Will be removed on datadog-ci-rb 1.0.
60
66
  alias_method :use, :instrument
61
67
 
62
68
  option :trace_flush
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "datadog/core"
4
+
3
5
  require_relative "../ext"
4
6
  require_relative "../../settings"
5
7
 
@@ -9,7 +11,7 @@ module Datadog
9
11
  module Cucumber
10
12
  module Configuration
11
13
  # Custom settings for the Cucumber integration
12
- # TODO: mark as `@public_api` when GA
14
+ # @public_api
13
15
  class Settings < Datadog::CI::Contrib::Settings
14
16
  option :enabled do |o|
15
17
  o.type :bool
@@ -22,10 +24,19 @@ module Datadog
22
24
  o.default { Datadog.configuration.service_without_fallback || Ext::SERVICE_NAME }
23
25
  end
24
26
 
27
+ # @deprecated Will be removed in 1.0
25
28
  option :operation_name do |o|
26
29
  o.type :string
27
30
  o.env Ext::ENV_OPERATION_NAME
28
31
  o.default Ext::OPERATION_NAME
32
+
33
+ o.after_set do |value|
34
+ if value && value != Ext::OPERATION_NAME
35
+ Datadog::Core.log_deprecation do
36
+ "The operation_name setting has no effect and will be removed in 1.0"
37
+ end
38
+ end
39
+ end
29
40
  end
30
41
  end
31
42
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../recorder"
4
3
  require_relative "../../ext/test"
5
4
  require_relative "ext"
6
5
 
@@ -28,56 +27,50 @@ module Datadog
28
27
  end
29
28
 
30
29
  def on_test_case_started(event)
31
- @current_feature_span = CI::Recorder.trace(
32
- configuration[:operation_name],
33
- {
34
- span_options: {
35
- resource: event.test_case.name,
36
- service: configuration[:service_name]
37
- },
38
- framework: Ext::FRAMEWORK,
39
- framework_version: CI::Contrib::Cucumber::Integration.version.to_s,
40
- test_name: event.test_case.name,
41
- test_suite: event.test_case.location.file,
42
- test_type: Ext::TEST_TYPE
43
- }
30
+ CI.start_test(
31
+ event.test_case.name,
32
+ event.test_case.location.file,
33
+ tags: {
34
+ CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
35
+ CI::Ext::Test::TAG_FRAMEWORK_VERSION => CI::Contrib::Cucumber::Integration.version.to_s,
36
+ CI::Ext::Test::TAG_TYPE => Ext::TEST_TYPE
37
+ },
38
+ service: configuration[:service_name]
44
39
  )
45
40
  end
46
41
 
47
42
  def on_test_case_finished(event)
48
- return if @current_feature_span.nil?
43
+ test_span = CI.active_test
44
+ return if test_span.nil?
49
45
 
50
46
  if event.result.skipped?
51
- CI::Recorder.skipped!(@current_feature_span)
47
+ test_span.skipped!
52
48
  elsif event.result.ok?
53
- CI::Recorder.passed!(@current_feature_span)
49
+ test_span.passed!
54
50
  elsif event.result.failed?
55
- CI::Recorder.failed!(@current_feature_span)
51
+ test_span.failed!
56
52
  end
57
53
 
58
- @current_feature_span.finish
54
+ test_span.finish
59
55
  end
60
56
 
61
57
  def on_test_step_started(event)
62
- trace_options = {
63
- resource: event.test_step.to_s,
64
- span_type: Ext::STEP_SPAN_TYPE
65
- }
66
- @current_step_span = Tracing.trace(Ext::STEP_SPAN_TYPE, **trace_options)
58
+ CI.trace(Ext::STEP_SPAN_TYPE, event.test_step.to_s)
67
59
  end
68
60
 
69
61
  def on_test_step_finished(event)
70
- return if @current_step_span.nil?
62
+ current_step_span = CI.active_span(Ext::STEP_SPAN_TYPE)
63
+ return if current_step_span.nil?
71
64
 
72
65
  if event.result.skipped?
73
- CI::Recorder.skipped!(@current_step_span, event.result.exception)
66
+ current_step_span.skipped!
74
67
  elsif event.result.ok?
75
- CI::Recorder.passed!(@current_step_span)
68
+ current_step_span.passed!
76
69
  elsif event.result.failed?
77
- CI::Recorder.failed!(@current_step_span, event.result.exception)
70
+ current_step_span.failed!(exception: event.result.exception)
78
71
  end
79
72
 
80
- @current_step_span.finish
73
+ current_step_span.finish
81
74
  end
82
75
 
83
76
  private
@@ -9,7 +9,7 @@ module Datadog
9
9
  module Minitest
10
10
  module Configuration
11
11
  # Custom settings for the Minitest integration
12
- # TODO: mark as `@public_api` when GA
12
+ # @public_api
13
13
  class Settings < Datadog::CI::Contrib::Settings
14
14
  option :enabled do |o|
15
15
  o.type :bool
@@ -22,10 +22,19 @@ module Datadog
22
22
  o.default { Datadog.configuration.service_without_fallback || Ext::SERVICE_NAME }
23
23
  end
24
24
 
25
+ # @deprecated Will be removed in 1.0
25
26
  option :operation_name do |o|
26
27
  o.type :string
27
28
  o.env Ext::ENV_OPERATION_NAME
28
29
  o.default Ext::OPERATION_NAME
30
+
31
+ o.after_set do |value|
32
+ if value && value != Ext::OPERATION_NAME
33
+ Datadog::Core.log_deprecation do
34
+ "The operation_name setting has no effect and will be removed in 1.0"
35
+ end
36
+ end
37
+ end
29
38
  end
30
39
  end
31
40
  end