Class: AppMap::Hook::RecordAround::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/appmap/hook/record_around.rb

Overview

Context for a recording.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hook_method) ⇒ Context

Returns a new instance of Context.



11
12
13
14
15
# File 'lib/appmap/hook/record_around.rb', line 11

def initialize(hook_method)
  @hook_method = hook_method
  @start_time = DateTime.now
  @tracer = AppMap.tracing.trace(thread: Thread.current)
end

Instance Attribute Details

#hook_methodObject (readonly)

Returns the value of attribute hook_method.



9
10
11
# File 'lib/appmap/hook/record_around.rb', line 9

def hook_method
  @hook_method
end

Instance Method Details

#finishObject

Finish recording the AppMap by collecting the events and classMap and writing the output file. rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/appmap/hook/record_around.rb', line 20

def finish
  return unless @tracer

  tracer = @tracer
  @tracer = nil
  AppMap.tracing.delete(tracer)

  events = tracer.events.map(&:to_h)

  timestamp = DateTime.now
  appmap_name = "#{hook_method.name} (#{Thread.current.object_id}) - #{timestamp.strftime("%T.%L")}"
  appmap_file_name = AppMap::Util.scenario_filename([timestamp.to_f, hook_method.name, Thread.current.object_id].join("_"))

   = AppMap..tap do ||
    [:name] = appmap_name
    [:source_location] = hook_method.source_location
    [:recorder] = {
      name: "command",
      type: "requests"
    }
  end

  appmap = {
    version: AppMap::APPMAP_FORMAT_VERSION,
    classMap: AppMap.class_map(tracer.event_methods),
    metadata: ,
    events: events
  }

  AppMap::Util.write_appmap(File.join(APPMAP_OUTPUT_DIR, appmap_file_name), appmap)
end