Class: Dontbugme::Span
- Inherits:
-
Object
- Object
- Dontbugme::Span
- Defined in:
- lib/dontbugme/span.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#detail ⇒ Object
readonly
Returns the value of attribute detail.
-
#duration_ms ⇒ Object
readonly
Returns the value of attribute duration_ms.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(category:, operation:, detail:, payload: {}, started_at:, duration_ms:, source: nil) ⇒ Span
constructor
A new instance of Span.
- #to_h ⇒ Object
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
#category ⇒ Object (readonly)
Returns the value of attribute category.
5 6 7 |
# File 'lib/dontbugme/span.rb', line 5 def category @category end |
#detail ⇒ Object (readonly)
Returns the value of attribute detail.
5 6 7 |
# File 'lib/dontbugme/span.rb', line 5 def detail @detail end |
#duration_ms ⇒ Object (readonly)
Returns the value of attribute duration_ms.
5 6 7 |
# File 'lib/dontbugme/span.rb', line 5 def duration_ms @duration_ms end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/dontbugme/span.rb', line 5 def id @id end |
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
5 6 7 |
# File 'lib/dontbugme/span.rb', line 5 def operation @operation end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
5 6 7 |
# File 'lib/dontbugme/span.rb', line 5 def payload @payload end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
5 6 7 |
# File 'lib/dontbugme/span.rb', line 5 def source @source end |
#started_at ⇒ Object (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_h ⇒ Object
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 |