Class: Lenjador::Tracer::Span

Inherits:
Object
  • Object
show all
Defined in:
lib/lenjador/tracer/span.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, operation_name, logger, start_time: Time.now, tags: {}) ⇒ Span

Returns a new instance of Span.



9
10
11
12
13
14
15
16
# File 'lib/lenjador/tracer/span.rb', line 9

def initialize(context, operation_name, logger, start_time: Time.now, tags: {})
  @context = context
  @operation_name = operation_name
  @logger = logger
  @start_time = start_time
  @tags = tags
  @logger.info "Span [#{@operation_name}] started", trace_information
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



5
6
7
# File 'lib/lenjador/tracer/span.rb', line 5

def context
  @context
end

#operation_name=(value) ⇒ Object (writeonly)

Sets the attribute operation_name

Parameters:

  • value

    the value to set the attribute operation_name to.



7
8
9
# File 'lib/lenjador/tracer/span.rb', line 7

def operation_name=(value)
  @operation_name = value
end

Instance Method Details

#finish(end_time: Time.now) ⇒ Object

Parameters:

  • end_time (Time) (defaults to: Time.now)

    custom end time, if not now



65
66
67
68
69
# File 'lib/lenjador/tracer/span.rb', line 65

def finish(end_time: Time.now)
  @logger.info "Span [#{@operation_name}] finished", trace_information(
    execution_time: end_time - @start_time
  )
end

#get_baggage_item(key) ⇒ Object

Get a baggage item

Parameters:

  • key (String)

    the key of the baggage item

Returns:

  • Value of the baggage item



40
41
42
# File 'lib/lenjador/tracer/span.rb', line 40

def get_baggage_item(key)
  nil
end

#log(event: nil, timestamp: Time.now, **fields) ⇒ Object

Add a log entry to this span

Parameters:

  • event (String) (defaults to: nil)

    event name for the log

  • timestamp (Time) (defaults to: Time.now)

    time of the log

  • fields (Hash)

    Additional information to log



49
50
51
# File 'lib/lenjador/tracer/span.rb', line 49

def log(event: nil, timestamp: Time.now, **fields)
  @logger.info "Span [#{@operation_name}] #{event}", trace_information.merge(fields)
end

#log_kv(timestamp: Time.now, **fields) ⇒ Object

Add a log entry to this span

Parameters:

  • timestamp (Time) (defaults to: Time.now)

    time of the log

  • fields (Hash)

    Additional information to log



57
58
59
60
# File 'lib/lenjador/tracer/span.rb', line 57

def log_kv(timestamp: Time.now, **fields)
  event = fields.fetch(:event, 'unknown')
  @logger.info "Span [#{@operation_name}] #{event}", trace_information.merge(fields)
end

#set_baggage_item(key, value) ⇒ Object

Set a baggage item on the span

Parameters:

  • key (String)

    the key of the baggage item

  • value (String)

    the value of the baggage item



31
32
33
# File 'lib/lenjador/tracer/span.rb', line 31

def set_baggage_item(key, value)
  self
end

#set_tag(key, value) ⇒ Object

Set a tag value on this span

a String, Numeric, or Boolean it will be encoded with to_s

Parameters:

  • key (String)

    the key of the tag

  • value (String, Numeric, Boolean)

    the value of the tag. If it’s not



23
24
25
# File 'lib/lenjador/tracer/span.rb', line 23

def set_tag(key, value)
  @tags = @tags.merge(key => value)
end

#to_hObject

Deprecated.

This is not in OpenTracing API. It will be removed soon.



72
73
74
# File 'lib/lenjador/tracer/span.rb', line 72

def to_h
  trace_information
end