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
readonly
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_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
-
#otel_result ⇒ Object
Read at reporter time, when the result is final.
- #result ⇒ Object
Methods inherited from Trace
Constructor Details
#initialize(example, history:, failure_reason: nil, failure_expanded: [], tags: nil, location_prefix: nil, external_id: nil, trace_id: nil) ⇒ Trace
Returns a new instance of Trace.
17 18 19 20 21 22 23 24 25 26 |
# 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, trace_id: nil) @example = example @history = history @failure_reason = failure_reason @failure_expanded = @tags = @location_prefix = location_prefix @external_id = external_id @trace_id = trace_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 (readonly)
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. The two OTel modes use the same attributes; buildkite.execution.via is the sole synthesis opt-in.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/buildkite/test_collector/rspec_plugin/trace.rb', line 43 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.execution.via"] = "otlp" if Buildkite::TestCollector.otel_only? attributes["buildkite.test.execution.external_id"] = external_id if external_id &.each do |key, value| attributes["buildkite.tag.#{key}"] = strip_invalid_utf8_chars(value.to_s) end attributes end |
#otel_exception_events ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/buildkite/test_collector/rspec_plugin/trace.rb', line 64 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
60 61 62 |
# File 'lib/buildkite/test_collector/rspec_plugin/trace.rb', line 60 def otel_failure_reason strip_invalid_utf8_chars(failure_reason) if failure_reason end |
#otel_result ⇒ Object
Read at reporter time, when the result is final.
37 38 39 |
# File 'lib/buildkite/test_collector/rspec_plugin/trace.rb', line 37 def otel_result result end |
#result ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/buildkite/test_collector/rspec_plugin/trace.rb', line 28 def result case example.execution_result.status when :passed; "passed" when :failed; "failed" when :pending; "skipped" end end |