Class: TypedOperation::Instrumentation::Trace
- Inherits:
-
Object
- Object
- TypedOperation::Instrumentation::Trace
- Defined in:
- lib/typed_operation/instrumentation/trace.rb
Overview
Represents a single operation execution trace with timing and result data. Supports nested traces for operations that call other operations.
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
: Array.
-
#end_time ⇒ Object
: Float?.
-
#exception ⇒ Object
: Exception?.
-
#extracted_params ⇒ Object
: Array?.
-
#fallback_used ⇒ Object
: bool.
-
#operation_class ⇒ Object
readonly
: untyped.
-
#params ⇒ Object
readonly
: Hash[Symbol, untyped].
-
#pass_mode ⇒ Object
: Symbol?.
-
#result ⇒ Object
: untyped.
-
#start_time ⇒ Object
readonly
: Float.
Instance Method Summary collapse
-
#add_child(trace) ⇒ Object
: (Trace) -> void.
-
#duration_ms ⇒ Object
: () -> (Float | Integer | nil).
-
#failure? ⇒ Boolean
: () -> bool.
-
#finish!(result: nil, exception: nil) ⇒ Object
: (?result: untyped, ?exception: Exception?) -> self.
-
#initialize(operation_class:, params: {}) ⇒ Trace
constructor
: (operation_class: untyped, ?params: Hash[Symbol, untyped]) -> void.
-
#operation_name ⇒ Object
: () -> String.
-
#success? ⇒ Boolean
: () -> bool.
Constructor Details
#initialize(operation_class:, params: {}) ⇒ Trace
: (operation_class: untyped, ?params: Hash[Symbol, untyped]) -> void
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/typed_operation/instrumentation/trace.rb', line 21 def initialize(operation_class:, params: {}) @operation_class = operation_class @params = params @start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) @end_time = nil @result = nil @exception = nil @children = [] @pass_mode = nil @extracted_params = nil @fallback_used = false end |
Instance Attribute Details
#children ⇒ Object (readonly)
: Array
12 13 14 |
# File 'lib/typed_operation/instrumentation/trace.rb', line 12 def children @children end |
#end_time ⇒ Object
: Float?
13 14 15 |
# File 'lib/typed_operation/instrumentation/trace.rb', line 13 def end_time @end_time end |
#exception ⇒ Object
: Exception?
15 16 17 |
# File 'lib/typed_operation/instrumentation/trace.rb', line 15 def exception @exception end |
#extracted_params ⇒ Object
: Array?
17 18 19 |
# File 'lib/typed_operation/instrumentation/trace.rb', line 17 def extracted_params @extracted_params end |
#fallback_used ⇒ Object
: bool
18 19 20 |
# File 'lib/typed_operation/instrumentation/trace.rb', line 18 def fallback_used @fallback_used end |
#operation_class ⇒ Object (readonly)
: untyped
9 10 11 |
# File 'lib/typed_operation/instrumentation/trace.rb', line 9 def operation_class @operation_class end |
#params ⇒ Object (readonly)
: Hash[Symbol, untyped]
10 11 12 |
# File 'lib/typed_operation/instrumentation/trace.rb', line 10 def params @params end |
#pass_mode ⇒ Object
: Symbol?
16 17 18 |
# File 'lib/typed_operation/instrumentation/trace.rb', line 16 def pass_mode @pass_mode end |
#result ⇒ Object
: untyped
14 15 16 |
# File 'lib/typed_operation/instrumentation/trace.rb', line 14 def result @result end |
#start_time ⇒ Object (readonly)
: Float
11 12 13 |
# File 'lib/typed_operation/instrumentation/trace.rb', line 11 def start_time @start_time end |
Instance Method Details
#add_child(trace) ⇒ Object
: (Trace) -> void
61 62 63 |
# File 'lib/typed_operation/instrumentation/trace.rb', line 61 def add_child(trace) @children << trace end |
#duration_ms ⇒ Object
: () -> (Float | Integer | nil)
43 44 45 46 |
# File 'lib/typed_operation/instrumentation/trace.rb', line 43 def duration_ms return nil unless end_time ((end_time - start_time) * 1000).round(2) end |
#failure? ⇒ Boolean
: () -> bool
56 57 58 |
# File 'lib/typed_operation/instrumentation/trace.rb', line 56 def failure? !success? end |
#finish!(result: nil, exception: nil) ⇒ Object
: (?result: untyped, ?exception: Exception?) -> self
35 36 37 38 39 40 |
# File 'lib/typed_operation/instrumentation/trace.rb', line 35 def finish!(result: nil, exception: nil) @end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) @result = result @exception = exception self end |
#operation_name ⇒ Object
: () -> String
66 67 68 |
# File 'lib/typed_operation/instrumentation/trace.rb', line 66 def operation_name operation_class.name || operation_class.to_s end |
#success? ⇒ Boolean
: () -> bool
49 50 51 52 53 |
# File 'lib/typed_operation/instrumentation/trace.rb', line 49 def success? return false if exception return result.success? if result.respond_to?(:success?) true end |