Sha256: d41e67f2f72bb51de6db2458a1f44679595edf3f41e6788823b5a04571f294cc

Contents?: true

Size: 1.79 KB

Versions: 14

Compression:

Stored size: 1.79 KB

Contents

module Sentry
  module Rails
    module Tracing
      class AbstractSubscriber

        class << self
          def subscribe!
            raise NotImplementedError
          end

          def unsubscribe!
            self::EVENT_NAMES.each do |name|
              ActiveSupport::Notifications.unsubscribe(name)
            end
          end

          if ::Rails.version.to_i == 5
            def subscribe_to_event(event_names)
              event_names.each do |event_name|
                ActiveSupport::Notifications.subscribe(event_name) do |*args|
                  next unless Tracing.get_current_transaction

                  event = ActiveSupport::Notifications::Event.new(*args)
                  yield(event_name, event.duration, event.payload)
                end
              end
            end
          else
            def subscribe_to_event(event_names)
              event_names.each do |event_name|
                ActiveSupport::Notifications.subscribe(event_name) do |event|
                  next unless Tracing.get_current_transaction

                  yield(event_name, event.duration, event.payload)
                end
              end
            end
          end

          def record_on_current_span(duration:, **options)
            return unless options[:start_timestamp]

            scope = Sentry.get_current_scope
            transaction = scope.get_transaction
            return unless transaction && transaction.sampled

            span = transaction.start_child(**options)
            # duration in ActiveSupport is computed in millisecond
            # so we need to covert it as second before calculating the timestamp
            span.set_timestamp(span.start_timestamp + duration / 1000)
            yield(span) if block_given?
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
sentry-rails-5.2.1 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.2.0 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.1.1 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.1.0 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.0.2 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.0.1 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.0.0 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-4.9.2 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-4.9.1 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-4.9.0 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-4.8.3 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-4.8.2 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-4.8.1 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-4.8.0 lib/sentry/rails/tracing/abstract_subscriber.rb