Class: Buildkite::TestCollector::RSpecPlugin::Trace
- Defined in:
- lib/buildkite/test_collector/rspec_plugin/trace.rb
Constant Summary collapse
- FILE_PATH_REGEX =
/^(.*?\.(rb|feature))/
Instance Attribute Summary collapse
-
#example ⇒ Object
Returns the value of attribute example.
-
#failure_expanded ⇒ Object
Returns the value of attribute failure_expanded.
-
#failure_reason ⇒ Object
Returns the value of attribute failure_reason.
-
#history ⇒ Object
Returns the value of attribute history.
-
#location_prefix ⇒ Object
readonly
Returns the value of attribute location_prefix.
-
#otel_end_timestamp ⇒ Object
Left open by the around hook; Reporter finishes it once RSpec settles the example's result.
-
#otel_span ⇒ Object
Left open by the around hook; Reporter finishes it once RSpec settles the example's result.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Attributes inherited from Trace
Instance Method Summary collapse
-
#initialize(example, history:, failure_reason: nil, failure_expanded: [], tags: nil, location_prefix: nil, external_id: nil) ⇒ Trace
constructor
A new instance of Trace.
-
#otel_attributes ⇒ Object
What the span says about the test itself.
- #otel_exception_events ⇒ Object
- #otel_failure_reason ⇒ Object
- #result ⇒ Object (also: #otel_result)
Methods inherited from Trace
Constructor Details
#initialize(example, history:, failure_reason: nil, failure_expanded: [], tags: nil, location_prefix: nil, external_id: nil) ⇒ Trace
Returns a new instance of Trace.
17 18 19 20 21 22 23 24 25 |
# File 'lib/buildkite/test_collector/rspec_plugin/trace.rb', line 17 def initialize(example, history:, failure_reason: nil, failure_expanded: [], tags: nil, location_prefix: nil, external_id: nil) @example = example @history = history @failure_reason = failure_reason @failure_expanded = @tags = @location_prefix = location_prefix @external_id = external_id end |
Instance Attribute Details
#example ⇒ Object
Returns the value of attribute example.
5 6 7 |
# File 'lib/buildkite/test_collector/rspec_plugin/trace.rb', line 5 def example @example end |
#failure_expanded ⇒ Object
Returns the value of attribute failure_expanded.
5 6 7 |
# File 'lib/buildkite/test_collector/rspec_plugin/trace.rb', line 5 def @failure_expanded end |
#failure_reason ⇒ Object
Returns the value of attribute failure_reason.
5 6 7 |
# File 'lib/buildkite/test_collector/rspec_plugin/trace.rb', line 5 def failure_reason @failure_reason end |
#history ⇒ Object
Returns the value of attribute history.
11 12 13 |
# File 'lib/buildkite/test_collector/rspec_plugin/trace.rb', line 11 def history @history end |
#location_prefix ⇒ Object (readonly)
Returns the value of attribute location_prefix.
13 14 15 |
# File 'lib/buildkite/test_collector/rspec_plugin/trace.rb', line 13 def location_prefix @location_prefix end |
#otel_end_timestamp ⇒ Object
Left open by the around hook; Reporter finishes it once RSpec settles the example's result.
9 10 11 |
# File 'lib/buildkite/test_collector/rspec_plugin/trace.rb', line 9 def @otel_end_timestamp end |
#otel_span ⇒ Object
Left open by the around hook; Reporter finishes it once RSpec settles the example's result.
9 10 11 |
# File 'lib/buildkite/test_collector/rspec_plugin/trace.rb', line 9 def otel_span @otel_span end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
12 13 14 |
# File 'lib/buildkite/test_collector/rspec_plugin/trace.rb', line 12 def @tags end |
Instance Method Details
#otel_attributes ⇒ Object
What the span says about the test itself. OTel adds the submission marker and run metadata that describe every test span.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/buildkite/test_collector/rspec_plugin/trace.rb', line 40 def otel_attributes attributes = { "buildkite.test.scope" => strip_invalid_utf8_chars(scope), "buildkite.test.name" => strip_invalid_utf8_chars(name), "test.case.name" => strip_invalid_utf8_chars(example.full_description), "test.suite.name" => strip_invalid_utf8_chars(scope), "code.file.path" => strip_invalid_utf8_chars(prepend_location_prefix(file_name)), "code.line.number" => source_line_number, } attributes["buildkite.test.execution.external_id"] = external_id if external_id prefix = Buildkite::TestCollector::OTel::TAG_ATTRIBUTE_PREFIX &.each do |key, value| attributes["#{prefix}#{key}"] = strip_invalid_utf8_chars(value.to_s) end attributes end |
#otel_exception_events ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/buildkite/test_collector/rspec_plugin/trace.rb', line 61 def otel_exception_events ( || []).filter_map do |failure| = Array(failure[:expanded]).join("\n") stacktrace = Array(failure[:backtrace]).join("\n") attributes = {} attributes["exception.message"] = strip_invalid_utf8_chars() unless .empty? attributes["exception.stacktrace"] = strip_invalid_utf8_chars(stacktrace) unless stacktrace.empty? attributes unless attributes.empty? end end |
#otel_failure_reason ⇒ Object
57 58 59 |
# File 'lib/buildkite/test_collector/rspec_plugin/trace.rb', line 57 def otel_failure_reason strip_invalid_utf8_chars(failure_reason) if failure_reason end |
#result ⇒ Object Also known as: otel_result
27 28 29 30 31 32 33 |
# File 'lib/buildkite/test_collector/rspec_plugin/trace.rb', line 27 def result case example.execution_result.status when :passed; "passed" when :failed; "failed" when :pending; "skipped" end end |