Class: Traces::Backend::Capture::Span

Inherits:
Object
  • Object
show all
Defined in:
lib/traces/backend/capture.rb

Overview

A span which validates tag assignment.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, name, attributes) ⇒ Span

Initialize a new span.



23
24
25
26
27
# File 'lib/traces/backend/capture.rb', line 23

def initialize(context, name, attributes)
  @context = context
  @name = name
  @attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



31
32
33
# File 'lib/traces/backend/capture.rb', line 31

def attributes
  @attributes
end

#contextObject (readonly)

Returns the value of attribute context.



29
30
31
# File 'lib/traces/backend/capture.rb', line 29

def context
  @context
end

#nameObject (readonly)

Returns the value of attribute name.



30
31
32
# File 'lib/traces/backend/capture.rb', line 30

def name
  @name
end

Instance Method Details

#[]=(key, value) ⇒ Object

Assign some metadata to the span.



36
37
38
# File 'lib/traces/backend/capture.rb', line 36

def []= key, value
  @attributes[key] = value
end

#as_jsonObject

Convert the span to a JSON representation.



41
42
43
44
45
46
47
# File 'lib/traces/backend/capture.rb', line 41

def as_json
  {
    name: @name,
    attributes: @attributes,
    context: @context.as_json
  }
end

#to_jsonObject

Convert the span to a JSON string.



50
51
52
# File 'lib/traces/backend/capture.rb', line 50

def to_json(...)
  as_json.to_json(...)
end