datadog-ci 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +50 -1
- data/README.md +26 -3
- data/lib/datadog/ci/concurrent_span.rb +59 -0
- data/lib/datadog/ci/configuration/components.rb +37 -3
- data/lib/datadog/ci/configuration/settings.rb +7 -1
- data/lib/datadog/ci/context/global.rb +80 -0
- data/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +12 -1
- data/lib/datadog/ci/contrib/cucumber/formatter.rb +3 -4
- data/lib/datadog/ci/contrib/minitest/configuration/settings.rb +10 -1
- data/lib/datadog/ci/contrib/minitest/hooks.rb +3 -4
- data/lib/datadog/ci/contrib/rspec/configuration/settings.rb +10 -1
- data/lib/datadog/ci/contrib/rspec/example.rb +3 -4
- data/lib/datadog/ci/contrib/settings.rb +2 -0
- data/lib/datadog/ci/ext/app_types.rb +5 -0
- data/lib/datadog/ci/ext/settings.rb +11 -0
- data/lib/datadog/ci/ext/test.rb +12 -1
- data/lib/datadog/ci/null_span.rb +63 -0
- data/lib/datadog/ci/recorder.rb +207 -35
- data/lib/datadog/ci/span.rb +13 -3
- data/lib/datadog/ci/test.rb +0 -1
- data/lib/datadog/ci/test_module.rb +23 -0
- data/lib/datadog/ci/test_session.rb +36 -0
- data/lib/datadog/ci/test_suite.rb +25 -0
- data/lib/datadog/ci/test_visibility/serializers/base.rb +100 -12
- data/lib/datadog/ci/test_visibility/serializers/factories/test_suite_level.rb +37 -0
- data/lib/datadog/ci/test_visibility/serializers/span.rb +2 -16
- data/lib/datadog/ci/test_visibility/serializers/test_module.rb +46 -0
- data/lib/datadog/ci/test_visibility/serializers/test_session.rb +46 -0
- data/lib/datadog/ci/test_visibility/serializers/test_suite.rb +46 -0
- data/lib/datadog/ci/test_visibility/serializers/test_v1.rb +3 -17
- data/lib/datadog/ci/test_visibility/serializers/test_v2.rb +38 -0
- data/lib/datadog/ci/test_visibility/transport.rb +4 -4
- data/lib/datadog/ci/utils/test_run.rb +15 -0
- data/lib/datadog/ci/version.rb +1 -1
- data/lib/datadog/ci.rb +214 -32
- data/sig/datadog/ci/concurrent_span.rbs +23 -0
- data/sig/datadog/ci/configuration/components.rbs +2 -0
- data/sig/datadog/ci/context/global.rbs +37 -0
- data/sig/datadog/ci/ext/app_types.rbs +6 -1
- data/sig/datadog/ci/ext/settings.rbs +3 -0
- data/sig/datadog/ci/ext/test.rbs +15 -0
- data/sig/datadog/ci/null_span.rbs +37 -0
- data/sig/datadog/ci/recorder.rbs +54 -1
- data/sig/datadog/ci/span.rbs +4 -0
- data/sig/datadog/ci/test_module.rbs +6 -0
- data/sig/datadog/ci/test_session.rbs +9 -0
- data/sig/datadog/ci/test_suite.rbs +6 -0
- data/sig/datadog/ci/test_visibility/serializers/base.rbs +26 -5
- data/sig/datadog/ci/test_visibility/serializers/factories/test_suite_level.rbs +13 -0
- data/sig/datadog/ci/test_visibility/serializers/test_module.rbs +26 -0
- data/sig/datadog/ci/test_visibility/serializers/test_session.rbs +26 -0
- data/sig/datadog/ci/test_visibility/serializers/test_suite.rbs +26 -0
- data/sig/datadog/ci/test_visibility/serializers/test_v1.rbs +1 -1
- data/sig/datadog/ci/test_visibility/serializers/test_v2.rbs +25 -0
- data/sig/datadog/ci/test_visibility/transport.rbs +3 -3
- data/sig/datadog/ci/utils/test_run.rbs +11 -0
- data/sig/datadog/ci.rbs +18 -2
- metadata +26 -2
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../test_v2"
|
4
|
+
require_relative "../test_session"
|
5
|
+
require_relative "../test_module"
|
6
|
+
require_relative "../test_suite"
|
7
|
+
require_relative "../span"
|
8
|
+
|
9
|
+
module Datadog
|
10
|
+
module CI
|
11
|
+
module TestVisibility
|
12
|
+
module Serializers
|
13
|
+
module Factories
|
14
|
+
# This factory takes care of creating citestcycle serializers when test-suite-level visibility is enabled
|
15
|
+
module TestSuiteLevel
|
16
|
+
module_function
|
17
|
+
|
18
|
+
def serializer(trace, span)
|
19
|
+
case span.type
|
20
|
+
when Datadog::CI::Ext::AppTypes::TYPE_TEST
|
21
|
+
Serializers::TestV2.new(trace, span)
|
22
|
+
when Datadog::CI::Ext::AppTypes::TYPE_TEST_SESSION
|
23
|
+
Serializers::TestSession.new(trace, span)
|
24
|
+
when Datadog::CI::Ext::AppTypes::TYPE_TEST_MODULE
|
25
|
+
Serializers::TestModule.new(trace, span)
|
26
|
+
when Datadog::CI::Ext::AppTypes::TYPE_TEST_SUITE
|
27
|
+
Serializers::TestSuite.new(trace, span)
|
28
|
+
else
|
29
|
+
Serializers::Span.new(trace, span)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -7,25 +7,11 @@ module Datadog
|
|
7
7
|
module TestVisibility
|
8
8
|
module Serializers
|
9
9
|
class Span < Base
|
10
|
-
CONTENT_FIELDS = [
|
11
|
-
"trace_id", "span_id", "parent_id",
|
12
|
-
"name", "resource", "service",
|
13
|
-
"error", "start", "duration",
|
14
|
-
"meta", "metrics",
|
15
|
-
"type" => "span_type"
|
16
|
-
].freeze
|
10
|
+
CONTENT_FIELDS = (["trace_id", "span_id", "parent_id"] + Base::CONTENT_FIELDS).freeze
|
17
11
|
|
18
12
|
CONTENT_MAP_SIZE = calculate_content_map_size(CONTENT_FIELDS)
|
19
13
|
|
20
|
-
REQUIRED_FIELDS = [
|
21
|
-
"trace_id",
|
22
|
-
"span_id",
|
23
|
-
"error",
|
24
|
-
"name",
|
25
|
-
"resource",
|
26
|
-
"start",
|
27
|
-
"duration"
|
28
|
-
].freeze
|
14
|
+
REQUIRED_FIELDS = (["trace_id", "span_id"] + Base::REQUIRED_FIELDS).freeze
|
29
15
|
|
30
16
|
def content_fields
|
31
17
|
CONTENT_FIELDS
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
require_relative "../../ext/test"
|
5
|
+
|
6
|
+
module Datadog
|
7
|
+
module CI
|
8
|
+
module TestVisibility
|
9
|
+
module Serializers
|
10
|
+
class TestModule < Base
|
11
|
+
CONTENT_FIELDS = (["test_session_id", "test_module_id"] + Base::CONTENT_FIELDS).freeze
|
12
|
+
|
13
|
+
CONTENT_MAP_SIZE = calculate_content_map_size(CONTENT_FIELDS)
|
14
|
+
|
15
|
+
REQUIRED_FIELDS = (["test_session_id", "test_module_id"] + Base::REQUIRED_FIELDS).freeze
|
16
|
+
|
17
|
+
def content_fields
|
18
|
+
CONTENT_FIELDS
|
19
|
+
end
|
20
|
+
|
21
|
+
def content_map_size
|
22
|
+
CONTENT_MAP_SIZE
|
23
|
+
end
|
24
|
+
|
25
|
+
def type
|
26
|
+
Ext::AppTypes::TYPE_TEST_MODULE
|
27
|
+
end
|
28
|
+
|
29
|
+
def name
|
30
|
+
"#{@span.get_tag(Ext::Test::TAG_FRAMEWORK)}.test_module"
|
31
|
+
end
|
32
|
+
|
33
|
+
def resource
|
34
|
+
"#{@span.get_tag(Ext::Test::TAG_FRAMEWORK)}.test_module.#{@span.get_tag(Ext::Test::TAG_MODULE)}"
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def required_fields
|
40
|
+
REQUIRED_FIELDS
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
require_relative "../../ext/test"
|
5
|
+
|
6
|
+
module Datadog
|
7
|
+
module CI
|
8
|
+
module TestVisibility
|
9
|
+
module Serializers
|
10
|
+
class TestSession < Base
|
11
|
+
CONTENT_FIELDS = (["test_session_id"] + Base::CONTENT_FIELDS).freeze
|
12
|
+
|
13
|
+
CONTENT_MAP_SIZE = calculate_content_map_size(CONTENT_FIELDS)
|
14
|
+
|
15
|
+
REQUIRED_FIELDS = (["test_session_id"] + Base::REQUIRED_FIELDS).freeze
|
16
|
+
|
17
|
+
def content_fields
|
18
|
+
CONTENT_FIELDS
|
19
|
+
end
|
20
|
+
|
21
|
+
def content_map_size
|
22
|
+
CONTENT_MAP_SIZE
|
23
|
+
end
|
24
|
+
|
25
|
+
def type
|
26
|
+
Ext::AppTypes::TYPE_TEST_SESSION
|
27
|
+
end
|
28
|
+
|
29
|
+
def name
|
30
|
+
"#{@span.get_tag(Ext::Test::TAG_FRAMEWORK)}.test_session"
|
31
|
+
end
|
32
|
+
|
33
|
+
def resource
|
34
|
+
"#{@span.get_tag(Ext::Test::TAG_FRAMEWORK)}.test_session.#{@span.get_tag(Ext::Test::TAG_COMMAND)}"
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def required_fields
|
40
|
+
REQUIRED_FIELDS
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
require_relative "../../ext/test"
|
5
|
+
|
6
|
+
module Datadog
|
7
|
+
module CI
|
8
|
+
module TestVisibility
|
9
|
+
module Serializers
|
10
|
+
class TestSuite < Base
|
11
|
+
CONTENT_FIELDS = (["test_session_id", "test_module_id", "test_suite_id"] + Base::CONTENT_FIELDS).freeze
|
12
|
+
|
13
|
+
CONTENT_MAP_SIZE = calculate_content_map_size(CONTENT_FIELDS)
|
14
|
+
|
15
|
+
REQUIRED_FIELDS = (["test_session_id", "test_module_id", "test_suite_id"] + Base::REQUIRED_FIELDS).freeze
|
16
|
+
|
17
|
+
def content_fields
|
18
|
+
CONTENT_FIELDS
|
19
|
+
end
|
20
|
+
|
21
|
+
def content_map_size
|
22
|
+
CONTENT_MAP_SIZE
|
23
|
+
end
|
24
|
+
|
25
|
+
def type
|
26
|
+
Ext::AppTypes::TYPE_TEST_SUITE
|
27
|
+
end
|
28
|
+
|
29
|
+
def name
|
30
|
+
"#{@span.get_tag(Ext::Test::TAG_FRAMEWORK)}.test_suite"
|
31
|
+
end
|
32
|
+
|
33
|
+
def resource
|
34
|
+
"#{@span.get_tag(Ext::Test::TAG_FRAMEWORK)}.test_suite.#{@span.get_tag(Ext::Test::TAG_SUITE)}"
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def required_fields
|
40
|
+
REQUIRED_FIELDS
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -8,25 +8,11 @@ module Datadog
|
|
8
8
|
module TestVisibility
|
9
9
|
module Serializers
|
10
10
|
class TestV1 < Base
|
11
|
-
CONTENT_FIELDS = [
|
12
|
-
"trace_id", "span_id",
|
13
|
-
"name", "resource", "service",
|
14
|
-
"error", "start", "duration",
|
15
|
-
"meta", "metrics",
|
16
|
-
"type" => "span_type"
|
17
|
-
].freeze
|
11
|
+
CONTENT_FIELDS = (["trace_id", "span_id"] + Base::CONTENT_FIELDS).freeze
|
18
12
|
|
19
13
|
CONTENT_MAP_SIZE = calculate_content_map_size(CONTENT_FIELDS)
|
20
14
|
|
21
|
-
REQUIRED_FIELDS = [
|
22
|
-
"trace_id",
|
23
|
-
"span_id",
|
24
|
-
"error",
|
25
|
-
"name",
|
26
|
-
"resource",
|
27
|
-
"start",
|
28
|
-
"duration"
|
29
|
-
].freeze
|
15
|
+
REQUIRED_FIELDS = (["trace_id", "span_id"] + Base::REQUIRED_FIELDS).freeze
|
30
16
|
|
31
17
|
def content_fields
|
32
18
|
CONTENT_FIELDS
|
@@ -37,7 +23,7 @@ module Datadog
|
|
37
23
|
end
|
38
24
|
|
39
25
|
def type
|
40
|
-
|
26
|
+
Ext::AppTypes::TYPE_TEST
|
41
27
|
end
|
42
28
|
|
43
29
|
def name
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "test_v1"
|
4
|
+
require_relative "../../ext/test"
|
5
|
+
|
6
|
+
module Datadog
|
7
|
+
module CI
|
8
|
+
module TestVisibility
|
9
|
+
module Serializers
|
10
|
+
class TestV2 < TestV1
|
11
|
+
CONTENT_FIELDS = (["test_session_id", "test_module_id", "test_suite_id"] + TestV1::CONTENT_FIELDS).freeze
|
12
|
+
|
13
|
+
CONTENT_MAP_SIZE = calculate_content_map_size(CONTENT_FIELDS)
|
14
|
+
|
15
|
+
REQUIRED_FIELDS = (["test_session_id", "test_module_id", "test_suite_id"] + TestV1::REQUIRED_FIELDS).freeze
|
16
|
+
|
17
|
+
def content_fields
|
18
|
+
CONTENT_FIELDS
|
19
|
+
end
|
20
|
+
|
21
|
+
def content_map_size
|
22
|
+
CONTENT_MAP_SIZE
|
23
|
+
end
|
24
|
+
|
25
|
+
def version
|
26
|
+
2
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def required_fields
|
32
|
+
REQUIRED_FIELDS
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -81,7 +81,7 @@ module Datadog
|
|
81
81
|
if spans.respond_to?(:filter_map)
|
82
82
|
spans.filter_map { |span| encode_span(trace, span) }
|
83
83
|
else
|
84
|
-
|
84
|
+
spans.map { |span| encode_span(trace, span) }.reject(&:nil?)
|
85
85
|
end
|
86
86
|
end
|
87
87
|
end
|
@@ -94,15 +94,15 @@ module Datadog
|
|
94
94
|
|
95
95
|
if encoded.size > max_payload_size
|
96
96
|
# This single event is too large, we can't flush it
|
97
|
-
Datadog.logger.
|
98
|
-
Datadog.logger.
|
97
|
+
Datadog.logger.warn("Dropping test event. Payload too large: '#{span.inspect}'")
|
98
|
+
Datadog.logger.warn(encoded)
|
99
99
|
|
100
100
|
return nil
|
101
101
|
end
|
102
102
|
|
103
103
|
encoded
|
104
104
|
else
|
105
|
-
Datadog.logger.
|
105
|
+
Datadog.logger.warn("Invalid event skipped: #{serializer} Errors: #{serializer.validation_errors}")
|
106
106
|
nil
|
107
107
|
end
|
108
108
|
end
|
data/lib/datadog/ci/version.rb
CHANGED
data/lib/datadog/ci.rb
CHANGED
@@ -10,16 +10,180 @@ module Datadog
|
|
10
10
|
# @public_api
|
11
11
|
module CI
|
12
12
|
class << self
|
13
|
+
# Starts a {Datadog::CI::TestSession ci_test_session} that represents the whole test session run.
|
14
|
+
#
|
15
|
+
# Read Datadog documentation on test sessions
|
16
|
+
# [here](https://docs.datadoghq.com/continuous_integration/explorer/?tab=testruns#sessions).
|
17
|
+
#
|
18
|
+
# Returns the existing test session if one is already active. There is at most a single test session per process.
|
19
|
+
#
|
20
|
+
# The {.start_test_session} method is used to mark the start of the test session:
|
21
|
+
# ```
|
22
|
+
# Datadog::CI.start_test_session(
|
23
|
+
# service: "my-web-site-tests",
|
24
|
+
# tags: { Datadog::CI::Ext::Test::TAG_FRAMEWORK => "my-test-framework" }
|
25
|
+
# )
|
26
|
+
#
|
27
|
+
# # Somewhere else after test run has ended
|
28
|
+
# Datadog::CI.active_test_session.finish
|
29
|
+
# ```
|
30
|
+
#
|
31
|
+
# Remember that calling {Datadog::CI::TestSession#finish} is mandatory.
|
32
|
+
#
|
33
|
+
# @param [String] service the service name for this session (optional, defaults to DD_SERVICE)
|
34
|
+
# @param [Hash<String,String>] tags extra tags which should be added to the test session.
|
35
|
+
# @return [Datadog::CI::TestSession] returns the active, running {Datadog::CI::TestSession}.
|
36
|
+
# @return [Datadog::CI::NullSpan] ci_span null object if CI visibility is disabled or if old Datadog agent is
|
37
|
+
# detected and test suite level visibility cannot be supported.
|
38
|
+
def start_test_session(service: nil, tags: {})
|
39
|
+
service ||= Datadog.configuration.service
|
40
|
+
recorder.start_test_session(service: service, tags: tags)
|
41
|
+
end
|
42
|
+
|
43
|
+
# The active, unfinished test session.
|
44
|
+
#
|
45
|
+
# Usage:
|
46
|
+
#
|
47
|
+
# ```
|
48
|
+
# # start a test session
|
49
|
+
# Datadog::CI.start_test_session(
|
50
|
+
# service: "my-web-site-tests",
|
51
|
+
# tags: { Datadog::CI::Ext::Test::TAG_FRAMEWORK => "my-test-framework" }
|
52
|
+
# )
|
53
|
+
#
|
54
|
+
# # somewhere else, access the session
|
55
|
+
# test_session = Datadog::CI.active_test_session
|
56
|
+
# test_session.finish
|
57
|
+
# ```
|
58
|
+
#
|
59
|
+
# @return [Datadog::CI::TestSession] the active test session
|
60
|
+
# @return [nil] if no test session is active
|
61
|
+
def active_test_session
|
62
|
+
recorder.active_test_session
|
63
|
+
end
|
64
|
+
|
65
|
+
# Starts a {Datadog::CI::TestModule ci_test_module} that represents a single test module (for most Ruby test frameworks
|
66
|
+
# module will correspond 1-1 to the test session).
|
67
|
+
#
|
68
|
+
# Read Datadog documentation on test modules
|
69
|
+
# [here](https://docs.datadoghq.com/continuous_integration/explorer/?tab=testruns#module).
|
70
|
+
#
|
71
|
+
# Returns the existing test session if one is already active. There is at most a single test module per process
|
72
|
+
# active at any given time.
|
73
|
+
#
|
74
|
+
# The {.start_test_module} method is used to mark the start of the test session:
|
75
|
+
# ```
|
76
|
+
# Datadog::CI.start_test_module(
|
77
|
+
# "my-module",
|
78
|
+
# service: "my-web-site-tests",
|
79
|
+
# tags: { Datadog::CI::Ext::Test::TAG_FRAMEWORK => "my-test-framework" }
|
80
|
+
# )
|
81
|
+
#
|
82
|
+
# # Somewhere else after the module has ended
|
83
|
+
# Datadog::CI.active_test_module.finish
|
84
|
+
# ```
|
85
|
+
#
|
86
|
+
# Remember that calling {Datadog::CI::TestModule#finish} is mandatory.
|
87
|
+
#
|
88
|
+
# @param [String] test_module_name the name for this module
|
89
|
+
# @param [String] service the service name for this session (optional, inherited from test session if not provided)
|
90
|
+
# @param [Hash<String,String>] tags extra tags which should be added to the test module (optional, some tags are inherited from test session).
|
91
|
+
# @return [Datadog::CI::TestModule] returns the active, running {Datadog::CI::TestModule}.
|
92
|
+
# @return [Datadog::CI::NullSpan] ci_span null object if CI visibility is disabled or if old Datadog agent is
|
93
|
+
# detected and test suite level visibility cannot be supported.
|
94
|
+
def start_test_module(test_module_name, service: nil, tags: {})
|
95
|
+
recorder.start_test_module(test_module_name, service: service, tags: tags)
|
96
|
+
end
|
97
|
+
|
98
|
+
# The active, unfinished test module.
|
99
|
+
#
|
100
|
+
# Usage:
|
101
|
+
#
|
102
|
+
# ```
|
103
|
+
# # start a test module
|
104
|
+
# Datadog::CI.start_test_module(
|
105
|
+
# "my-module",
|
106
|
+
# service: "my-web-site-tests",
|
107
|
+
# tags: { Datadog::CI::Ext::Test::TAG_FRAMEWORK => "my-test-framework" }
|
108
|
+
# )
|
109
|
+
#
|
110
|
+
# # somewhere else, access the current module
|
111
|
+
# test_module = Datadog::CI.active_test_module
|
112
|
+
# test_module.finish
|
113
|
+
# ```
|
114
|
+
#
|
115
|
+
# @return [Datadog::CI::TestModule] the active test module
|
116
|
+
# @return [nil] if no test module is active
|
117
|
+
def active_test_module
|
118
|
+
recorder.active_test_module
|
119
|
+
end
|
120
|
+
|
121
|
+
# Starts a {Datadog::CI::TestSuite ci_test_suite} that represents a single test suite.
|
122
|
+
# If a test suite with given name is running, returns the existing test suite.
|
123
|
+
#
|
124
|
+
# Read Datadog documentation on test suites
|
125
|
+
# [here](https://docs.datadoghq.com/continuous_integration/explorer/?tab=testruns#module).
|
126
|
+
#
|
127
|
+
# The {.start_test_suite} method is used to mark the start of a test suite:
|
128
|
+
# ```
|
129
|
+
# Datadog::CI.start_test_suite(
|
130
|
+
# "calculator_tests",
|
131
|
+
# service: "my-web-site-tests",
|
132
|
+
# tags: { Datadog::CI::Ext::Test::TAG_FRAMEWORK => "my-test-framework" }
|
133
|
+
# )
|
134
|
+
#
|
135
|
+
# # Somewhere else after the suite has ended
|
136
|
+
# Datadog::CI.active_test_suite("calculator_tests").finish
|
137
|
+
# ```
|
138
|
+
#
|
139
|
+
# Remember that calling {Datadog::CI::TestSuite#finish} is mandatory.
|
140
|
+
#
|
141
|
+
# @param [String] test_suite_name the name of the test suite
|
142
|
+
# @param [String] service the service name for this test suite (optional, inherited from test session if not provided)
|
143
|
+
# @param [Hash<String,String>] tags extra tags which should be added to the test module (optional, some tags are inherited from test session)
|
144
|
+
# @return [Datadog::CI::TestSuite] returns the active, running {Datadog::CI::TestSuite}.
|
145
|
+
# @return [Datadog::CI::NullSpan] ci_span null object if CI visibility is disabled or if old Datadog agent is
|
146
|
+
# detected and test suite level visibility cannot be supported.
|
147
|
+
def start_test_suite(test_suite_name, service: nil, tags: {})
|
148
|
+
recorder.start_test_suite(test_suite_name, service: service, tags: tags)
|
149
|
+
end
|
150
|
+
|
151
|
+
# The active, unfinished test suite.
|
152
|
+
#
|
153
|
+
# Usage:
|
154
|
+
#
|
155
|
+
# ```
|
156
|
+
# # start a test suite
|
157
|
+
# Datadog::CI.start_test_suite(
|
158
|
+
# "calculator_tests",
|
159
|
+
# service: "my-web-site-tests",
|
160
|
+
# tags: { Datadog::CI::Ext::Test::TAG_FRAMEWORK => "my-test-framework" }
|
161
|
+
# )
|
162
|
+
#
|
163
|
+
# # Somewhere else after the suite has ended
|
164
|
+
# test_suite = Datadog::CI.active_test_suite("calculator_tests")
|
165
|
+
# test_suite.finish
|
166
|
+
# ```
|
167
|
+
#
|
168
|
+
# @return [Datadog::CI::TestSuite] the active test suite
|
169
|
+
# @return [nil] if no test suite with given name is active
|
170
|
+
def active_test_suite(test_suite_name)
|
171
|
+
recorder.active_test_suite(test_suite_name)
|
172
|
+
end
|
173
|
+
|
13
174
|
# Return a {Datadog::CI::Test ci_test} that will trace a test called `test_name`.
|
14
175
|
# Raises an error if a test is already active.
|
176
|
+
# If there is an active test session, the new test will be connected to the session.
|
177
|
+
# The test will inherit service name and tags from the running test session if not provided
|
178
|
+
# in parameters.
|
15
179
|
#
|
16
180
|
# You could trace your test using a <tt>do-block</tt> like:
|
17
181
|
#
|
18
182
|
# ```
|
19
183
|
# Datadog::CI.trace_test(
|
20
184
|
# "test_add_two_numbers",
|
21
|
-
#
|
22
|
-
#
|
185
|
+
# "calculator_tests",
|
186
|
+
# service: "my-web-site-tests",
|
23
187
|
# tags: { Datadog::CI::Ext::Test::TAG_FRAMEWORK => "my-test-framework" }
|
24
188
|
# ) do |ci_test|
|
25
189
|
# result = run_test
|
@@ -32,60 +196,59 @@ module Datadog
|
|
32
196
|
# end
|
33
197
|
# ```
|
34
198
|
#
|
35
|
-
# The {
|
199
|
+
# The {.trace_test} method can also be used without a block in this way:
|
36
200
|
# ```
|
37
201
|
# ci_test = Datadog::CI.trace_test(
|
38
|
-
# "test_add_two_numbers
|
202
|
+
# "test_add_two_numbers",
|
203
|
+
# "calculator_tests",
|
39
204
|
# service: "my-web-site-tests",
|
40
|
-
# operation_name: "test",
|
41
205
|
# tags: { Datadog::CI::Ext::Test::TAG_FRAMEWORK => "my-test-framework" }
|
42
206
|
# )
|
43
|
-
#
|
207
|
+
# # ... run test here ...
|
44
208
|
# ci_test.finish
|
45
209
|
# ```
|
46
210
|
#
|
47
211
|
# Remember that in this case, calling {Datadog::CI::Test#finish} is mandatory.
|
48
212
|
#
|
49
213
|
# @param [String] test_name {Datadog::CI::Test} name (example: "test_add_two_numbers").
|
50
|
-
# @param [String]
|
51
|
-
# @param [String]
|
214
|
+
# @param [String] test_suite_name name of test suite this test belongs to (example: "CalculatorTest").
|
215
|
+
# @param [String] service the service name for this test (optional, inherited from test session if not provided)
|
52
216
|
# @param [Hash<String,String>] tags extra tags which should be added to the test.
|
53
217
|
# @return [Object] If a block is provided, returns the result of the block execution.
|
54
218
|
# @return [Datadog::CI::Test] If no block is provided, returns the active,
|
55
219
|
# unfinished {Datadog::CI::Test}.
|
56
|
-
# @
|
220
|
+
# @return [Datadog::CI::NullSpan] ci_span null object if CI visibility is disabled
|
221
|
+
# @yield Optional block where newly created {Datadog::CI::Test} captures the execution.
|
57
222
|
# @yieldparam [Datadog::CI::Test] ci_test the newly created and active [Datadog::CI::Test]
|
58
|
-
#
|
59
|
-
|
60
|
-
|
61
|
-
recorder.trace_test(test_name, service_name: service_name, operation_name: operation_name, tags: tags, &block)
|
223
|
+
# @yieldparam [Datadog::CI::NullSpan] ci_span null object if CI visibility is disabled
|
224
|
+
def trace_test(test_name, test_suite_name, service: nil, tags: {}, &block)
|
225
|
+
recorder.trace_test(test_name, test_suite_name, service: service, tags: tags, &block)
|
62
226
|
end
|
63
227
|
|
64
|
-
# Same as {
|
228
|
+
# Same as {.trace_test} but it does not accept a block.
|
65
229
|
# Raises an error if a test is already active.
|
66
230
|
#
|
67
231
|
# Usage:
|
68
232
|
#
|
69
233
|
# ```
|
70
234
|
# ci_test = Datadog::CI.start_test(
|
71
|
-
# "test_add_two_numbers
|
235
|
+
# "test_add_two_numbers",
|
236
|
+
# "calculator_tests",
|
72
237
|
# service: "my-web-site-tests",
|
73
|
-
# operation_name: "test",
|
74
238
|
# tags: { Datadog::CI::Ext::Test::TAG_FRAMEWORK => "my-test-framework" }
|
75
239
|
# )
|
76
|
-
#
|
240
|
+
# # ... run test here ...
|
77
241
|
# ci_test.finish
|
78
242
|
# ```
|
79
243
|
#
|
80
244
|
# @param [String] test_name {Datadog::CI::Test} name (example: "test_add_two_numbers").
|
81
|
-
# @param [String]
|
82
|
-
# @param [String]
|
245
|
+
# @param [String] test_suite_name name of test suite this test belongs to (example: "CalculatorTest").
|
246
|
+
# @param [String] service the service name for this span (optional, inherited from test session if not provided)
|
83
247
|
# @param [Hash<String,String>] tags extra tags which should be added to the test.
|
84
248
|
# @return [Datadog::CI::Test] Returns the active, unfinished {Datadog::CI::Test}.
|
85
|
-
#
|
86
|
-
|
87
|
-
|
88
|
-
recorder.trace_test(test_name, service_name: service_name, operation_name: operation_name, tags: tags)
|
249
|
+
# @return [Datadog::CI::NullSpan] ci_span null object if CI visibility is disabled
|
250
|
+
def start_test(test_name, test_suite_name, service: nil, tags: {})
|
251
|
+
recorder.trace_test(test_name, test_suite_name, service: service, tags: tags)
|
89
252
|
end
|
90
253
|
|
91
254
|
# Trace any custom span inside a test. For example, you could trace:
|
@@ -93,7 +256,7 @@ module Datadog
|
|
93
256
|
# - database query
|
94
257
|
# - any custom operation you want to see in your trace view
|
95
258
|
#
|
96
|
-
# You can use
|
259
|
+
# You can use this method with a <tt>do-block</tt> like:
|
97
260
|
#
|
98
261
|
# ```
|
99
262
|
# Datadog::CI.trace(
|
@@ -105,14 +268,14 @@ module Datadog
|
|
105
268
|
# end
|
106
269
|
# ```
|
107
270
|
#
|
108
|
-
# The {
|
271
|
+
# The {.trace} method can also be used without a block in this way:
|
109
272
|
# ```
|
110
273
|
# ci_span = Datadog::CI.trace(
|
111
274
|
# "step",
|
112
275
|
# "Given I have 42 cucumbers",
|
113
276
|
# tags: {}
|
114
277
|
# )
|
115
|
-
#
|
278
|
+
# # ... run test here ...
|
116
279
|
# ci_span.finish
|
117
280
|
# ```
|
118
281
|
# Remember that in this case, calling {Datadog::CI::Span#finish} is mandatory.
|
@@ -123,10 +286,10 @@ module Datadog
|
|
123
286
|
# @return [Object] If a block is provided, returns the result of the block execution.
|
124
287
|
# @return [Datadog::CI::Span] If no block is provided, returns the active,
|
125
288
|
# unfinished {Datadog::CI::Span}.
|
126
|
-
# @
|
289
|
+
# @return [Datadog::CI::NullSpan] ci_span null object if CI visibility is disabled
|
290
|
+
# @yield Optional block where newly created {Datadog::CI::Span} captures the execution.
|
127
291
|
# @yieldparam [Datadog::CI::Span] ci_span the newly created and active [Datadog::CI::Span]
|
128
|
-
#
|
129
|
-
# @public_api
|
292
|
+
# @yieldparam [Datadog::CI::NullSpan] ci_span null object if CI visibility is disabled
|
130
293
|
def trace(span_type, span_name, tags: {}, &block)
|
131
294
|
recorder.trace(span_type, span_name, tags: tags, &block)
|
132
295
|
end
|
@@ -166,9 +329,9 @@ module Datadog
|
|
166
329
|
# ```
|
167
330
|
# # start a test
|
168
331
|
# Datadog::CI.start_test(
|
169
|
-
# "test_add_two_numbers
|
332
|
+
# "test_add_two_numbers",
|
333
|
+
# "calculator_tests",
|
170
334
|
# service: "my-web-site-tests",
|
171
|
-
# operation_name: "test",
|
172
335
|
# tags: { Datadog::CI::Ext::Test::TAG_FRAMEWORK => "my-test-framework" }
|
173
336
|
# )
|
174
337
|
#
|
@@ -184,11 +347,30 @@ module Datadog
|
|
184
347
|
recorder.active_test
|
185
348
|
end
|
186
349
|
|
187
|
-
# Internal only, to finish a test use Datadog::CI::Test#finish
|
350
|
+
# Internal only, to finish a test use {Datadog::CI::Test#finish}
|
351
|
+
# @private
|
188
352
|
def deactivate_test(test)
|
189
353
|
recorder.deactivate_test(test)
|
190
354
|
end
|
191
355
|
|
356
|
+
# Internal only, to finish a test session use {Datadog::CI::TestSession#finish}
|
357
|
+
# @private
|
358
|
+
def deactivate_test_session
|
359
|
+
recorder.deactivate_test_session
|
360
|
+
end
|
361
|
+
|
362
|
+
# Internal only, to finish a test module use {Datadog::CI::TestModule#finish}
|
363
|
+
# @private
|
364
|
+
def deactivate_test_module
|
365
|
+
recorder.deactivate_test_module
|
366
|
+
end
|
367
|
+
|
368
|
+
# Internal only, to finish a test suite use {Datadog::CI::TestSuite#finish}
|
369
|
+
# @private
|
370
|
+
def deactivate_test_suite(test_suite_name)
|
371
|
+
recorder.deactivate_test_suite(test_suite_name)
|
372
|
+
end
|
373
|
+
|
192
374
|
private
|
193
375
|
|
194
376
|
def components
|