class OpenTracingTestTracer::Span

Attributes

context[R]

NOTE: These are not OT compliant. These are meant only for testing.

end_time[R]

NOTE: These are not OT compliant. These are meant only for testing.

logs[R]

NOTE: These are not OT compliant. These are meant only for testing.

operation_name[RW]
references[R]

NOTE: These are not OT compliant. These are meant only for testing.

start_time[R]

NOTE: These are not OT compliant. These are meant only for testing.

tags[R]

NOTE: These are not OT compliant. These are meant only for testing.

Public Class Methods

new( context:, operation_name:, start_time: Time.now, tags: {}, references: nil, tracer: nil ) click to toggle source
# File lib/signalfx_test_tracer/span.rb, line 10
def initialize(
  context:,
  operation_name:,
  start_time: Time.now,
  tags: {},
  references: nil,
  tracer: nil
)
  @context = context
  @operation_name = operation_name
  @start_time = start_time
  @tags = tags
  @logs = []
  @references = references
  @tracer = tracer
end

Public Instance Methods

finish(end_time: Time.now) click to toggle source

Finish the {Span}

@param end_time [Time] custom end time, if not now

# File lib/signalfx_test_tracer/span.rb, line 88
def finish(end_time: Time.now)
  @end_time = end_time
end
finished?() click to toggle source

NOTE: This is not OT compliant. This is meant only for testing.

# File lib/signalfx_test_tracer/span.rb, line 102
def finished?
  @end_time != nil
end
get_baggage_item(_key) click to toggle source

Get a baggage item

@param key [String] the key of the baggage item

@return Value of the baggage item

# File lib/signalfx_test_tracer/span.rb, line 54
def get_baggage_item(_key)
  nil
end
log(*args) click to toggle source

Add a log entry to this span

@deprecated Use {#log_kv} instead.

# File lib/signalfx_test_tracer/span.rb, line 61
def log(*args)
  warn 'Span#log is deprecated. Please use Span#log_kv instead.'
  log_kv(*args)
end
log_kv(timestamp: Time.now, **fields) click to toggle source

Add a log entry to this span

@param timestamp [Time] time of the log @param fields [Hash] Additional information to log

# File lib/signalfx_test_tracer/span.rb, line 70
def log_kv(timestamp: Time.now, **fields)
  @logs << fields.merge(timestamp: timestamp)
  nil
end
record_exception(exception, record_error=true) click to toggle source

Record an exception on this span

# File lib/signalfx_test_tracer/span.rb, line 76
def record_exception(exception, record_error=true)
  set_tag(:error, true) if record_error
  set_tag(:'sfx.error.kind', exception.class.to_s) 
  set_tag(:'sfx.error.message', exception.message)
  if not exception.backtrace.nil?
    set_tag(:'sfx.error.stack', exception.backtrace.join('\n'))
  end
end
set_baggage_item(_key, _value) click to toggle source

Set a baggage item on the span

@param key [String] the key of the baggage item @param value [String] the value of the baggage item

# File lib/signalfx_test_tracer/span.rb, line 45
def set_baggage_item(_key, _value)
  self
end
set_tag(key, value) click to toggle source

Set a tag value on this span

@param key [String] the key of the tag @param value [String, Numeric, Boolean] the value of the tag. If it's not a String, Numeric, or Boolean it will be encoded with to_s

# File lib/signalfx_test_tracer/span.rb, line 36
def set_tag(key, value)
  sanitized_value = valid_tag_value?(value) ? value : value.to_s
  @tags = @tags.merge(key.to_s => sanitized_value)
end
to_s() click to toggle source
# File lib/signalfx_test_tracer/span.rb, line 92
def to_s
  "Span(operation_name=#{@operation_name}, " \
    "tags=#{@tags}, " \
    "logs=#{@logs}, " \
    "start_time=#{@start_time}, " \
    "end_time=#{@end_time}, " \
    "context=#{@context})"
end
tracer() click to toggle source
# File lib/signalfx_test_tracer/span.rb, line 27
def tracer
  @tracer
end

Private Instance Methods

valid_tag_value?(value) click to toggle source
# File lib/signalfx_test_tracer/span.rb, line 108
def valid_tag_value?(value)
  value.is_a?(String) ||
    value.is_a?(Numeric) ||
    value.is_a?(TrueClass) ||
    value.is_a?(FalseClass)
end