Class: Skylight::Core::Subscriber Private
- Inherits:
-
Object
- Object
- Skylight::Core::Subscriber
- Includes:
- Util::Logging
- Defined in:
- lib/skylight/core/subscriber.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: Notification
Instance Attribute Summary collapse
- #config ⇒ Object readonly private
Instance Method Summary collapse
- #finish(name, id, payload) ⇒ Object private
-
#initialize(config, instrumenter) ⇒ Subscriber
constructor
private
A new instance of Subscriber.
- #publish(name, *args) ⇒ Object private
- #register! ⇒ Object private
- #start(name, id, payload) ⇒ Object private
- #unregister! ⇒ Object private
Methods included from Util::Logging
#config_for_logging, #debug, #error, #fmt, #info, #log, #log_context, #log_env_prefix, #raise_on_error?, #t, #trace, #trace?, #warn
Constructor Details
#initialize(config, instrumenter) ⇒ Subscriber
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 Subscriber.
8 9 10 11 12 13 |
# File 'lib/skylight/core/subscriber.rb', line 8 def initialize(config, instrumenter) @config = config @normalizers = Normalizers.build(config) @instrumenter = instrumenter @subscribers = [] 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.
6 7 8 |
# File 'lib/skylight/core/subscriber.rb', line 6 def config @config end |
Instance Method Details
#finish(name, id, payload) ⇒ 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.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/skylight/core/subscriber.rb', line 70 def finish(name, id, payload) return if @instrumenter.disabled? return unless trace = @instrumenter.current_trace while curr = trace.notifications.pop if curr.name == name begin normalize_after(trace, curr.span, name, payload) ensure = { } [:exception] = payload[:exception] if payload[:exception] [:exception_object] = payload[:exception_object] if payload[:exception_object] trace.done(curr.span, ) if curr.span end return end end rescue Exception => e error "Subscriber#finish error; msg=%s", e. debug "trace=%s", trace.inspect debug "in: name=%s", name.inspect debug "in: payload=%s", payload.inspect t { e.backtrace.join("\n") } nil end |
#publish(name, *args) ⇒ 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.
97 98 99 |
# File 'lib/skylight/core/subscriber.rb', line 97 def publish(name, *args) # Ignored for now because nothing in rails uses it end |
#register! ⇒ 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.
15 16 17 18 19 20 |
# File 'lib/skylight/core/subscriber.rb', line 15 def register! unregister! @normalizers.keys.each do |key| @subscribers << ActiveSupport::Notifications.subscribe(key, self) end end |
#start(name, id, payload) ⇒ 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.
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 |
# File 'lib/skylight/core/subscriber.rb', line 42 def start(name, id, payload) return if @instrumenter.disabled? return unless trace = @instrumenter.current_trace result = normalize(trace, name, payload) unless result == :skip case result.size when 3, 4 cat, title, desc, = result else raise "Invalid normalizer result: #{result.inspect}" end span = trace.instrument(cat, title, desc, ) end trace.notifications << Notification.new(name, span) rescue Exception => e error "Subscriber#start error; msg=%s", e. debug "trace=%s", trace.inspect debug "in: name=%s", name.inspect debug "in: payload=%s", payload.inspect debug "out: cat=%s, title=%s, desc=%s", cat.inspect, name.inspect, desc.inspect t { e.backtrace.join("\n") } nil end |
#unregister! ⇒ 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.
22 23 24 25 26 |
# File 'lib/skylight/core/subscriber.rb', line 22 def unregister! until @subscribers.empty? ActiveSupport::Notifications.unsubscribe @subscribers.shift end end |