Class: RSpecTelemetry::Trace::Viewer::Document
- Inherits:
-
Object
- Object
- RSpecTelemetry::Trace::Viewer::Document
- Defined in:
- lib/rspec_telemetry/trace/viewer/document.rb
Overview
Incrementally folds an NDJSON trace into examples and their child events.
Defined Under Namespace
Constant Summary collapse
- FAILED_STATUSES =
The single source of truth for which statuses count as failures.
%w[failed error].freeze
- INFRA_FIELDS =
Hidden from generic labels/details; the original fields remain on each event.
%w[type seq op action wall_ms t timestamp monotonic_time pid thread_id].freeze
Instance Attribute Summary collapse
-
#end_wall_ms ⇒ Object
readonly
Returns the value of attribute end_wall_ms.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#example_count ⇒ Object
readonly
Returns the value of attribute example_count.
-
#failed_action ⇒ Object
readonly
Returns the value of attribute failed_action.
-
#failure_count ⇒ Object
readonly
Returns the value of attribute failure_count.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#pending_count ⇒ Object
readonly
Returns the value of attribute pending_count.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
-
#wall_time ⇒ Object
readonly
Returns the value of attribute wall_time.
Class Method Summary collapse
Instance Method Summary collapse
- #action(seq) ⇒ Object
- #actions ⇒ Object
-
#apply(line) ⇒ Object
Unknown future event types are kept as generic events instead of dropped.
- #events ⇒ Object
- #events_for(action_seq) ⇒ Object
-
#initialize ⇒ Document
constructor
A new instance of Document.
- #pending? ⇒ Boolean
- #status ⇒ Object
Constructor Details
#initialize ⇒ Document
Returns a new instance of Document.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rspec_telemetry/trace/viewer/document.rb', line 39 def initialize @entries = [] @actions_by_seq = {} @action_by_example = {} @current_action = nil @seq = -1 @t0 = nil @started = false @ended = false @status = nil end |
Instance Attribute Details
#end_wall_ms ⇒ Object (readonly)
Returns the value of attribute end_wall_ms.
22 23 24 |
# File 'lib/rspec_telemetry/trace/viewer/document.rb', line 22 def end_wall_ms @end_wall_ms end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
22 23 24 |
# File 'lib/rspec_telemetry/trace/viewer/document.rb', line 22 def entries @entries end |
#example_count ⇒ Object (readonly)
Returns the value of attribute example_count.
22 23 24 |
# File 'lib/rspec_telemetry/trace/viewer/document.rb', line 22 def example_count @example_count end |
#failed_action ⇒ Object (readonly)
Returns the value of attribute failed_action.
22 23 24 |
# File 'lib/rspec_telemetry/trace/viewer/document.rb', line 22 def failed_action @failed_action end |
#failure_count ⇒ Object (readonly)
Returns the value of attribute failure_count.
22 23 24 |
# File 'lib/rspec_telemetry/trace/viewer/document.rb', line 22 def failure_count @failure_count end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
22 23 24 |
# File 'lib/rspec_telemetry/trace/viewer/document.rb', line 22 def level @level end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
22 23 24 |
# File 'lib/rspec_telemetry/trace/viewer/document.rb', line 22 def @metadata end |
#pending_count ⇒ Object (readonly)
Returns the value of attribute pending_count.
22 23 24 |
# File 'lib/rspec_telemetry/trace/viewer/document.rb', line 22 def pending_count @pending_count end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
22 23 24 |
# File 'lib/rspec_telemetry/trace/viewer/document.rb', line 22 def version @version end |
#wall_time ⇒ Object (readonly)
Returns the value of attribute wall_time.
22 23 24 |
# File 'lib/rspec_telemetry/trace/viewer/document.rb', line 22 def wall_time @wall_time end |
Class Method Details
.from_lines(lines) ⇒ Object
35 36 37 |
# File 'lib/rspec_telemetry/trace/viewer/document.rb', line 35 def self.from_lines(lines) lines.each_with_object(new) { |line, doc| doc.apply(line) } end |
Instance Method Details
#action(seq) ⇒ Object
81 |
# File 'lib/rspec_telemetry/trace/viewer/document.rb', line 81 def action(seq) = @actions_by_seq[seq] |
#actions ⇒ Object
79 |
# File 'lib/rspec_telemetry/trace/viewer/document.rb', line 79 def actions = @entries.grep(Action) |
#apply(line) ⇒ Object
Unknown future event types are kept as generic events instead of dropped.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rspec_telemetry/trace/viewer/document.rb', line 52 def apply(line) parsed = parse(line) return self unless parsed.is_a?(Hash) @started = true set_origin(parsed) case parsed["type"] when nil self when "example.started" open_action(parsed) when "example.finished" close_action(parsed) when "factory_bot.run_factory" record("factory", parsed) when "suite.finished" finish(parsed) else record(parsed["type"], parsed) end self end |
#events ⇒ Object
77 |
# File 'lib/rspec_telemetry/trace/viewer/document.rb', line 77 def events = @entries.grep(Event) |
#events_for(action_seq) ⇒ Object
83 84 85 |
# File 'lib/rspec_telemetry/trace/viewer/document.rb', line 83 def events_for(action_seq) @entries.select { |entry| entry.is_a?(Event) && entry.action == action_seq } end |
#pending? ⇒ Boolean
87 |
# File 'lib/rspec_telemetry/trace/viewer/document.rb', line 87 def pending? = @started && !@ended |
#status ⇒ Object
89 90 91 92 93 94 |
# File 'lib/rspec_telemetry/trace/viewer/document.rb', line 89 def status return @status if @status return "ok" if @ended "pending" end |