Class: Deimos::Tracing::Mock

Inherits:
Provider show all
Defined in:
lib/deimos/tracing/mock.rb,
sig/defs.rbs

Overview

Class that mocks out tracing functionality

Instance Method Summary collapse

Constructor Details

#initialize(logger = nil) ⇒ Mock

@param logger

Parameters:

  • logger (Logger, nil) (defaults to: nil)


10
11
12
13
14
# File 'lib/deimos/tracing/mock.rb', line 10

def initialize(logger=nil)
  @logger = logger || Logger.new(STDOUT)
  @logger.info('MockTracingProvider initialized')
  @active_span = MockSpan.new
end

Instance Method Details

#active_spanObject

:nodoc:

Returns:

  • (Object)


35
36
37
# File 'lib/deimos/tracing/mock.rb', line 35

def active_span
  @active_span ||= MockSpan.new
end

#finish(span) ⇒ void

This method returns an undefined value.

:nodoc:

Parameters:

  • span (Object)


27
28
29
30
31
32
# File 'lib/deimos/tracing/mock.rb', line 27

def finish(span)
  name = span[:name]
  start = span[:started_at]
  finish = Time.zone.now
  @logger.info("Mock span '#{name}' finished: #{start} to #{finish}")
end

#get_tag(tag) ⇒ Object

Get a tag from a span with the specified tag.

Parameters:

  • tag (String)


50
51
52
# File 'lib/deimos/tracing/mock.rb', line 50

def get_tag(tag)
  @span.get_tag(tag)
end

#set_error(span, exception) ⇒ void

This method returns an undefined value.

:nodoc:

Parameters:

  • span (Object)
  • exception (Exception)


55
56
57
58
59
# File 'lib/deimos/tracing/mock.rb', line 55

def set_error(span, exception)
  span[:exception] = exception
  name = span[:name]
  @logger.info("Mock span '#{name}' set an error: #{exception}")
end

#set_tag(tag, value, span = nil) ⇒ void

This method returns an undefined value.

:nodoc:

Parameters:

  • tag (String)
  • value (String)
  • span (Object, nil) (defaults to: nil)


40
41
42
43
44
45
46
# File 'lib/deimos/tracing/mock.rb', line 40

def set_tag(tag, value, span=nil)
  if span
    span.set_tag(tag, value)
  else
    active_span.set_tag(tag, value)
  end
end

#start(span_name, _options = {}) ⇒ Object

@param span_name

@param _options

Parameters:

  • span_name (String)
  • _options (::Hash[untyped, untyped]) (defaults to: {})

Returns:

  • (Object)


18
19
20
21
22
23
24
# File 'lib/deimos/tracing/mock.rb', line 18

def start(span_name, _options={})
  @logger.info("Mock span '#{span_name}' started")
  {
    name: span_name,
    started_at: Time.zone.now
  }
end