Class: Findbug::Performance::Transaction
- Inherits:
-
Object
- Object
- Findbug::Performance::Transaction
- Defined in:
- lib/findbug/performance/transaction.rb
Overview
Transaction provides manual performance tracking for custom operations.
WHY MANUAL TRANSACTIONS?
Automatic instrumentation catches HTTP requests, but what about:
-
External API calls
-
Background job processing
-
Custom business logic
-
Third-party service calls
With transactions, you can track anything:
Findbug.track_performance("stripe_charge") do
Stripe::Charge.create(...)
end
Findbug.track_performance("pdf_generation") do
generate_report_pdf(...)
end
NESTING
Transactions can be nested. Child transactions contribute to parent timing:
Findbug.track_performance("checkout") do
Findbug.track_performance("payment") do
process_payment
end
Findbug.track_performance("fulfillment") do
create_shipment
end
end
This creates a tree of timings you can analyze.
Class Method Summary collapse
-
.start(name, tags: {}) ⇒ TransactionSpan
Start a transaction manually (for cases where block syntax doesn’t work).
-
.track(name, tags: {}) { ... } ⇒ Object
Track a block’s performance.
Class Method Details
.start(name, tags: {}) ⇒ TransactionSpan
Start a transaction manually (for cases where block syntax doesn’t work)
89 90 91 |
# File 'lib/findbug/performance/transaction.rb', line 89 def start(name, tags: {}) TransactionSpan.new(name, ) end |
.track(name, tags: {}) { ... } ⇒ Object
Track a block’s performance
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/findbug/performance/transaction.rb', line 51 def track(name, tags: {}, &block) return yield unless Findbug.enabled? return yield unless Findbug.config.performance_enabled start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) begin # Execute the block result = yield # Calculate duration duration_ms = calculate_duration(start_time) # Record the transaction record_transaction(name, duration_ms, , success: true) result rescue StandardError => e # Calculate duration even on error duration_ms = calculate_duration(start_time) # Record as failed record_transaction(name, duration_ms, , success: false, error: e.class.name) raise end end |