@@ -21,38 +21,21 @@ def run(*args)
21
21
return super if ::RSpec . configuration . dry_run? && !datadog_configuration [ :dry_run_enabled ]
22
22
return super unless datadog_configuration [ :enabled ]
23
23
24
- test_name = full_description . strip
25
- if metadata [ :description ] . empty?
26
- # for unnamed it blocks this appends something like "example at ./spec/some_spec.rb:10"
27
- test_name << " #{ description } "
28
- end
29
-
30
- test_suite_description = fetch_top_level_example_group [ :description ]
31
- suite_name = "#{ test_suite_description } at #{ metadata [ :example_group ] [ :rerun_file_path ] } "
32
-
33
- # remove example group description from test name to avoid duplication
34
- test_name = test_name . sub ( test_suite_description , "" ) . strip
35
-
36
- if ci_queue?
37
- suite_name = "#{ suite_name } (ci-queue running example [#{ test_name } ])"
38
- ci_queue_test_span = test_visibility_component . start_test_suite ( suite_name )
39
- end
24
+ test_suite_span = test_visibility_component . start_test_suite ( datadog_test_suite_name ) if ci_queue?
40
25
41
26
# don't report test to RSpec::Core::Reporter until retries are done
42
27
@skip_reporting = true
43
28
44
29
test_retries_component . with_retries do
45
30
test_visibility_component . trace_test (
46
- test_name ,
47
- suite_name ,
31
+ datadog_test_name ,
32
+ datadog_test_suite_name ,
48
33
tags : {
49
34
CI ::Ext ::Test ::TAG_FRAMEWORK => Ext ::FRAMEWORK ,
50
35
CI ::Ext ::Test ::TAG_FRAMEWORK_VERSION => datadog_integration . version . to_s ,
51
36
CI ::Ext ::Test ::TAG_SOURCE_FILE => Git ::LocalRepository . relative_to_root ( metadata [ :file_path ] ) ,
52
37
CI ::Ext ::Test ::TAG_SOURCE_START => metadata [ :line_number ] . to_s ,
53
- CI ::Ext ::Test ::TAG_PARAMETERS => Utils ::TestRun . test_parameters (
54
- metadata : { "scoped_id" => metadata [ :scoped_id ] }
55
- )
38
+ CI ::Ext ::Test ::TAG_PARAMETERS => datadog_test_parameters
56
39
} ,
57
40
service : datadog_configuration [ :service_name ]
58
41
) do |test_span |
@@ -87,8 +70,8 @@ def run(*args)
87
70
end
88
71
end
89
72
90
- # this is a special case for ci-queue, we need to finish the test suite span
91
- ci_queue_test_span &.finish
73
+ # this is a special case for ci-queue, we need to finish the test suite span created for a single test
74
+ test_suite_span &.finish
92
75
93
76
# after retries are done, we can finally report the test to RSpec
94
77
@skip_reporting = false
@@ -129,6 +112,45 @@ def datadog_configuration
129
112
Datadog . configuration . ci [ :rspec ]
130
113
end
131
114
115
+ def datadog_test_suite_description
116
+ @datadog_test_suite_description ||= fetch_top_level_example_group [ :description ]
117
+ end
118
+
119
+ def datadog_test_name
120
+ return @datadog_test_name if defined? ( @datadog_test_name )
121
+
122
+ test_name = full_description . strip
123
+ if metadata [ :description ] . empty?
124
+ # for unnamed it blocks this appends something like "example at ./spec/some_spec.rb:10"
125
+ test_name << " #{ description } "
126
+ end
127
+
128
+ # remove example group description from test name to avoid duplication
129
+ test_name = test_name . sub ( datadog_test_suite_description , "" ) . strip
130
+
131
+ @datadog_test_name = test_name
132
+ end
133
+
134
+ def datadog_test_suite_name
135
+ return @datadog_test_suite_name if defined? ( @datadog_test_suite_name )
136
+
137
+ suite_name = "#{ datadog_test_suite_description } at #{ metadata [ :example_group ] [ :rerun_file_path ] } "
138
+
139
+ if ci_queue?
140
+ suite_name = "#{ suite_name } (ci-queue running example [#{ datadog_test_name } ])"
141
+ end
142
+
143
+ @datadog_test_suite_name = suite_name
144
+ end
145
+
146
+ def datadog_test_parameters
147
+ return @datadog_test_parameters if defined? ( @datadog_test_parameters )
148
+
149
+ @datadog_test_parameters = Utils ::TestRun . test_parameters (
150
+ metadata : { "scoped_id" => metadata [ :scoped_id ] }
151
+ )
152
+ end
153
+
132
154
def test_visibility_component
133
155
Datadog . send ( :components ) . test_visibility
134
156
end
0 commit comments