@@ -10,8 +10,59 @@ module Datadog
10
10
# @public_api
11
11
module CI
12
12
class << self
13
+ # Return a {Datadog::CI::TestSesstion ci_test_session} that represents the whole test session run.
14
+ # Raises an error if a session is already active.
15
+ #
16
+ # The {#start_test_session} method is used to mark the start of the test session:
17
+ # ```
18
+ # Datadog::CI.start_test_session(
19
+ # service: "my-web-site-tests",
20
+ # tags: { Datadog::CI::Ext::Test::TAG_FRAMEWORK => "my-test-framework" }
21
+ # )
22
+ #
23
+ # # Somewhere else after test run has ended
24
+ # Datadog::CI.active_test_session.finish
25
+ # ```
26
+ #
27
+ # Remember that calling {Datadog::CI::TestSession#finish} is mandatory.
28
+ #
29
+ # @param [String] service_name the service name for this session
30
+ # @param [Hash<String,String>] tags extra tags which should be added to the test.
31
+ # @return [Datadog::CI::TestSession] returns the active, running {Datadog::CI::TestSession}.
32
+ # @return [nil] if test suite level visibility is disabled (old Datadog agent detected)
33
+ #
34
+ # @public_api
35
+ def start_test_session ( service_name : nil , tags : { } )
36
+ recorder . start_test_session ( service_name : service_name , tags : tags )
37
+ end
38
+
39
+ # The active, unfinished test session span.
40
+ #
41
+ # Usage:
42
+ #
43
+ # ```
44
+ # # start a test session
45
+ # Datadog::CI.start_test_session(
46
+ # service: "my-web-site-tests",
47
+ # tags: { Datadog::CI::Ext::Test::TAG_FRAMEWORK => "my-test-framework" }
48
+ # )
49
+ #
50
+ # # somewhere else, access the session
51
+ # test_session = Datadog::CI.active_test_session
52
+ # test_session.finish
53
+ # ```
54
+ #
55
+ # @return [Datadog::CI::TestSession] the active test session
56
+ # @return [nil] if no test session is active
57
+ def active_test_session
58
+ recorder . active_test_session
59
+ end
60
+
13
61
# Return a {Datadog::CI::Test ci_test} that will trace a test called `test_name`.
14
62
# Raises an error if a test is already active.
63
+ # If there is an active test session, the new test will be connected to the session.
64
+ # The test will inherit service name and tags from the running test session if not provided
65
+ # in parameters.
15
66
#
16
67
# You could trace your test using a <tt>do-block</tt> like:
17
68
#
@@ -189,6 +240,11 @@ def deactivate_test(test)
189
240
recorder . deactivate_test ( test )
190
241
end
191
242
243
+ # Internal only, to finish a test session use Datadog::CI::TestSession#finish
244
+ def deactivate_test_session
245
+ recorder . deactivate_test_session
246
+ end
247
+
192
248
private
193
249
194
250
def components
0 commit comments