Sha256: ea916e0bc5c3d056a5cee0259c4ad67d219cd8a95d129e0f21096019d7c8846f

Contents?: true

Size: 1.69 KB

Versions: 19

Compression:

Stored size: 1.69 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]

            Sentry.with_child_span(**options) do |child_span|
              # duration in ActiveSupport is computed in millisecond
              # so we need to covert it as second before calculating the timestamp
              child_span.set_timestamp(child_span.start_timestamp + duration / 1000)
              yield(child_span) if block_given?
            end
          end
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
sentry-rails-5.16.1 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.15.2 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.15.1 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.15.0 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.14.0 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.13.0 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.12.0 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.11.0 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.10.0 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.9.0 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.8.0 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.7.0 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.6.0 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.5.0 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.4.2 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.4.1 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.4.0 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.3.1 lib/sentry/rails/tracing/abstract_subscriber.rb
sentry-rails-5.3.0 lib/sentry/rails/tracing/abstract_subscriber.rb