Class: Mnemosyne::Trace

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

Defined Under Namespace

Classes: Error

Constant Summary collapse

BT_REGEXP =
/^((?:[a-zA-Z]:)?[^:]+):(\d+)(?::in `([^']+)')?$/

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.



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

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

#errorsObject (readonly)

Returns the value of attribute errors.



7
8
9
# File 'lib/mnemosyne/trace.rb', line 7

def errors
  @errors
end

#originObject (readonly)

Returns the value of attribute origin.



7
8
9
# File 'lib/mnemosyne/trace.rb', line 7

def origin
  @origin
end

#spanObject (readonly)

Returns the value of attribute span.



7
8
9
# File 'lib/mnemosyne/trace.rb', line 7

def span
  @span
end

#transactionObject (readonly)

Returns the value of attribute transaction.



7
8
9
# File 'lib/mnemosyne/trace.rb', line 7

def transaction
  @transaction
end

#uuidObject (readonly)

Returns the value of attribute uuid.



7
8
9
# File 'lib/mnemosyne/trace.rb', line 7

def uuid
  @uuid
end

Instance Method Details

#<<(span) ⇒ Object



22
23
24
# File 'lib/mnemosyne/trace.rb', line 22

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

#attach_error(error) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/mnemosyne/trace.rb', line 26

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

#releaseObject



43
44
45
# File 'lib/mnemosyne/trace.rb', line 43

def release
  @instrumenter.release self
end

#serializeObject



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

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

#submitObject



37
38
39
40
41
# File 'lib/mnemosyne/trace.rb', line 37

def submit
  finish! unless finish

  @instrumenter.submit self
end