Class: RSpecTelemetry::Recorder
- Inherits:
-
Object
- Object
- RSpecTelemetry::Recorder
- Defined in:
- lib/rspec_telemetry/recorder.rb
Constant Summary collapse
- EXAMPLE_ID =
FactoryBot notifications read this to attach themselves to the active example.
:rspec_telemetry_example_id
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
Class Method Summary collapse
Instance Method Summary collapse
- #clear_current_example ⇒ Object
- #common_fields(type) ⇒ Object
- #finish ⇒ Object
- #flush ⇒ Object
-
#initialize(config, writer: nil, summary: nil) ⇒ Recorder
constructor
A new instance of Recorder.
- #record(type, fields = {}) ⇒ Object
- #set_current_example(id) ⇒ Object
- #start ⇒ Object
- #started? ⇒ Boolean
Constructor Details
#initialize(config, writer: nil, summary: nil) ⇒ Recorder
Returns a new instance of Recorder.
12 13 14 15 16 17 |
# File 'lib/rspec_telemetry/recorder.rb', line 12 def initialize(config, writer: nil, summary: nil) @config = config @writer = writer || Writer.new(config.output_path, flush_each: config.flush_each) @summary = summary || Summary.new(config) @started = false end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/rspec_telemetry/recorder.rb', line 10 def config @config end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
10 11 12 |
# File 'lib/rspec_telemetry/recorder.rb', line 10 def summary @summary end |
Class Method Details
.thread_id ⇒ Object
70 71 72 73 |
# File 'lib/rspec_telemetry/recorder.rb', line 70 def self.thread_id t = Thread.current t.respond_to?(:native_thread_id) && t.native_thread_id ? t.native_thread_id : t.object_id end |
Instance Method Details
#clear_current_example ⇒ Object
66 67 68 |
# File 'lib/rspec_telemetry/recorder.rb', line 66 def clear_current_example Thread.current[EXAMPLE_ID] = nil end |
#common_fields(type) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rspec_telemetry/recorder.rb', line 51 def common_fields(type) { type: type, timestamp: Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%6NZ"), monotonic_time: Process.clock_gettime(Process::CLOCK_MONOTONIC), pid: Process.pid, thread_id: self.class.thread_id, example_id: Thread.current[EXAMPLE_ID] } end |
#finish ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/rspec_telemetry/recorder.rb', line 43 def finish return unless @started SummaryPrinter.print(@summary, @config) if @config.print_summary @writer.close @started = false end |
#flush ⇒ Object
39 40 41 |
# File 'lib/rspec_telemetry/recorder.rb', line 39 def flush @writer.flush end |
#record(type, fields = {}) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/rspec_telemetry/recorder.rb', line 30 def record(type, fields = {}) return unless @config.enabled && @started event = common_fields(type).merge(fields) @writer.write(event) @summary.add(event) event end |
#set_current_example(id) ⇒ Object
62 63 64 |
# File 'lib/rspec_telemetry/recorder.rb', line 62 def set_current_example(id) Thread.current[EXAMPLE_ID] = id end |
#start ⇒ Object
19 20 21 22 23 24 |
# File 'lib/rspec_telemetry/recorder.rb', line 19 def start return if @started || !@config.enabled @writer.open @started = true end |
#started? ⇒ Boolean
26 27 28 |
# File 'lib/rspec_telemetry/recorder.rb', line 26 def started? @started end |