Class: Logasm::Tracer::Span

Inherits:
Object
  • Object
show all
Defined in:
lib/logasm/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



7
8
9
10
11
12
13
14
# File 'lib/logasm/tracer/span.rb', line 7

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/logasm/tracer/span.rb', line 5

def context
  @context
end

Instance Method Details

#finish(end_time: Time.now) ⇒ Object



54
55
56
57
58
# File 'lib/logasm/tracer/span.rb', line 54

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



38
39
40
# File 'lib/logasm/tracer/span.rb', line 38

def get_baggage_item(key)
  nil
end

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

Add a log entry to this span



47
48
49
# File 'lib/logasm/tracer/span.rb', line 47

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

#set_baggage_item(key, value) ⇒ Object

Set a baggage item on the span



29
30
31
# File 'lib/logasm/tracer/span.rb', line 29

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



21
22
23
# File 'lib/logasm/tracer/span.rb', line 21

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.



61
62
63
# File 'lib/logasm/tracer/span.rb', line 61

def to_h
  trace_information
end