datadog-ci 0.2.0 → 0.4.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 (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -1
  3. data/README.md +36 -36
  4. data/lib/datadog/ci/configuration/components.rb +51 -25
  5. data/lib/datadog/ci/context/local.rb +50 -0
  6. data/lib/datadog/ci/contrib/cucumber/formatter.rb +23 -29
  7. data/lib/datadog/ci/contrib/minitest/hooks.rb +16 -25
  8. data/lib/datadog/ci/contrib/rspec/example.rb +14 -18
  9. data/lib/datadog/ci/ext/environment/extractor.rb +5 -10
  10. data/lib/datadog/ci/ext/environment/providers/appveyor.rb +4 -0
  11. data/lib/datadog/ci/ext/environment/providers/aws_code_pipeline.rb +39 -0
  12. data/lib/datadog/ci/ext/environment/providers/azure.rb +4 -0
  13. data/lib/datadog/ci/ext/environment/providers/base.rb +4 -0
  14. data/lib/datadog/ci/ext/environment/providers/bitbucket.rb +4 -0
  15. data/lib/datadog/ci/ext/environment/providers/bitrise.rb +4 -0
  16. data/lib/datadog/ci/ext/environment/providers/buddy.rb +4 -0
  17. data/lib/datadog/ci/ext/environment/providers/buildkite.rb +4 -0
  18. data/lib/datadog/ci/ext/environment/providers/circleci.rb +4 -0
  19. data/lib/datadog/ci/ext/environment/providers/codefresh.rb +4 -0
  20. data/lib/datadog/ci/ext/environment/providers/github_actions.rb +17 -4
  21. data/lib/datadog/ci/ext/environment/providers/gitlab.rb +4 -0
  22. data/lib/datadog/ci/ext/environment/providers/jenkins.rb +4 -0
  23. data/lib/datadog/ci/ext/environment/providers/teamcity.rb +4 -0
  24. data/lib/datadog/ci/ext/environment/providers/travis.rb +4 -0
  25. data/lib/datadog/ci/ext/environment/providers.rb +16 -14
  26. data/lib/datadog/ci/ext/transport.rb +5 -0
  27. data/lib/datadog/ci/recorder.rb +82 -46
  28. data/lib/datadog/ci/span.rb +107 -0
  29. data/lib/datadog/ci/test.rb +26 -0
  30. data/lib/datadog/ci/test_visibility/transport.rb +11 -29
  31. data/lib/datadog/ci/transport/api/base.rb +36 -0
  32. data/lib/datadog/ci/transport/api/builder.rb +46 -0
  33. data/lib/datadog/ci/transport/api/ci_test_cycle.rb +30 -0
  34. data/lib/datadog/ci/transport/api/evp_proxy.rb +44 -0
  35. data/lib/datadog/ci/transport/gzip.rb +4 -2
  36. data/lib/datadog/ci/transport/http.rb +25 -101
  37. data/lib/datadog/ci/utils/url.rb +15 -0
  38. data/lib/datadog/ci/version.rb +1 -1
  39. data/lib/datadog/ci.rb +193 -4
  40. data/sig/datadog/ci/configuration/components.rbs +7 -1
  41. data/sig/datadog/ci/context/local.rbs +21 -0
  42. data/sig/datadog/ci/ext/environment/extractor.rbs +0 -2
  43. data/sig/datadog/ci/ext/environment/providers/aws_code_pipeline.rbs +19 -0
  44. data/sig/datadog/ci/ext/environment/providers/base.rbs +2 -0
  45. data/sig/datadog/ci/ext/environment/providers/github_actions.rbs +5 -0
  46. data/sig/datadog/ci/ext/environment/providers.rbs +1 -1
  47. data/sig/datadog/ci/ext/transport.rbs +8 -0
  48. data/sig/datadog/ci/recorder.rbs +20 -8
  49. data/sig/datadog/ci/span.rbs +35 -0
  50. data/sig/datadog/ci/test.rbs +7 -0
  51. data/sig/datadog/ci/test_visibility/transport.rbs +7 -11
  52. data/sig/datadog/ci/transport/api/base.rbs +21 -0
  53. data/sig/datadog/ci/transport/api/builder.rbs +12 -0
  54. data/sig/datadog/ci/transport/api/ci_test_cycle.rbs +21 -0
  55. data/sig/datadog/ci/transport/api/evp_proxy.rbs +19 -0
  56. data/sig/datadog/ci/transport/http.rbs +12 -37
  57. data/sig/datadog/ci/utils/url.rbs +9 -0
  58. data/sig/datadog/ci.rbs +15 -3
  59. metadata +21 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: edf471864cc0dc97624e2666deede58c547f5513a972a4e041c1204a0b665a36
4
- data.tar.gz: a1cbf16a8c4891173dc02ceef831a94be2b2a50936bf551494c814c94a94594c
3
+ metadata.gz: 60a81205d586462fc1e58ff85bcddd69bbab3dc597abe2a730ad393fe9261040
4
+ data.tar.gz: d44884f838dd3b50db30796d581017127ff6de63dc3121fc531ad54f786ae389
5
5
  SHA512:
6
- metadata.gz: 9c1559ae996b1f7ee7fc5ac0ec131f4e227fb227c7fa62af30f3e6739e040d5947a1e1ca900b3abe94d21262608164dd0ea82ffbcd7fa1e5a157ab400bd22554
7
- data.tar.gz: c58b74157088a4c3e8dbafad7cbf443ebbb503cc831ae2106190bfadc26cfd67f1c80be6d7b500350736b3b3ee8056d1de4aec4693a7500cef1156dd490d3cf7
6
+ metadata.gz: e69a35a679697d2b142140f71f0704f2c9a4fcf28d2fc9ddff79dd4f514172711c50123c4294252b2e89188ce17ced36656f08290e4c86ee187c3b22965d56da
7
+ data.tar.gz: c12c56c96a6b31be3b931afdc441890ac88a59e7d12cf663b3fbbce7408ea8338b8d31fb4f49360fcaddfd425e36088bf638f960032cae6c1507d9c83fe36c7a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.0] - 2023-11-21
4
+
5
+ ### Added
6
+
7
+ * Public API for manual test instrumentation ([#64][]) ([#61][])
8
+
9
+ ### Changed
10
+
11
+ * fix tracing instrumentation example in readme ([#60][])
12
+
13
+ ### Fixed
14
+
15
+ * Remove user credentials from ssh URLs and from GITHUB_REPO_URL environment variable ([#66][])
16
+
17
+ ### Removed
18
+
19
+ * Remove _dd.measured tag from spans ([#65][])
20
+
21
+ ## [0.3.0] - 2023-10-25
22
+
23
+ ### Added
24
+
25
+ * Add AWS CodePipeline support for automatic CI tags extraction ([#54][])
26
+ * Support test visibility protocol via Datadog Agent with EVP proxy ([#51][])
27
+
28
+ ### Changed
29
+
30
+ * Migrate to Net::HTTP adapter from Core module of ddtrace gem ([#49][])
31
+
3
32
  ## [0.2.0] - 2023-10-05
4
33
 
5
34
  ### Added
@@ -36,7 +65,9 @@
36
65
 
37
66
  * Ruby versions < 2.7 no longer supported ([#8][])
38
67
 
39
- [Unreleased]: https://github.com/DataDog/datadog-ci-rb/compare/v0.2.0...main
68
+ [Unreleased]: https://github.com/DataDog/datadog-ci-rb/compare/v0.4.0...main
69
+ [0.4.0]: https://github.com/DataDog/datadog-ci-rb/compare/v0.3.0...v0.4.0
70
+ [0.3.0]: https://github.com/DataDog/datadog-ci-rb/compare/v0.2.0...v0.3.0
40
71
  [0.2.0]: https://github.com/DataDog/datadog-ci-rb/compare/v0.1.1...v0.2.0
41
72
  [0.1.1]: https://github.com/DataDog/datadog-ci-rb/compare/v0.1.0...v0.1.1
42
73
 
@@ -51,3 +82,11 @@
51
82
  [#31]: https://github.com/DataDog/datadog-ci-rb/issues/31
52
83
  [#33]: https://github.com/DataDog/datadog-ci-rb/issues/33
53
84
  [#40]: https://github.com/DataDog/datadog-ci-rb/issues/40
85
+ [#49]: https://github.com/DataDog/datadog-ci-rb/issues/49
86
+ [#51]: https://github.com/DataDog/datadog-ci-rb/issues/51
87
+ [#54]: https://github.com/DataDog/datadog-ci-rb/issues/54
88
+ [#60]: https://github.com/DataDog/datadog-ci-rb/issues/60
89
+ [#61]: https://github.com/DataDog/datadog-ci-rb/issues/61
90
+ [#64]: https://github.com/DataDog/datadog-ci-rb/issues/64
91
+ [#65]: https://github.com/DataDog/datadog-ci-rb/issues/65
92
+ [#66]: https://github.com/DataDog/datadog-ci-rb/issues/66
data/README.md CHANGED
@@ -30,18 +30,18 @@ To activate `RSpec` integration, add this to the `spec_helper.rb` file:
30
30
  require 'rspec'
31
31
  require 'datadog/ci'
32
32
 
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
39
-
40
- # The name of the service or library under test
41
- c.service = 'my-ruby-app'
42
-
43
- # Enables the RSpec instrumentation
44
- c.ci.instrument :rspec, **options
33
+ # Only activates test instrumentation on CI
34
+ if ENV["DD_ENV"] == "ci"
35
+ Datadog.configure do |c|
36
+ # Configures the tracer to ensure results delivery
37
+ c.ci.enabled = true
38
+
39
+ # The name of the service or library under test
40
+ c.service = 'my-ruby-app'
41
+
42
+ # Enables the RSpec instrumentation
43
+ c.ci.instrument :rspec, **options
44
+ end
45
45
  end
46
46
  ```
47
47
 
@@ -51,7 +51,7 @@ end
51
51
  | --- | ----------- | ------- |
52
52
  | `enabled` | Defines whether RSpec tests should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` |
53
53
  | `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'` |
54
+ | `operation_name` | Operation name used for `rspec` instrumentation. | `'rspec.example'` |
55
55
 
56
56
  ### Minitest
57
57
 
@@ -63,18 +63,18 @@ To activate your integration, use the `Datadog.configure` method:
63
63
  require 'minitest'
64
64
  require 'datadog/ci'
65
65
 
66
+ # Only activates test instrumentation on CI
67
+ if ENV["DD_ENV"] == "ci"
66
68
  # 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
69
+ Datadog.configure do |c|
70
+ # Configures the tracer to ensure results delivery
71
+ c.ci.enabled = true
73
72
 
74
- # The name of the service or library under test
75
- c.service = 'my-ruby-app'
73
+ # The name of the service or library under test
74
+ c.service = 'my-ruby-app'
76
75
 
77
- c.ci.instrument :minitest, **options
76
+ c.ci.instrument :minitest, **options
77
+ end
78
78
  end
79
79
  ```
80
80
 
@@ -84,7 +84,7 @@ end
84
84
  | --- | ----------- | ------- |
85
85
  | `enabled` | Defines whether Minitest tests should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` |
86
86
  | `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'` |
87
+ | `operation_name` | Operation name used for `minitest` instrumentation. | `'minitest.test'` |
88
88
 
89
89
  ### Cucumber
90
90
 
@@ -94,18 +94,18 @@ Activate `Cucumber` integration with configuration
94
94
  require 'cucumber'
95
95
  require 'datadog/ci'
96
96
 
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
97
+ # Only activates test instrumentation on CI
98
+ if ENV["DD_ENV"] == "ci"
99
+ Datadog.configure do |c|
100
+ # Configures the tracer to ensure results delivery
101
+ c.ci.enabled = true
103
102
 
104
- # The name of the service or library under test
105
- c.service = 'my-ruby-app'
103
+ # The name of the service or library under test
104
+ c.service = 'my-ruby-app'
106
105
 
107
- # Enables the Cucumber instrumentation
108
- c.ci.instrument :cucumber, **options
106
+ # Enables the Cucumber instrumentation
107
+ c.ci.instrument :cucumber, **options
108
+ end
109
109
  end
110
110
  ```
111
111
 
@@ -115,7 +115,7 @@ end
115
115
  | --- | ----------- | ------- |
116
116
  | `enabled` | Defines whether Cucumber tests should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` |
117
117
  | `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'` |
118
+ | `operation_name` | Operation name used for `cucumber` instrumentation. | `'cucumber.test'` |
119
119
 
120
120
  ## Agentless mode
121
121
 
@@ -145,8 +145,8 @@ In order to achieve this you can configure ddtrace instrumentations in your conf
145
145
  ```ruby
146
146
  Datadog.configure do |c|
147
147
  # ... ci configs and instrumentation here ...
148
- c.instrument :redis
149
- c.instrument :pg
148
+ c.tracing.instrument :redis
149
+ c.tracing.instrument :pg
150
150
  end
151
151
  ```
152
152
 
@@ -1,13 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "datadog/core/configuration/agent_settings_resolver"
4
+ require "datadog/core/remote/negotiation"
5
+
6
+ require_relative "../ext/transport"
3
7
  require_relative "../test_visibility/flush"
4
8
  require_relative "../test_visibility/transport"
9
+ require_relative "../transport/api/builder"
10
+ require_relative "../recorder"
5
11
 
6
12
  module Datadog
7
13
  module CI
8
14
  module Configuration
9
15
  # Adds CI behavior to Datadog trace components
10
16
  module Components
17
+ attr_reader :ci_recorder
18
+
11
19
  def initialize(settings)
12
20
  # Activate CI mode if enabled
13
21
  activate_ci!(settings) if settings.ci.enabled
@@ -17,25 +25,13 @@ module Datadog
17
25
  end
18
26
 
19
27
  def activate_ci!(settings)
20
- agentless_transport = nil
28
+ test_visibility_transport = nil
29
+ agent_settings = Datadog::Core::Configuration::AgentSettingsResolver.call(settings)
21
30
 
22
31
  if settings.ci.agentless_mode_enabled
23
- if settings.api_key.nil?
24
- # agentless mode is requested but no API key is provided -
25
- # we cannot continue and log an error
26
- # Tests are running without CI visibility enabled
27
-
28
- Datadog.logger.error(
29
- "DATADOG CONFIGURATION - CI VISIBILITY - ATTENTION - " \
30
- "Agentless mode was enabled but DD_API_KEY is not set: CI visibility is disabled. " \
31
- "Please make sure to set valid api key in DD_API_KEY environment variable"
32
- )
33
-
34
- settings.ci.enabled = false
35
- return
36
- else
37
- agentless_transport = build_agentless_transport(settings)
38
- end
32
+ test_visibility_transport = build_agentless_transport(settings)
33
+ elsif can_use_evp_proxy?(settings, agent_settings)
34
+ test_visibility_transport = build_evp_proxy_transport(settings, agent_settings)
39
35
  end
40
36
 
41
37
  # Deactivate telemetry
@@ -51,25 +47,55 @@ module Datadog
51
47
  settings.tracing.test_mode.trace_flush = settings.ci.trace_flush || CI::TestVisibility::Flush::Finished.new
52
48
 
53
49
  writer_options = settings.ci.writer_options
54
- if agentless_transport
55
- writer_options[:transport] = agentless_transport
50
+ if test_visibility_transport
51
+ writer_options[:transport] = test_visibility_transport
56
52
  writer_options[:shutdown_timeout] = 60
57
53
 
58
54
  settings.tracing.test_mode.async = true
59
55
  end
60
56
 
61
57
  settings.tracing.test_mode.writer_options = writer_options
58
+
59
+ @ci_recorder = Recorder.new
60
+ end
61
+
62
+ def can_use_evp_proxy?(settings, agent_settings)
63
+ Datadog::Core::Remote::Negotiation.new(settings, agent_settings).endpoint?(
64
+ Ext::Transport::EVP_PROXY_PATH_PREFIX
65
+ )
62
66
  end
63
67
 
64
68
  def build_agentless_transport(settings)
65
- dd_site = settings.site || "datadoghq.com"
66
- agentless_url = settings.ci.agentless_url ||
67
- "https://#{Ext::Transport::TEST_VISIBILITY_INTAKE_HOST_PREFIX}.#{dd_site}:443"
69
+ if settings.api_key.nil?
70
+ # agentless mode is requested but no API key is provided -
71
+ # we cannot continue and log an error
72
+ # Tests are running without CI visibility enabled
73
+
74
+ Datadog.logger.error(
75
+ "DATADOG CONFIGURATION - CI VISIBILITY - ATTENTION - " \
76
+ "Agentless mode was enabled but DD_API_KEY is not set: CI visibility is disabled. " \
77
+ "Please make sure to set valid api key in DD_API_KEY environment variable"
78
+ )
79
+
80
+ settings.ci.enabled = false
81
+
82
+ nil
83
+ else
84
+ Datadog.logger.debug("CI visibility configured to use agentless transport")
85
+
86
+ Datadog::CI::TestVisibility::Transport.new(
87
+ api: Transport::Api::Builder.build_ci_test_cycle_api(settings),
88
+ dd_env: settings.env
89
+ )
90
+ end
91
+ end
92
+
93
+ def build_evp_proxy_transport(settings, agent_settings)
94
+ Datadog.logger.debug("CI visibility configured to use agent transport via EVP proxy")
68
95
 
69
96
  Datadog::CI::TestVisibility::Transport.new(
70
- api_key: settings.api_key,
71
- url: agentless_url,
72
- env: settings.env
97
+ api: Transport::Api::Builder.build_evp_proxy_api(agent_settings),
98
+ dd_env: settings.env
73
99
  )
74
100
  end
75
101
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datadog
4
+ module CI
5
+ module Context
6
+ class Local
7
+ def initialize
8
+ @key = :datadog_ci_active_test
9
+
10
+ self.active_test = nil
11
+ end
12
+
13
+ def activate_test!(test)
14
+ raise "Nested tests are not supported. Currently active test: #{active_test}" unless active_test.nil?
15
+
16
+ if block_given?
17
+ begin
18
+ self.active_test = test
19
+ yield
20
+ ensure
21
+ self.active_test = nil
22
+ end
23
+ else
24
+ self.active_test = test
25
+ end
26
+ end
27
+
28
+ def deactivate_test!(test)
29
+ return if active_test.nil?
30
+
31
+ if active_test == test
32
+ self.active_test = nil
33
+ else
34
+ raise "Trying to deactivate test #{test}, but currently active test is #{active_test}"
35
+ end
36
+ end
37
+
38
+ def active_test
39
+ Thread.current[@key]
40
+ end
41
+
42
+ private
43
+
44
+ def active_test=(test)
45
+ Thread.current[@key] = test
46
+ end
47
+ end
48
+ end
49
+ end
50
+ 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,51 @@ 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
+ tags: {
33
+ CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
34
+ CI::Ext::Test::TAG_FRAMEWORK_VERSION => CI::Contrib::Cucumber::Integration.version.to_s,
35
+ CI::Ext::Test::TAG_TYPE => Ext::TEST_TYPE,
36
+ CI::Ext::Test::TAG_SUITE => event.test_case.location.file
37
+ },
38
+ service_name: configuration[:service_name],
39
+ operation_name: configuration[:operation_name]
44
40
  )
45
41
  end
46
42
 
47
43
  def on_test_case_finished(event)
48
- return if @current_feature_span.nil?
44
+ test_span = CI.active_test
45
+ return if test_span.nil?
49
46
 
50
47
  if event.result.skipped?
51
- CI::Recorder.skipped!(@current_feature_span)
48
+ test_span.skipped!
52
49
  elsif event.result.ok?
53
- CI::Recorder.passed!(@current_feature_span)
50
+ test_span.passed!
54
51
  elsif event.result.failed?
55
- CI::Recorder.failed!(@current_feature_span)
52
+ test_span.failed!
56
53
  end
57
54
 
58
- @current_feature_span.finish
55
+ test_span.finish
59
56
  end
60
57
 
61
58
  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)
59
+ CI.trace(Ext::STEP_SPAN_TYPE, event.test_step.to_s)
67
60
  end
68
61
 
69
62
  def on_test_step_finished(event)
70
- return if @current_step_span.nil?
63
+ current_step_span = CI.active_span(Ext::STEP_SPAN_TYPE)
64
+ return if current_step_span.nil?
71
65
 
72
66
  if event.result.skipped?
73
- CI::Recorder.skipped!(@current_step_span, event.result.exception)
67
+ current_step_span.skipped!
74
68
  elsif event.result.ok?
75
- CI::Recorder.passed!(@current_step_span)
69
+ current_step_span.passed!
76
70
  elsif event.result.failed?
77
- CI::Recorder.failed!(@current_step_span, event.result.exception)
71
+ current_step_span.failed!(exception: event.result.exception)
78
72
  end
79
73
 
80
- @current_step_span.finish
74
+ current_step_span.finish
81
75
  end
82
76
 
83
77
  private
@@ -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
 
@@ -19,41 +18,33 @@ module Datadog
19
18
  path, = method(name).source_location
20
19
  test_suite = Pathname.new(path.to_s).relative_path_from(Pathname.pwd).to_s
21
20
 
22
- span = CI::Recorder.trace(
23
- configuration[:operation_name],
24
- {
25
- span_options: {
26
- resource: test_name,
27
- service: configuration[:service_name]
28
- },
29
- framework: Ext::FRAMEWORK,
30
- framework_version: CI::Contrib::Minitest::Integration.version.to_s,
31
- test_name: test_name,
32
- test_suite: test_suite,
33
- test_type: Ext::TEST_TYPE
34
- }
21
+ CI.start_test(
22
+ test_name,
23
+ tags: {
24
+ CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
25
+ CI::Ext::Test::TAG_FRAMEWORK_VERSION => CI::Contrib::Minitest::Integration.version.to_s,
26
+ CI::Ext::Test::TAG_TYPE => Ext::TEST_TYPE,
27
+ CI::Ext::Test::TAG_SUITE => test_suite
28
+ },
29
+ service_name: configuration[:service_name],
30
+ operation_name: configuration[:operation_name]
35
31
  )
36
-
37
- Thread.current[:_datadog_test_span] = span
38
32
  end
39
33
 
40
34
  def after_teardown
41
- span = Thread.current[:_datadog_test_span]
42
- return super unless span
43
-
44
- Thread.current[:_datadog_test_span] = nil
35
+ test_span = CI.active_test
36
+ return super unless test_span
45
37
 
46
38
  case result_code
47
39
  when "."
48
- CI::Recorder.passed!(span)
40
+ test_span.passed!
49
41
  when "E", "F"
50
- CI::Recorder.failed!(span, failure)
42
+ test_span.failed!(exception: failure)
51
43
  when "S"
52
- CI::Recorder.skipped!(span)
53
- span.set_tag(CI::Ext::Test::TAG_SKIP_REASON, failure.message)
44
+ test_span.skipped!(reason: failure.message)
54
45
  end
55
46
 
56
- span.finish
47
+ test_span.finish
57
48
 
58
49
  super
59
50
  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
 
@@ -25,29 +24,26 @@ module Datadog
25
24
  test_name += " #{description}"
26
25
  end
27
26
 
28
- CI::Recorder.trace(
29
- configuration[:operation_name],
30
- {
31
- span_options: {
32
- resource: test_name,
33
- service: configuration[:service_name]
34
- },
35
- framework: Ext::FRAMEWORK,
36
- framework_version: CI::Contrib::RSpec::Integration.version.to_s,
37
- test_name: test_name,
38
- test_suite: metadata[:example_group][:file_path],
39
- test_type: Ext::TEST_TYPE
40
- }
41
- ) do |span|
27
+ CI.trace_test(
28
+ test_name,
29
+ tags: {
30
+ CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
31
+ CI::Ext::Test::TAG_FRAMEWORK_VERSION => CI::Contrib::RSpec::Integration.version.to_s,
32
+ CI::Ext::Test::TAG_TYPE => Ext::TEST_TYPE,
33
+ CI::Ext::Test::TAG_SUITE => metadata[:example_group][:file_path]
34
+ },
35
+ service_name: configuration[:service_name],
36
+ operation_name: configuration[:operation_name]
37
+ ) do |test_span|
42
38
  result = super
43
39
 
44
40
  case execution_result.status
45
41
  when :passed
46
- CI::Recorder.passed!(span)
42
+ test_span.passed!
47
43
  when :failed
48
- CI::Recorder.failed!(span, execution_result.exception)
44
+ test_span.failed!(exception: execution_result.exception)
49
45
  else
50
- CI::Recorder.skipped!(span, execution_result.exception) if execution_result.example_skipped?
46
+ test_span.skipped!(exception: execution_result.exception) if execution_result.example_skipped?
51
47
  end
52
48
 
53
49
  result
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "../git"
4
4
  require_relative "../../utils/git"
5
+ require_relative "../../utils/url"
5
6
  require_relative "providers"
6
7
 
7
8
  module Datadog
@@ -68,14 +69,14 @@ module Datadog
68
69
 
69
70
  def normalize_git!
70
71
  branch_ref = @tags[Git::TAG_BRANCH]
71
- if Datadog::CI::Utils::Git.is_git_tag?(branch_ref)
72
+ if Utils::Git.is_git_tag?(branch_ref)
72
73
  @tags[Git::TAG_TAG] = branch_ref
73
74
  @tags.delete(Git::TAG_BRANCH)
74
75
  end
75
76
 
76
- @tags[Git::TAG_TAG] = Datadog::CI::Utils::Git.normalize_ref(@tags[Git::TAG_TAG])
77
- @tags[Git::TAG_BRANCH] = Datadog::CI::Utils::Git.normalize_ref(@tags[Git::TAG_BRANCH])
78
- @tags[Git::TAG_REPOSITORY_URL] = filter_sensitive_info(
77
+ @tags[Git::TAG_TAG] = Utils::Git.normalize_ref(@tags[Git::TAG_TAG])
78
+ @tags[Git::TAG_BRANCH] = Utils::Git.normalize_ref(@tags[Git::TAG_BRANCH])
79
+ @tags[Git::TAG_REPOSITORY_URL] = Utils::Url.filter_sensitive_info(
79
80
  @tags[Git::TAG_REPOSITORY_URL]
80
81
  )
81
82
  end
@@ -87,12 +88,6 @@ module Datadog
87
88
  @tags[TAG_WORKSPACE_PATH] = File.expand_path(workspace_path)
88
89
  end
89
90
  end
90
-
91
- def filter_sensitive_info(url)
92
- return nil if url.nil?
93
-
94
- url.gsub(%r{(https?://)[^/]*@}, '\1')
95
- end
96
91
  end
97
92
  end
98
93
  end
@@ -10,6 +10,10 @@ module Datadog
10
10
  # Appveyor: https://www.appveyor.com/
11
11
  # Environment variables docs: https://www.appveyor.com/docs/environment-variables/
12
12
  class Appveyor < Base
13
+ def self.handles?(env)
14
+ env.key?("APPVEYOR")
15
+ end
16
+
13
17
  def provider_name
14
18
  "appveyor"
15
19
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base"
4
+
5
+ module Datadog
6
+ module CI
7
+ module Ext
8
+ module Environment
9
+ module Providers
10
+ # AWS CodePipeline: https://aws.amazon.com/codepipeline/
11
+ # Environment variables docs: https://docs.aws.amazon.com/codepipeline/latest/userguide/actions-variables.html
12
+ # AWS CodeBuild: https://aws.amazon.com/codebuild/
13
+ # Environment variable docs: https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
14
+ class AwsCodePipeline < Base
15
+ def self.handles?(env)
16
+ !env["CODEBUILD_INITIATOR"].nil? && env["CODEBUILD_INITIATOR"].start_with?("codepipeline")
17
+ end
18
+
19
+ def provider_name
20
+ "awscodepipeline"
21
+ end
22
+
23
+ def pipeline_id
24
+ env["DD_PIPELINE_EXECUTION_ID"]
25
+ end
26
+
27
+ def ci_env_vars
28
+ {
29
+ "CODEBUILD_BUILD_ARN" => env["CODEBUILD_BUILD_ARN"],
30
+ "DD_PIPELINE_EXECUTION_ID" => env["DD_PIPELINE_EXECUTION_ID"],
31
+ "DD_ACTION_EXECUTION_ID" => env["DD_ACTION_EXECUTION_ID"]
32
+ }.to_json
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -12,6 +12,10 @@ module Datadog
12
12
  # Azure Pipelines: https://azure.microsoft.com/en-us/products/devops/pipelines
13
13
  # Environment variables docs: https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml
14
14
  class Azure < Base
15
+ def self.handles?(env)
16
+ env.key?("TF_BUILD")
17
+ end
18
+
15
19
  def provider_name
16
20
  "azurepipelines"
17
21
  end