Class: Findbug::Performance::TransactionSpan
- Inherits:
-
Object
- Object
- Findbug::Performance::TransactionSpan
- Defined in:
- lib/findbug/performance/transaction.rb
Overview
TransactionSpan represents an in-progress transaction.
Use this when block syntax isn’t convenient:
span = Findbug::Performance::Transaction.start("my_operation")
begin
do_work
span.finish
rescue => e
span.finish(error: e)
raise
end
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
-
#current_duration_ms ⇒ Object
Get current duration (for monitoring in-progress transactions).
-
#finish(error: nil) ⇒ Object
Finish the transaction.
-
#finished? ⇒ Boolean
Check if already finished.
-
#initialize(name, tags = {}) ⇒ TransactionSpan
constructor
A new instance of TransactionSpan.
Constructor Details
#initialize(name, tags = {}) ⇒ TransactionSpan
Returns a new instance of TransactionSpan.
140 141 142 143 144 145 |
# File 'lib/findbug/performance/transaction.rb', line 140 def initialize(name, = {}) @name = name @tags = @start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) @finished = false end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
138 139 140 |
# File 'lib/findbug/performance/transaction.rb', line 138 def name @name end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
138 139 140 |
# File 'lib/findbug/performance/transaction.rb', line 138 def start_time @start_time end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
138 139 140 |
# File 'lib/findbug/performance/transaction.rb', line 138 def @tags end |
Instance Method Details
#current_duration_ms ⇒ Object
Get current duration (for monitoring in-progress transactions)
181 182 183 |
# File 'lib/findbug/performance/transaction.rb', line 181 def current_duration_ms calculate_duration end |
#finish(error: nil) ⇒ Object
Finish the transaction
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/findbug/performance/transaction.rb', line 151 def finish(error: nil) return if @finished @finished = true duration_ms = calculate_duration event = { transaction_name: name, transaction_type: "custom", duration_ms: duration_ms, success: error.nil?, error_class: error&.class&.name, tags: , context: Capture::Context.to_h, captured_at: Time.now.utc.iso8601(3), environment: Findbug.config.environment, release: Findbug.config.release } Storage::RedisBuffer.push_performance(event) rescue StandardError => e Findbug.logger.debug("[Findbug] Span finish failed: #{e.}") end |
#finished? ⇒ Boolean
Check if already finished
176 177 178 |
# File 'lib/findbug/performance/transaction.rb', line 176 def finished? @finished end |