Class: Skylight::Core::Subscriber Private

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#configObject (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

#normalizersObject (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 normalizers
  @normalizers
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.



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 47

def finish(name, _id, payload)
  return if @instrumenter.disabled?
  return unless (trace = @instrumenter.current_trace)

  while (curr = trace.notifications.pop)
    next unless curr.name == name

    meta = {}
    meta[:exception] = payload[:exception] if payload[:exception]
    meta[:exception_object] = payload[:exception_object] if payload[:exception_object]
    trace.done(curr.span, meta) if curr.span
    normalize_after(trace, curr.span, name, payload)
    return
  end
rescue Exception => e
  error "Subscriber#finish error; msg=%s", e.message
  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.



70
71
72
# File 'lib/skylight/core/subscriber.rb', line 70

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.



41
42
43
44
45
# File 'lib/skylight/core/subscriber.rb', line 41

def start(name, _id, payload)
  return if @instrumenter.disabled?
  return unless (trace = @instrumenter.current_trace)
  _start(trace, name, payload)
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
# File 'lib/skylight/core/subscriber.rb', line 22

def unregister!
  ActiveSupport::Notifications.unsubscribe @subscribers.shift until @subscribers.empty?
end