Class: Labkit::Tracing::Adapters::OpentracingSpan

Inherits:
BaseSpan
  • Object
show all
Defined in:
lib/labkit/tracing/adapters/opentracing_span.rb

Instance Attribute Summary collapse

Attributes inherited from BaseSpan

#span

Instance Method Summary collapse

Constructor Details

#initialize(span_or_scope) ⇒ OpentracingSpan

Returns a new instance of OpentracingSpan.



9
10
11
12
13
14
15
16
17
# File 'lib/labkit/tracing/adapters/opentracing_span.rb', line 9

def initialize(span_or_scope)
  if span_or_scope.respond_to?(:span)
    @scope = span_or_scope
    @span = span_or_scope.span
  else
    @scope = nil
    @span = span_or_scope
  end
end

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



7
8
9
# File 'lib/labkit/tracing/adapters/opentracing_span.rb', line 7

def scope
  @scope
end

Instance Method Details

#closeObject



44
45
46
# File 'lib/labkit/tracing/adapters/opentracing_span.rb', line 44

def close
  finish
end

#contextObject



48
49
50
# File 'lib/labkit/tracing/adapters/opentracing_span.rb', line 48

def context
  span.context
end

#finish(**opts) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/labkit/tracing/adapters/opentracing_span.rb', line 34

def finish(**opts)
  if opts[:end_timestamp]
    span.finish(end_time: opts[:end_timestamp])
  else
    span.finish
  end

  scope&.close
end

#log_event(name, **attributes) ⇒ Object



23
24
25
# File 'lib/labkit/tracing/adapters/opentracing_span.rb', line 23

def log_event(name, **attributes)
  span.log_kv(**attributes, event: name)
end

#set_error(exception) ⇒ Object



27
28
29
30
31
32
# File 'lib/labkit/tracing/adapters/opentracing_span.rb', line 27

def set_error(exception)
  return if exception.blank?

  span.set_tag("error", true)
  span.log_kv(**kv_tags_for_exception(exception))
end

#set_tag(key, value) ⇒ Object



19
20
21
# File 'lib/labkit/tracing/adapters/opentracing_span.rb', line 19

def set_tag(key, value)
  span.set_tag(key, value)
end