Class: Bigcommerce::Lightstep::Tracer
- Inherits:
-
Object
- Object
- Bigcommerce::Lightstep::Tracer
- Includes:
- Singleton
- Defined in:
- lib/bigcommerce/lightstep/tracer.rb
Overview
Global tracer
Instance Method Summary collapse
-
#active_span ⇒ ::LightStep::Span|NilClass
Return the active span.
-
#clear_active_span! ⇒ Object
Clear the active span.
- #enabled? ⇒ Boolean
- #reporter_initialized? ⇒ Boolean
-
#start_span(name, context: nil, start_time: nil, tags: nil) ⇒ Object
Start a new span.
Instance Method Details
#active_span ⇒ ::LightStep::Span|NilClass
Return the active span
87 88 89 |
# File 'lib/bigcommerce/lightstep/tracer.rb', line 87 def active_span Thread.current[:lightstep_active_span] end |
#clear_active_span! ⇒ Object
Clear the active span
94 95 96 |
# File 'lib/bigcommerce/lightstep/tracer.rb', line 94 def clear_active_span! Thread.current[:lightstep_active_span] = nil end |
#enabled? ⇒ Boolean
108 109 110 |
# File 'lib/bigcommerce/lightstep/tracer.rb', line 108 def enabled? Bigcommerce::Lightstep.enabled end |
#reporter_initialized? ⇒ Boolean
101 102 103 |
# File 'lib/bigcommerce/lightstep/tracer.rb', line 101 def reporter_initialized? tracer.instance_variable_defined?(:@reporter) && !tracer.instance_variable_get(:@reporter).nil? end |
#start_span(name, context: nil, start_time: nil, tags: nil) ⇒ Object
Start a new span
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/bigcommerce/lightstep/tracer.rb', line 38 def start_span(name, context: nil, start_time: nil, tags: nil) if enabled? # enable the tracer (for fork support) tracer.enable elsif tracer && tracer.enabled? # We are not enabled and the tracer is currently on # https://github.com/lightstep/lightstep-tracer-ruby/blob/master/lib/lightstep/tracer.rb#L129-L130 # we have to set this through instance_variable_set because of a bug in the core lightstep gem which # assumes the presence of a reporter, which happens in the initializer, which may not be called # because the reporter attempts to flush spans on initialization (which is bad if lightstep isn't # present) tracer.instance_variable_set(:@enabled, false) end # find the currently active span last_active_span = active_span # determine who is the actual parent span current_parent = determine_parent(context: context) # create new span span = ::LightStep.start_span(name, child_of: current_parent, start_time: start_time, tags: ) # set it as the active span self.active_span = span # run the process begin result = yield span rescue StandardError span.set_tag('error', true) raise ensure # finish this span if the reporter is initialized span.finish if enabled? && reporter_initialized? # now set back the parent as the active span self.active_span = last_active_span end # return result result end |