Class: InfluxReporter::Transaction
- Inherits:
-
Object
- Object
- InfluxReporter::Transaction
- Defined in:
- lib/influx_reporter/transaction.rb
Constant Summary collapse
- ROOT_TRACE_NAME =
'transaction'
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#notifications ⇒ Object
readonly
Returns the value of attribute notifications.
-
#result ⇒ Object
Returns the value of attribute result.
-
#root_trace ⇒ Object
readonly
Returns the value of attribute root_trace.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#traces ⇒ Object
readonly
Returns the value of attribute traces.
Instance Method Summary collapse
- #current_offset ⇒ Object
- #current_trace ⇒ Object
- #done(result = nil) ⇒ Object
- #done? ⇒ Boolean
- #extra_tags {|| ... } ⇒ Object
- #extra_values {|| ... } ⇒ Object
-
#initialize(client, endpoint, kind = 'code.custom', result = nil) ⇒ Transaction
constructor
A new instance of Transaction.
- #inspect ⇒ Object
- #release ⇒ Object
- #running_traces ⇒ Object
- #submit(result = nil) ⇒ Object
- #trace(signature, kind = nil, extra = nil) ⇒ Object
Constructor Details
#initialize(client, endpoint, kind = 'code.custom', result = nil) ⇒ Transaction
Returns a new instance of Transaction.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/influx_reporter/transaction.rb', line 13 def initialize(client, endpoint, kind = 'code.custom', result = nil) @client = client @config = client.config if client.respond_to?(:config) @endpoint = endpoint @kind = kind @result = result @timestamp = Util.nanos @root_trace = Trace.new(self, ROOT_TRACE_NAME, ROOT_TRACE_NAME) @traces = [@root_trace] @notifications = [] @start_time = Util.nanos @root_trace.start @start_time end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
31 32 33 |
# File 'lib/influx_reporter/transaction.rb', line 31 def config @config end |
#duration ⇒ Object
Returns the value of attribute duration.
30 31 32 |
# File 'lib/influx_reporter/transaction.rb', line 30 def duration @duration end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
30 31 32 |
# File 'lib/influx_reporter/transaction.rb', line 30 def endpoint @endpoint end |
#kind ⇒ Object
Returns the value of attribute kind.
30 31 32 |
# File 'lib/influx_reporter/transaction.rb', line 30 def kind @kind end |
#notifications ⇒ Object (readonly)
Returns the value of attribute notifications.
31 32 33 |
# File 'lib/influx_reporter/transaction.rb', line 31 def notifications @notifications end |
#result ⇒ Object
Returns the value of attribute result.
30 31 32 |
# File 'lib/influx_reporter/transaction.rb', line 30 def result @result end |
#root_trace ⇒ Object (readonly)
Returns the value of attribute root_trace.
31 32 33 |
# File 'lib/influx_reporter/transaction.rb', line 31 def root_trace @root_trace end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
31 32 33 |
# File 'lib/influx_reporter/transaction.rb', line 31 def start_time @start_time end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
31 32 33 |
# File 'lib/influx_reporter/transaction.rb', line 31 def @timestamp end |
#traces ⇒ Object (readonly)
Returns the value of attribute traces.
31 32 33 |
# File 'lib/influx_reporter/transaction.rb', line 31 def traces @traces end |
Instance Method Details
#current_offset ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/influx_reporter/transaction.rb', line 98 def current_offset if curr = current_trace return curr.start_time end start_time end |
#current_trace ⇒ Object
94 95 96 |
# File 'lib/influx_reporter/transaction.rb', line 94 def current_trace traces.reverse.find(&:running?) end |
#done(result = nil) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/influx_reporter/transaction.rb', line 37 def done(result = nil) @result = result @root_trace.done Util.nanos @duration = @root_trace.duration self end |
#done? ⇒ Boolean
46 47 48 |
# File 'lib/influx_reporter/transaction.rb', line 46 def done? @root_trace.done? end |
#extra_tags {|| ... } ⇒ Object
80 81 82 83 |
# File 'lib/influx_reporter/transaction.rb', line 80 def @root_trace.extra[:tags] ||= {} yield @root_trace.extra[:tags] end |
#extra_values {|| ... } ⇒ Object
85 86 87 88 |
# File 'lib/influx_reporter/transaction.rb', line 85 def extra_values @root_trace.extra[:values] ||= {} yield @root_trace.extra[:values] end |
#inspect ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/influx_reporter/transaction.rb', line 106 def inspect info = %w[endpoint kind result duration timestamp start_time] <<~TEXT <Transaction #{info.map { |m| "#{m}:#{send(m).inspect}" }.join(' ')}> #{traces.map(&:inspect).join("\n ")}" TEXT end |
#release ⇒ Object
33 34 35 |
# File 'lib/influx_reporter/transaction.rb', line 33 def release @client.current_transaction = nil end |
#running_traces ⇒ Object
90 91 92 |
# File 'lib/influx_reporter/transaction.rb', line 90 def running_traces traces.select(&:running?) end |
#submit(result = nil) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/influx_reporter/transaction.rb', line 50 def submit(result = nil) done result release @client.submit_transaction self self end |
#trace(signature, kind = nil, extra = nil) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/influx_reporter/transaction.rb', line 60 def trace(signature, kind = nil, extra = nil) trace = Trace.new(self, signature, kind, running_traces, extra) rel_time = current_offset traces << trace trace.start rel_time return trace unless block_given? begin result = yield trace ensure trace.done end result end |