lib/sentry/rails/tracing.rb in sentry-rails-4.7.2 vs lib/sentry/rails/tracing.rb in sentry-rails-4.7.3

- old
+ new

@@ -1,29 +1,39 @@ module Sentry module Rails module Tracing + START_TIMESTAMP_NAME = :sentry_start_timestamp + def self.register_subscribers(subscribers) @subscribers = subscribers end def self.subscribers @subscribers end + def self.subscribed_tracing_events + @subscribed_tracing_events ||= [] + end + def self.subscribe_tracing_events # need to avoid duplicated subscription return if @subscribed - subscribers.each(&:subscribe!) + subscribers.each do |subscriber| + subscriber.subscribe! + subscribed_tracing_events << subscriber::EVENT_NAME + end @subscribed = true end def self.unsubscribe_tracing_events return unless @subscribed subscribers.each(&:unsubscribe!) + subscribed_tracing_events.clear @subscribed = false end # this is necessary because instrumentation events don't record absolute start/finish time @@ -33,12 +43,13 @@ ::ActiveSupport::Notifications::Instrumenter.send(:prepend, SentryNotificationExtension) end SentryNotificationExtension.module_eval do def instrument(name, payload = {}, &block) - is_public_event = name[0] != "!" - - payload[:start_timestamp] = Time.now.utc.to_f if is_public_event + # only inject timestamp to the events the SDK subscribes to + if Tracing.subscribed_tracing_events.include?(name) + payload[START_TIMESTAMP_NAME] = Time.now.utc.to_f if name[0] != "!" && payload.is_a?(Hash) + end super(name, payload, &block) end end end