Class: Appsignal::Span
Instance Method Summary collapse
- #[]=(key, value) ⇒ Object
- #add_error(error) ⇒ Object
- #child ⇒ Object
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(namespace = nil, ext = nil) ⇒ Span
constructor
A new instance of Span.
- #instrument ⇒ Object
- #name=(value) ⇒ Object
- #set_sample_data(key, data) ⇒ Object
- #to_h ⇒ Object
Constructor Details
Instance Method Details
#[]=(key, value) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/appsignal/span.rb', line 43 def []=(key, value) case value when String @ext.set_attribute_string(key.to_s, value) when Integer begin @ext.set_attribute_int(key.to_s, value) rescue RangeError @ext.set_attribute_string(key.to_s, "bigint:#{value}") end when TrueClass, FalseClass @ext.set_attribute_bool(key.to_s, value) when Float @ext.set_attribute_double(key.to_s, value) else raise TypeError, "value needs to be a string, int, bool or float" end end |
#add_error(error) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/appsignal/span.rb', line 19 def add_error(error) unless error.is_a?(Exception) Appsignal.logger.error "Appsignal::Span#add_error: Cannot add error. " \ "The given value is not an exception: #{error.inspect}" return end return unless error backtrace = cleaned_backtrace(error.backtrace) @ext.add_error( error.class.name, error..to_s, backtrace ? Appsignal::Utils::Data.generate(backtrace) : Appsignal::Extension.data_array_new ) end |
#child ⇒ Object
11 12 13 |
# File 'lib/appsignal/span.rb', line 11 def child Span.new(nil, @ext.child) end |
#close ⇒ Object
74 75 76 |
# File 'lib/appsignal/span.rb', line 74 def close @ext.close end |
#closed? ⇒ Boolean
78 79 80 |
# File 'lib/appsignal/span.rb', line 78 def closed? to_h.nil? end |
#instrument ⇒ Object
68 69 70 71 72 |
# File 'lib/appsignal/span.rb', line 68 def instrument yield self ensure close end |
#name=(value) ⇒ Object
15 16 17 |
# File 'lib/appsignal/span.rb', line 15 def name=(value) @ext.set_name(value) end |
#set_sample_data(key, data) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/appsignal/span.rb', line 35 def set_sample_data(key, data) return unless key && data && (data.is_a?(Array) || data.is_a?(Hash)) @ext.set_sample_data( key.to_s, Appsignal::Utils::Data.generate(data) ) end |
#to_h ⇒ Object
62 63 64 65 66 |
# File 'lib/appsignal/span.rb', line 62 def to_h json = @ext.to_json return unless json JSON.parse(json) end |