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
27
28
29
30
31
32
33
# File 'lib/mnemosyne/trace.rb', line 24

def attach_error(error)
  case error
    when Exception
      @errors << Error.new(error)
    when String
      @errors << Error.new(RuntimeError.new(error))
    else
      raise ArgumentError.new "Invalid error type: #{error.inspect}"
  end
end

#release ⇒ Object



41
42
43
# File 'lib/mnemosyne/trace.rb', line 41

def release
  @instrumenter.release self
end

#serialize ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/mnemosyne/trace.rb', line 45

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



35
36
37
38
39
# File 'lib/mnemosyne/trace.rb', line 35

def submit
  finish! unless finish

  @instrumenter.submit self
end