Class: Maze::Api::Model::OtelAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/maze/api/model/otel_attribute.rb

Overview

OTEL attributes used in both spans and resources

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, key, value) ⇒ OtelAttribute

Returns a new instance of OtelAttribute.



21
22
23
24
25
# File 'lib/maze/api/model/otel_attribute.rb', line 21

def initialize(type, key, value)
  @key = key
  @type = type
  @value = value
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



19
20
21
# File 'lib/maze/api/model/otel_attribute.rb', line 19

def key
  @key
end

#typeObject

Returns the value of attribute type.



19
20
21
# File 'lib/maze/api/model/otel_attribute.rb', line 19

def type
  @type
end

#valueObject

Returns the value of attribute value.



19
20
21
# File 'lib/maze/api/model/otel_attribute.rb', line 19

def value
  @value
end

Class Method Details

.array_from_hash(hash_array) ⇒ Array<OtelAttributeArrayElement>

Create an array of OtelAttributeArrayElement from a hash array.

Parameters:

  • hash_array (Array<Hash>)

    Array of hashes representing attribute values.

Returns:



31
32
33
34
35
36
37
38
39
# File 'lib/maze/api/model/otel_attribute.rb', line 31

def array_from_hash(hash_array)
  array = []
  hash_array.each do |value_hash|
    type = OtelAttributeType::for_string(value_hash.keys.first)
    value = value_hash.values.first
    array << OtelAttributeArrayElement.new(type, value)
  end
  array
end

.from_hash(hash) ⇒ OtelAttribute

Create an OtelAttribute from a hash.

Parameters:

  • hash (Hash)

    Hash representing an OTEL attribute.

Returns:



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/maze/api/model/otel_attribute.rb', line 44

def from_hash(hash)
  type = OtelAttributeType.for_string(hash['value'].keys.first)
  hash_value = hash['value']
  value = if hash_value.has_key?('arrayValue')
    array_from_hash(hash_value['arrayValue']['values'])
  elsif hash_value.has_key?('boolValue')
    hash_value['boolValue']
  elsif hash_value.has_key?('doubleValue')
    hash_value['doubleValue']
  elsif hash_value.has_key?('intValue')
    hash_value['intValue']
  elsif hash_value.has_key?('stringValue')
    hash_value['stringValue']
  end

  new(
    type,
    hash['key'],
    value
  )
end