Class: OpenTracingTestTracer::Span

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Span.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/opentracing_test_tracer/span.rb', line 10

def initialize(
  context:,
  operation_name:,
  start_time: Time.now,
  tags: {},
  references: nil
)
  @context = context
  @operation_name = operation_name
  @start_time = start_time
  @tags = tags
  @logs = []
  @references = references
end

Instance Attribute Details

#contextObject (readonly)

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



8
9
10
# File 'lib/opentracing_test_tracer/span.rb', line 8

def context
  @context
end

#end_timeObject (readonly)

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



8
9
10
# File 'lib/opentracing_test_tracer/span.rb', line 8

def end_time
  @end_time
end

#logsObject (readonly)

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



8
9
10
# File 'lib/opentracing_test_tracer/span.rb', line 8

def logs
  @logs
end

#operation_nameObject

Returns the value of attribute operation_name.



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

def operation_name
  @operation_name
end

#referencesObject (readonly)

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



8
9
10
# File 'lib/opentracing_test_tracer/span.rb', line 8

def references
  @references
end

#start_timeObject (readonly)

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



8
9
10
# File 'lib/opentracing_test_tracer/span.rb', line 8

def start_time
  @start_time
end

#tagsObject (readonly)

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



8
9
10
# File 'lib/opentracing_test_tracer/span.rb', line 8

def tags
  @tags
end

Instance Method Details

#finish(end_time: Time.now) ⇒ Object

Parameters:

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

    custom end time, if not now



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

def finish(end_time: Time.now)
  @end_time = end_time
end

#finished?Boolean

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

Returns:

  • (Boolean)


86
87
88
# File 'lib/opentracing_test_tracer/span.rb', line 86

def finished?
  @end_time != nil
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



48
49
50
# File 'lib/opentracing_test_tracer/span.rb', line 48

def get_baggage_item(_key)
  nil
end

#log(*args) ⇒ Object

Deprecated.

Use #log_kv instead.

Add a log entry to this span



55
56
57
58
# File 'lib/opentracing_test_tracer/span.rb', line 55

def log(*args)
  warn 'Span#log is deprecated. Please use Span#log_kv instead.'
  log_kv(*args)
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



64
65
66
67
# File 'lib/opentracing_test_tracer/span.rb', line 64

def log_kv(timestamp: Time.now, **fields)
  @logs << fields.merge(timestamp: timestamp)
  nil
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



39
40
41
# File 'lib/opentracing_test_tracer/span.rb', line 39

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



30
31
32
33
# File 'lib/opentracing_test_tracer/span.rb', line 30

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_sObject



76
77
78
79
80
81
82
83
# File 'lib/opentracing_test_tracer/span.rb', line 76

def to_s
  "Span(operation_name=#{@operation_name}, " \
    "tags=#{@tags}, " \
    "logs=#{@logs}, " \
    "start_time=#{@start_time}, " \
    "end_time=#{@end_time}, " \
    "context=#{@context})"
end