class XRay::Annotations
Annotations
are simple key-value pairs that are indexed for use with filter expressions. Use annotations to record data that you want to use to group traces in the console, or when calling the GetTraceSummaries API.
Public Class Methods
new(entity)
click to toggle source
# File lib/aws-xray-sdk/model/annotations.rb, line 11 def initialize(entity) @entity = entity @data = {} end
Public Instance Methods
[](key)
click to toggle source
# File lib/aws-xray-sdk/model/annotations.rb, line 16 def [](key) @data[key] end
[]=(k, v)
click to toggle source
@param [Symbol] k Only characters in `A-Za-z0-9_` are supported. @param v Only `Numeric`, `String` true/false is supported.
# File lib/aws-xray-sdk/model/annotations.rb, line 22 def []=(k, v) raise EntityClosedError if @entity.closed? if key_supported?(k) && value_supported?(v) @data[k] = v else logger.warn %(Dropping annotation with key #{k} due to invalid characters.) end end
to_h()
click to toggle source
# File lib/aws-xray-sdk/model/annotations.rb, line 38 def to_h sanitize_values(@data) end
update(h)
click to toggle source
@param [Hash] h Update annotations with a single input hash.
# File lib/aws-xray-sdk/model/annotations.rb, line 32 def update(h) raise EntityClosedError if @entity.closed? filtered = filter_annotations(h) @data.merge!(filtered) end
Private Instance Methods
filter_annotations(h)
click to toggle source
# File lib/aws-xray-sdk/model/annotations.rb, line 44 def filter_annotations(h) h.delete_if do |k, v| drop = !key_supported?(k) || !value_supported?(v) logger.warn %(Dropping annotation with key #{k} due to invalid characters.) if drop drop end end
key_supported?(k)
click to toggle source
# File lib/aws-xray-sdk/model/annotations.rb, line 60 def key_supported?(k) k.match(/[A-Za-z0-9_]+/) end
sanitize_values(h)
click to toggle source
# File lib/aws-xray-sdk/model/annotations.rb, line 52 def sanitize_values(h) h.each_pair do |k, v| if v.is_a?(Float) h[k] = v.to_s if v.nan? || v.infinite? == 1 || v.infinite? == -1 end end end
value_supported?(v)
click to toggle source
# File lib/aws-xray-sdk/model/annotations.rb, line 64 def value_supported?(v) case v when Numeric true when true, false true else v.is_a?(String) end end