Class: Skylight::Core::Instrumenter Private
- Inherits:
-
Object
- Object
- Skylight::Core::Instrumenter
- Includes:
- Util::Logging
- Defined in:
- lib/skylight/core/instrumenter.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: TraceInfo
Constant Summary collapse
- KEY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
:__skylight_current_trace- TOO_MANY_UNIQUES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"<too many unique descriptions>"
Instance Attribute Summary collapse
- #config ⇒ Object readonly private
- #gc ⇒ Object readonly private
- #trace_info ⇒ Object readonly private
- #uuid ⇒ Object readonly private
Class Method Summary collapse
- .match?(string, regex) ⇒ Boolean private
- .native_new(_uuid, _config_env) ⇒ Object private
- .new(config) ⇒ Object private
- .trace_class ⇒ Object private
Instance Method Summary collapse
- #broken! ⇒ Object private
- #check_install! ⇒ Object private
- #current_trace ⇒ Object private
- #current_trace=(trace) ⇒ Object private
- #disable ⇒ Object private
- #disabled? ⇒ Boolean private
- #done(span, meta = nil) ⇒ Object private
- #ignore?(trace) ⇒ Boolean private
-
#initialize(uuid, config) ⇒ Instrumenter
constructor
private
A new instance of Instrumenter.
- #instrument(cat, title = nil, desc = nil, meta = nil) ⇒ Object private
- #limited_description(description) ⇒ Object private
- #log_context ⇒ Object private
- #match?(string, regex) ⇒ Boolean private
- #native_start ⇒ Object private
- #native_stop ⇒ Object private
- #native_submit_trace(_trace) ⇒ Object private
- #native_track_desc(_endpoint, _description) ⇒ Object private
- #process(trace) ⇒ Object private
-
#process_sql(sql) ⇒ Object
private
Return [title, sql].
- #shutdown ⇒ Object private
- #span_correlation_header(span) ⇒ Object private
- #start! ⇒ Object private
- #trace(endpoint, cat, title = nil, desc = nil, meta = nil) ⇒ Object private
Methods included from Util::Logging
#config_for_logging, #debug, #error, #fmt, #info, #log, #log_env_prefix, #raise_on_error?, #t, #trace?, #warn
Constructor Details
#initialize(uuid, config) ⇒ Instrumenter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Instrumenter.
47 48 49 50 51 52 53 54 55 |
# File 'lib/skylight/core/instrumenter.rb', line 47 def initialize(uuid, config) @uuid = uuid @gc = config.gc @config = config @subscriber = Subscriber.new(config, self) key = "#{KEY}_#{self.class.trace_class.name}".gsub(/\W/, '_') @trace_info = @config[:trace_info] || TraceInfo.new(key) end |
Instance Attribute Details
#config ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 |
# File 'lib/skylight/core/instrumenter.rb', line 28 def config @config end |
#gc ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 |
# File 'lib/skylight/core/instrumenter.rb', line 28 def gc @gc end |
#trace_info ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 |
# File 'lib/skylight/core/instrumenter.rb', line 28 def trace_info @trace_info end |
#uuid ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 |
# File 'lib/skylight/core/instrumenter.rb', line 28 def uuid @uuid end |
Class Method Details
.match?(string, regex) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
162 163 164 165 166 |
# File 'lib/skylight/core/instrumenter.rb', line 162 def self.match?(string, regex) @scanner ||= StringScanner.new('') @scanner.string = string @scanner.match?(regex) end |
.native_new(_uuid, _config_env) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 |
# File 'lib/skylight/core/instrumenter.rb', line 34 def self.native_new(_uuid, _config_env) raise "not implemented" end |
.new(config) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 41 42 43 44 45 |
# File 'lib/skylight/core/instrumenter.rb', line 38 def self.new(config) config.validate! uuid = SecureRandom.uuid inst = native_new(uuid, config.to_native_env) inst.send(:initialize, uuid, config) inst end |
.trace_class ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 |
# File 'lib/skylight/core/instrumenter.rb', line 30 def self.trace_class Trace end |
Instance Method Details
#broken! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
213 214 215 216 |
# File 'lib/skylight/core/instrumenter.rb', line 213 def broken! return unless trace = @trace_info.current trace.broken! end |
#check_install! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
86 87 88 |
# File 'lib/skylight/core/instrumenter.rb', line 86 def check_install! true end |
#current_trace ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
77 78 79 |
# File 'lib/skylight/core/instrumenter.rb', line 77 def current_trace @trace_info.current end |
#current_trace=(trace) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
81 82 83 84 |
# File 'lib/skylight/core/instrumenter.rb', line 81 def current_trace=(trace) t { "setting current_trace=#{trace ? trace.uuid : "nil"}; thread=#{Thread.current.object_id}" } @trace_info.current = trace end |
#disable ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
151 152 153 154 155 156 |
# File 'lib/skylight/core/instrumenter.rb', line 151 def disable @disabled = true yield ensure @disabled = false end |
#disabled? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
158 159 160 |
# File 'lib/skylight/core/instrumenter.rb', line 158 def disabled? @disabled end |
#done(span, meta = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
218 219 220 221 |
# File 'lib/skylight/core/instrumenter.rb', line 218 def done(span, =nil) return unless trace = @trace_info.current trace.done(span, ) end |
#ignore?(trace) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
253 254 255 |
# File 'lib/skylight/core/instrumenter.rb', line 253 def ignore?(trace) config.ignored_endpoints.include?(trace.endpoint.sub(%r{<sk-segment>.+</sk-segment>}, '')) end |
#instrument(cat, title = nil, desc = nil, meta = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/skylight/core/instrumenter.rb', line 172 def instrument(cat, title=nil, desc=nil, =nil) raise ArgumentError, 'cat is required' unless cat unless trace = @trace_info.current return yield if block_given? return end cat = cat.to_s unless match?(cat, Skylight::CATEGORY_REGEX) warn "invalid skylight instrumentation category; trace=%s; value=%s", trace.uuid, cat return yield if block_given? return end cat = "other.#{cat}" unless match?(cat, Skylight::TIER_REGEX) unless sp = trace.instrument(cat, title, desc, ) return yield if block_given? return end return sp unless block_given? = {} begin yield sp rescue Exception => e = { exception: [e.class.name, e.], exception_object: e } raise e ensure trace.done(sp, ) end end |
#limited_description(description) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/skylight/core/instrumenter.rb', line 223 def limited_description(description) endpoint = @trace_info.current.endpoint if description if native_track_desc(endpoint, description) description else TOO_MANY_UNIQUES end end end |
#log_context ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
57 58 59 |
# File 'lib/skylight/core/instrumenter.rb', line 57 def log_context @log_context ||= { inst: uuid } end |
#match?(string, regex) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
168 169 170 |
# File 'lib/skylight/core/instrumenter.rb', line 168 def match?(string, regex) self.class.match?(string, regex) end |
#native_start ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
61 62 63 |
# File 'lib/skylight/core/instrumenter.rb', line 61 def native_start raise "not implemented" end |
#native_stop ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
65 66 67 |
# File 'lib/skylight/core/instrumenter.rb', line 65 def native_stop raise "not implemented" end |
#native_submit_trace(_trace) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
73 74 75 |
# File 'lib/skylight/core/instrumenter.rb', line 73 def native_submit_trace(_trace) raise "not implemented" end |
#native_track_desc(_endpoint, _description) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
69 70 71 |
# File 'lib/skylight/core/instrumenter.rb', line 69 def native_track_desc(_endpoint, _description) raise "not implemented" end |
#process(trace) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/skylight/core/instrumenter.rb', line 235 def process(trace) t { fmt "processing trace=#{trace.uuid}" } if ignore?(trace) t { fmt "ignoring trace=#{trace.uuid}" } return false end begin native_submit_trace(trace) true rescue => e warn "failed to submit trace to worker; trace=%s, err=%s", trace.uuid, e t { "BACKTRACE:\n#{e.backtrace.join("\n")}" } false end end |
#process_sql(sql) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return [title, sql]
258 259 260 |
# File 'lib/skylight/core/instrumenter.rb', line 258 def process_sql(sql) [nil, sql] end |
#shutdown ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
118 119 120 121 |
# File 'lib/skylight/core/instrumenter.rb', line 118 def shutdown @subscriber.unregister! native_stop end |
#span_correlation_header(span) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
208 209 210 211 |
# File 'lib/skylight/core/instrumenter.rb', line 208 def span_correlation_header(span) return unless trace = @trace_info.current trace.span_correlation_header(span) end |
#start! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/skylight/core/instrumenter.rb', line 90 def start! # We do this here since we can't report these issues via Gem install without stopping install entirely. check_install! t { "starting instrumenter" } unless config.validate_with_server log_error "invalid config" return end t { "starting native instrumenter" } unless native_start warn "failed to start instrumenter" return end config.gc.enable @subscriber.register! self rescue Exception => e log_error "failed to start instrumenter; msg=%s; config=%s", e., config.inspect t { e.backtrace.join("\n") } nil end |
#trace(endpoint, cat, title = nil, desc = nil, meta = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/skylight/core/instrumenter.rb', line 123 def trace(endpoint, cat, title=nil, desc=nil, =nil) # If a trace is already in progress, continue with that one if trace = @trace_info.current return yield(trace) if block_given? return trace end begin trace = self.class.trace_class.new(self, endpoint, Util::Clock.nanos, cat, title, desc, ) rescue Exception => e log_error e. t { e.backtrace.join("\n") } return end @trace_info.current = trace return trace unless block_given? begin yield trace ensure @trace_info.current = nil t { "instrumenter submitting trace; trace=#{trace.uuid}" } trace.submit end end |