Sha256: 2bb9452eaea4828ec360984ff42947747fa77773fd20ba7e0ee3c24b0983a8f6

Contents?: true

Size: 1.25 KB

Versions: 6

Compression:

Stored size: 1.25 KB

Contents

module Skylight
  class Subscriber
    include Util::Logging

    attr_reader :config

    def initialize(config)
      @config      = config
      @subscriber  = nil
      @normalizers = Normalizers.build(config)
    end

    def register!
      unregister! if @subscriber
      @subscriber = ActiveSupport::Notifications.subscribe nil, self
    end

    def unregister!
      ActiveSupport::Notifications.unsubscribe @subscriber
      @subscriber = nil
    end

    def start(name, id, payload)
      return unless trace = Instrumenter.current_trace

      cat, title, desc, annot = normalize(trace, name, payload)
      trace.start(now - gc_time, cat, title, desc, annot)

      trace
    rescue Exception => e
      error "Subscriber#start error; msg=%s", e.message
    end

    def finish(name, id, payload)
      return unless trace = Instrumenter.current_trace
      trace.stop(now - gc_time)
    rescue Exception => e
      error "Subscriber#finish error; msg=%s", e.message
    end

    def publish(name, *args)
      # Ignored for now because nothing in rails uses it
    end

  private

    def normalize(*args)
      @normalizers.normalize(*args)
    end

    def gc_time
      GC.update
      GC.time
    end

    def now
      Util::Clock.micros
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
skylight-0.1.5.alpha2 lib/skylight/subscriber.rb
skylight-0.1.5.alpha1 lib/skylight/subscriber.rb
skylight-0.1.4 lib/skylight/subscriber.rb
skylight-0.1.4.alpha3 lib/skylight/subscriber.rb
skylight-0.1.4.alpha2 lib/skylight/subscriber.rb
skylight-0.1.4.alpha1 lib/skylight/subscriber.rb