Class: Mnemosyne::Trace

Inherits:
Span
  • Object
show all
Defined in:
lib/mnemosyne/trace.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Attributes inherited from Span

#finish, #meta, #name, #start, #type

Instance Method Summary collapse

Methods inherited from Span

#finish!, #start!

Constructor Details

#initialize(instrumenter, name, transaction: nil, origin: nil, **kwargs) ⇒ Trace

Returns a new instance of Trace.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/mnemosyne/trace.rb', line 7

def initialize(instrumenter, name, transaction: nil, origin: nil, **kwargs)
  super(name, **kwargs)

  @uuid   = ::SecureRandom.uuid
  @span   = []
  @errors = []

  @origin      = origin
  @transaction = transaction

  @instrumenter = instrumenter
end

Instance Attribute Details

#errors ⇒ Object (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/mnemosyne/trace.rb', line 5

def errors
  @errors
end

#origin ⇒ Object (readonly)

Returns the value of attribute origin.



5
6
7
# File 'lib/mnemosyne/trace.rb', line 5

def origin
  @origin
end

#span ⇒ Object (readonly)

Returns the value of attribute span.



5
6
7
# File 'lib/mnemosyne/trace.rb', line 5

def span
  @span
end

#transaction ⇒ Object (readonly)

Returns the value of attribute transaction.



5
6
7
# File 'lib/mnemosyne/trace.rb', line 5

def transaction
  @transaction
end

#uuid ⇒ Object (readonly)

Returns the value of attribute uuid.



5
6
7
# File 'lib/mnemosyne/trace.rb', line 5

def uuid
  @uuid
end

Instance Method Details

#<<(span) ⇒ Object



20
21
22
# File 'lib/mnemosyne/trace.rb', line 20

def <<(span)
  @span << span
end

#attach_error(error) ⇒ Object



24
25
26
# File 'lib/mnemosyne/trace.rb', line 24

def attach_error(error)
  @errors << Error.new(error)
end

#release ⇒ Object



34
35
36
# File 'lib/mnemosyne/trace.rb', line 34

def release
  @instrumenter.release self
end

#serialize ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mnemosyne/trace.rb', line 38

def serialize
  {
    uuid: uuid,
    origin: origin,
    transaction: transaction,
    name: name,
    start: start,
    stop: finish,
    meta: meta,
    span: @span.map(&:serialize),
    errors: @errors.map(&:serialize)
  }
end

#submit ⇒ Object



28
29
30
31
32
# File 'lib/mnemosyne/trace.rb', line 28

def submit
  finish! unless finish

  @instrumenter.submit self
end