Class: LightStep::Tracer
- Inherits:
-
Object
- Object
- LightStep::Tracer
- Defined in:
- lib/lightstep/tracer.rb
Direct Known Subclasses
Defined Under Namespace
Classes: ConfigurationError, Error
Constant Summary collapse
- FORMAT_TEXT_MAP =
1- FORMAT_BINARY =
2- FORMAT_RACK =
3
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#guid ⇒ Object
readonly
Returns the value of attribute guid.
Instance Method Summary collapse
-
#disable(discard: true) ⇒ Object
Disables the tracer.
-
#enable ⇒ Object
Enables the tracer.
-
#enabled? ⇒ Boolean
True if the tracer is enabled.
-
#extract(operation_name, format, carrier) ⇒ Span
Extract a span from a carrier.
-
#finish_span(span) ⇒ Object
Internal use only.
-
#flush ⇒ Object
Flush to the Transport.
-
#initialize(component_name:, access_token: nil, transport: nil, tags: {}) ⇒ Object
constructor
Initialize a new tracer.
-
#inject(span, format, carrier) ⇒ Object
Inject a span into the given carrier.
- #max_log_records ⇒ Object
- #max_log_records=(max) ⇒ Object
- #max_span_records ⇒ Object
- #max_span_records=(max) ⇒ Object
-
#report_period_seconds=(seconds) ⇒ Object
Set the report flushing period.
-
#start_span(operation_name, child_of: nil, start_time: nil, tags: nil) ⇒ Span
Starts a new span.
Constructor Details
#initialize(component_name:, access_token: nil, transport: nil, tags: {}) ⇒ Object
Initialize a new tracer. Either an access_token or a transport must be provided. A component_name is always required.
29 30 31 |
# File 'lib/lightstep/tracer.rb', line 29 def initialize(component_name:, access_token: nil, transport: nil, tags: {}) configure(component_name: component_name, access_token: access_token, transport: transport, tags: ) end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
19 20 21 |
# File 'lib/lightstep/tracer.rb', line 19 def access_token @access_token end |
#guid ⇒ Object (readonly)
Returns the value of attribute guid.
19 20 21 |
# File 'lib/lightstep/tracer.rb', line 19 def guid @guid end |
Instance Method Details
#disable(discard: true) ⇒ Object
Disables the tracer
141 142 143 144 145 |
# File 'lib/lightstep/tracer.rb', line 141 def disable(discard: true) @enabled = false @reporter.clear if discard @reporter.flush end |
#enable ⇒ Object
Enables the tracer
135 136 137 |
# File 'lib/lightstep/tracer.rb', line 135 def enable @enabled = true end |
#enabled? ⇒ Boolean
Returns true if the tracer is enabled.
129 130 131 132 |
# File 'lib/lightstep/tracer.rb', line 129 def enabled? return @enabled if defined?(@enabled) @enabled = true end |
#extract(operation_name, format, carrier) ⇒ Span
Extract a span from a carrier
113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/lightstep/tracer.rb', line 113 def extract(operation_name, format, carrier) case format when LightStep::Tracer::FORMAT_TEXT_MAP extract_from_text_map(operation_name, carrier) when LightStep::Tracer::FORMAT_BINARY warn 'Binary join format not yet implemented' nil when LightStep::Tracer::FORMAT_RACK extract_from_rack(operation_name, carrier) else warn 'Unknown join format' nil end end |
#finish_span(span) ⇒ Object
Internal use only.
155 156 157 158 |
# File 'lib/lightstep/tracer.rb', line 155 def finish_span(span) return unless enabled? @reporter.add_span(span) end |
#flush ⇒ Object
Flush to the Transport
148 149 150 151 |
# File 'lib/lightstep/tracer.rb', line 148 def flush return unless enabled? @reporter.flush end |
#inject(span, format, carrier) ⇒ Object
Inject a span into the given carrier
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/lightstep/tracer.rb', line 95 def inject(span, format, carrier) case format when LightStep::Tracer::FORMAT_TEXT_MAP inject_to_text_map(span, carrier) when LightStep::Tracer::FORMAT_BINARY warn 'Binary inject format not yet implemented' when LightStep::Tracer::FORMAT_RACK inject_to_rack(span, carrier) else warn 'Unknown inject format' end end |
#max_log_records ⇒ Object
33 34 35 |
# File 'lib/lightstep/tracer.rb', line 33 def max_log_records @max_log_records ||= DEFAULT_MAX_LOG_RECORDS end |
#max_log_records=(max) ⇒ Object
37 38 39 |
# File 'lib/lightstep/tracer.rb', line 37 def max_log_records=(max) @max_log_records = [MIN_MAX_LOG_RECORDS, max].max end |
#max_span_records ⇒ Object
41 42 43 |
# File 'lib/lightstep/tracer.rb', line 41 def max_span_records @max_span_records ||= DEFAULT_MAX_SPAN_RECORDS end |
#max_span_records=(max) ⇒ Object
45 46 47 48 |
# File 'lib/lightstep/tracer.rb', line 45 def max_span_records=(max) @max_span_records = [MIN_MAX_SPAN_RECORDS, max].max @reporter.max_span_records = @max_span_records end |
#report_period_seconds=(seconds) ⇒ Object
Set the report flushing period. If set to 0, no flushing will be done, you must manually call flush.
52 53 54 |
# File 'lib/lightstep/tracer.rb', line 52 def report_period_seconds=(seconds) @reporter.period = seconds end |
#start_span(operation_name, child_of: nil, start_time: nil, tags: nil) ⇒ Span
Starts a new span.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/lightstep/tracer.rb', line 64 def start_span(operation_name, child_of: nil, start_time: nil, tags: nil) child_of_id = nil trace_id = nil if Span === child_of child_of_id = child_of.span_context.id trace_id = child_of.span_context.trace_id else trace_id = LightStep.guid end span = Span.new( tracer: self, operation_name: operation_name, child_of_id: child_of_id, trace_id: trace_id, start_micros: start_time.nil? ? LightStep.micros(Time.now) : LightStep.micros(start_time), tags: , max_log_records: max_log_records ) if Span === child_of span.set_baggage(child_of.span_context.baggage) end span end |