21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/datadog/ci/contrib/rspec/example.rb', line 21
def run(*args)
return super if ::RSpec.configuration.dry_run? && !datadog_configuration[:dry_run_enabled]
return super unless datadog_configuration[:enabled]
test_suite_span = test_visibility_component.start_test_suite(datadog_test_suite_name) if ci_queue?
@skip_reporting = true
tags = {
CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
CI::Ext::Test::TAG_FRAMEWORK_VERSION => datadog_integration.version.to_s,
CI::Ext::Test::TAG_SOURCE_FILE => Git::LocalRepository.relative_to_root(metadata[:file_path]),
CI::Ext::Test::TAG_SOURCE_START => metadata[:line_number].to_s,
CI::Ext::Test::TAG_PARAMETERS => datadog_test_parameters
}
end_line = Utils::SourceCode.last_line(@example_block)
tags[CI::Ext::Test::TAG_SOURCE_END] = end_line.to_s if end_line
test_retries_component.with_retries do
test_visibility_component.trace_test(
datadog_test_name,
datadog_test_suite_name,
tags: tags,
service: datadog_configuration[:service_name]
) do |test_span|
test_span&.itr_unskippable! if datadog_unskippable?
metadata[:skip] = test_span&.datadog_skip_reason if test_span&.should_skip?
@exception = nil
result = super
return result if ::RSpec.world.wants_to_quit
case execution_result.status
when :passed
test_span&.passed!
when :failed
test_span&.failed!(exception: execution_result.exception)
@exception = nil if test_span&.should_ignore_failures?
else
test_span&.skipped!(
reason: execution_result.pending_message,
exception: execution_result.pending_exception
)
end
if datadog_configuration[:datadog_formatter_enabled]
if test_span&.is_retry?
metadata[Ext::METADATA_DD_RETRIES] ||= 0
metadata[Ext::METADATA_DD_RETRY_RESULTS] ||= Hash.new(0)
metadata[Ext::METADATA_DD_RETRIES] += 1
metadata[Ext::METADATA_DD_RETRY_REASON] = test_span&.retry_reason
metadata[Ext::METADATA_DD_RETRY_RESULTS][test_span&.status] += 1
end
metadata[Ext::METADATA_DD_QUARANTINED] = true if test_span&.quarantined?
metadata[Ext::METADATA_DD_DISABLED] = true if test_span&.disabled?
if test_span&.skipped_by_test_impact_analysis?
metadata[Ext::METADATA_DD_SKIPPED_BY_ITR] = true
end
end
end
end
test_suite_span&.finish
@skip_reporting = false
finish(reporter)
end
|