Class: OpenTracingTestTracer::Span

Inherits:
Object
  • Object
show all
Defined in:
lib/signalfx_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, tracer: nil) ⇒ Span

Returns a new instance of Span.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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

Instance Attribute Details

#contextObject (readonly)

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



8
9
10
# File 'lib/signalfx_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/signalfx_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/signalfx_test_tracer/span.rb', line 8

def logs
  @logs
end

#operation_nameObject

Returns the value of attribute operation_name.



5
6
7
# File 'lib/signalfx_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/signalfx_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/signalfx_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/signalfx_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



88
89
90
# File 'lib/signalfx_test_tracer/span.rb', line 88

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)


102
103
104
# File 'lib/signalfx_test_tracer/span.rb', line 102

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



54
55
56
# File 'lib/signalfx_test_tracer/span.rb', line 54

def get_baggage_item(_key)
  nil
end

#log(*args) ⇒ Object

Deprecated.

Use #log_kv instead.

Add a log entry to this span



61
62
63
64
# 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) ⇒ 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



70
71
72
73
# 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) ⇒ Object

Record an exception on this span



76
77
78
79
80
81
82
83
# 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) ⇒ 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



45
46
47
# File 'lib/signalfx_test_tracer/span.rb', line 45

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



36
37
38
39
# 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_sObject



92
93
94
95
96
97
98
99
# 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

#tracerObject



27
28
29
# File 'lib/signalfx_test_tracer/span.rb', line 27

def tracer
  @tracer
end