Class: Lens::Trace

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Trace

Returns a new instance of Trace.



3
4
5
6
7
8
9
10
11
12
# File 'lib/lens/trace.rb', line 3

def initialize(id)
  @id = id
  @data = []

  @gc_statistics = Lens::GC.new
  @gc_statistics.enable

  @allocations_data = Lens::AllocationsData.new
  @allocations_data.enable if Lens.configuration.with_memory_usage?
end

Class Method Details

.present?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/lens/trace.rb', line 52

def present?
  current.present?
end

.process(event) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/lens/trace.rb', line 43

def process(event)
  create(event.transaction_id) if first_event?(event)

  if Trace.present?
    current.add(event)
    current.complete(event) if last_event?(event)
  end
end

Instance Method Details

#add(event) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/lens/trace.rb', line 14

def add(event)
  @data.push event.payload.merge(
    etype: event.name,
    eduration: event.duration,
    estart: event.time.to_f,
    efinish: event.end.to_f
  )
end

#complete(event) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/lens/trace.rb', line 23

def complete(event)
  formatter = Lens::EventFormatter.new(
    event,
    @data,
    @gc_statistics.total_time,
    @allocations_data
  )
  formatted_data = formatter.json_formatted
  send(formatted_data)
  Thread.current[:__lens_trace] = nil
end