Module: GoodData::ContextManager

Extended by:
Mixin::PropertyAccessor
Included in:
GdLogger
Defined in:
lib/gooddata/bricks/middleware/context_manager.rb

Instance Method Summary collapse

Methods included from Mixin::PropertyAccessor

property_accessor, property_reader, property_writer

Instance Method Details

#context(now = Time.now) ⇒ Hash

Return current brick context extended with time specific information

Parameters:

  • now, (Time)

    allows to specify exact time, when outer call was performed

Returns:

  • (Hash)

    Brick context



34
35
36
37
# File 'lib/gooddata/bricks/middleware/context_manager.rb', line 34

def context(now = Time.now)
  time_specific_context = action ? { :time => time_from_action_start(now) } : {}
  @context.merge(time_specific_context)
end

#end_action(logger = nil) ⇒ Object

Ends currently opened lcm action

Parameters:

  • logger, (Logger)

    logger that should log current context info



61
62
63
64
65
66
67
# File 'lib/gooddata/bricks/middleware/context_manager.rb', line 61

def end_action(logger = nil)
  GoodData::LCM2::Helpers.fail_if_development 'No matching action to start found' unless action

  logger.info '' if logger
  self.status = :not_in_action
  self.action = nil
end

#initialize_contextObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gooddata/bricks/middleware/context_manager.rb', line 18

def initialize_context
  @action_start = Time.now

  # :log_v is used to differentiate new versions of logs in splunk
  @context = {
    :api_version => GoodData.version,
    :log_v => 0,
    :component => 'lcm.ruby',
    :status => :not_in_action
  }
end

#start_action(next_action, logger = nil, now = Time.now) ⇒ Object

Starts lcm action

Parameters:

  • action, (String)

    name of the action

  • logger, (Logger)

    logger that should log current context info

  • now, (Time)

    allows to specify exact time, when outer call was performed



49
50
51
52
53
54
55
56
# File 'lib/gooddata/bricks/middleware/context_manager.rb', line 49

def start_action(next_action, logger = nil, now = Time.now)
  GoodData::LCM2::Helpers.fail_if_development 'An action is already being profiled' if action

  self.action = next_action
  @action_start = now
  logger.info '' if logger
  self.status = :action_in_progress
end

#time_from_action_start(now = Time.now) ⇒ Object



39
40
41
42
# File 'lib/gooddata/bricks/middleware/context_manager.rb', line 39

def time_from_action_start(now = Time.now)
  GoodData::LCM2::Helpers.fail_if_development 'No action is being profiled' unless action
  (now - @action_start) * 1000
end