Class: Dontbugme::Span

Inherits:
Object
  • Object
show all
Defined in:
lib/dontbugme/span.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(category:, operation:, detail:, payload: {}, started_at:, duration_ms:, source: nil) ⇒ Span

Returns a new instance of Span.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dontbugme/span.rb', line 7

def initialize(
  category:,
  operation:,
  detail:,
  payload: {},
  started_at:,
  duration_ms:,
  source: nil
)
  @id = "sp_#{SecureRandom.hex(4)}"
  @category = category.to_sym
  @operation = operation.to_s
  max_size = defined?(Dontbugme) && Dontbugme.respond_to?(:config) ? Dontbugme.config&.max_span_detail_size : 8192
  @detail = truncate_string(detail.to_s, max_size)
  @payload = payload
  @started_at = started_at
  @duration_ms = duration_ms
  @source = source
end

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



5
6
7
# File 'lib/dontbugme/span.rb', line 5

def category
  @category
end

#detailObject (readonly)

Returns the value of attribute detail.



5
6
7
# File 'lib/dontbugme/span.rb', line 5

def detail
  @detail
end

#duration_msObject (readonly)

Returns the value of attribute duration_ms.



5
6
7
# File 'lib/dontbugme/span.rb', line 5

def duration_ms
  @duration_ms
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/dontbugme/span.rb', line 5

def id
  @id
end

#operationObject (readonly)

Returns the value of attribute operation.



5
6
7
# File 'lib/dontbugme/span.rb', line 5

def operation
  @operation
end

#payloadObject (readonly)

Returns the value of attribute payload.



5
6
7
# File 'lib/dontbugme/span.rb', line 5

def payload
  @payload
end

#sourceObject (readonly)

Returns the value of attribute source.



5
6
7
# File 'lib/dontbugme/span.rb', line 5

def source
  @source
end

#started_atObject (readonly)

Returns the value of attribute started_at.



5
6
7
# File 'lib/dontbugme/span.rb', line 5

def started_at
  @started_at
end

Class Method Details

.from_h(hash) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dontbugme/span.rb', line 40

def self.from_h(hash)
  span = new(
    category: hash[:category] || hash['category'],
    operation: hash[:operation] || hash['operation'],
    detail: hash[:detail] || hash['detail'],
    payload: (hash[:payload] || hash['payload'] || {}).transform_keys(&:to_sym),
    started_at: hash[:started_at] || hash['started_at'],
    duration_ms: hash[:duration_ms] || hash['duration_ms'],
    source: hash[:source] || hash['source']
  )
  span.instance_variable_set(:@id, (hash[:id] || hash['id']).to_s) if hash[:id] || hash['id']
  span
end

Instance Method Details

#to_hObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dontbugme/span.rb', line 27

def to_h
  {
    id: id,
    category: category,
    operation: operation,
    detail: detail,
    payload: payload,
    started_at: started_at,
    duration_ms: duration_ms,
    source: source
  }
end