Class: AppPerfRpm::Tracing::Span
- Inherits:
-
Object
- Object
- AppPerfRpm::Tracing::Span
- Defined in:
- lib/app_perf_rpm/tracing/span.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#log_entries ⇒ Object
readonly
Returns the value of attribute log_entries.
-
#operation_name ⇒ Object
Returns the value of attribute operation_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
- #add_tags(tags) ⇒ Object
- #exit(opts = {}) ⇒ Object
- #finish(opts = {}) ⇒ Object
- #get_baggage_item(key) ⇒ Object
-
#initialize(context, operation_name, collector, opts = {}) ⇒ Span
constructor
A new instance of Span.
-
#log(opts = {}, *_, fields) ⇒ Object
Original definition for ruby 2+ was this: def log(opts = { :event => nil, :timestamp => AppPerfRpm.now }, **fields) but this doesn’t work in 1.9.
- #log_error(exception, opts = {}) ⇒ Object
- #set_baggage_item(key, value) ⇒ Object
- #set_tag(key, value) ⇒ Object
Constructor Details
#initialize(context, operation_name, collector, opts = {}) ⇒ Span
Returns a new instance of Span.
9 10 11 12 13 14 15 16 17 |
# File 'lib/app_perf_rpm/tracing/span.rb', line 9 def initialize(context, operation_name, collector, opts = {}) @context = context @operation_name = operation_name @collector = collector @start_time = opts[:start_time] || AppPerfRpm.now @end_time = nil @tags = opts[:tags] || {} @log_entries = [] end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
8 9 10 |
# File 'lib/app_perf_rpm/tracing/span.rb', line 8 def context @context end |
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
8 9 10 |
# File 'lib/app_perf_rpm/tracing/span.rb', line 8 def end_time @end_time end |
#log_entries ⇒ Object (readonly)
Returns the value of attribute log_entries.
8 9 10 |
# File 'lib/app_perf_rpm/tracing/span.rb', line 8 def log_entries @log_entries end |
#operation_name ⇒ Object
Returns the value of attribute operation_name.
6 7 8 |
# File 'lib/app_perf_rpm/tracing/span.rb', line 6 def operation_name @operation_name end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
8 9 10 |
# File 'lib/app_perf_rpm/tracing/span.rb', line 8 def start_time @start_time end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
8 9 10 |
# File 'lib/app_perf_rpm/tracing/span.rb', line 8 def @tags end |
Instance Method Details
#add_tags(tags) ⇒ Object
23 24 25 26 27 |
# File 'lib/app_perf_rpm/tracing/span.rb', line 23 def () .each_pair do |key, value| set_tag(key, value) end end |
#exit(opts = {}) ⇒ Object
63 64 65 |
# File 'lib/app_perf_rpm/tracing/span.rb', line 63 def exit(opts = {}) @end_time = opts[:end_time] || AppPerfRpm.now end |
#finish(opts = {}) ⇒ Object
67 68 69 |
# File 'lib/app_perf_rpm/tracing/span.rb', line 67 def finish(opts = {}) @collector.send_span(self, @end_time || opts[:end_time] || AppPerfRpm.now) end |
#get_baggage_item(key) ⇒ Object
33 34 35 |
# File 'lib/app_perf_rpm/tracing/span.rb', line 33 def get_baggage_item(key) @context.get_baggage_item(key) end |
#log(opts = {}, *_, fields) ⇒ Object
Original definition for ruby 2+ was this: def log(opts = { :event => nil, :timestamp => AppPerfRpm.now }, **fields) but this doesn’t work in 1.9.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/app_perf_rpm/tracing/span.rb', line 40 def log(opts = {}, *_, fields) entry = { "event" => opts[:event] || nil, "timestamp" => opts[:timestamp] || AppPerfRpm.now, } entry["fields"] = fields @log_entries << entry nil end |
#log_error(exception, opts = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/app_perf_rpm/tracing/span.rb', line 52 def log_error(exception, opts = {}) log( event: "error", timestamp: opts[:timestamp] || AppPerfRpm.now, message: exception., error_class: exception.class.to_s, backtrace: AppPerfRpm::Backtrace.clean(exception.backtrace), source: AppPerfRpm::Backtrace.source_extract(backtrace: exception.backtrace) ) end |
#set_baggage_item(key, value) ⇒ Object
29 30 31 |
# File 'lib/app_perf_rpm/tracing/span.rb', line 29 def set_baggage_item(key, value) @context.set_baggage_item(key, value) end |
#set_tag(key, value) ⇒ Object
19 20 21 |
# File 'lib/app_perf_rpm/tracing/span.rb', line 19 def set_tag(key, value) @tags = @tags.merge(key => value) end |