Sha256: 38ca718c8a962cb5feb1add460af13e0e8ab620eb759be4fb9c7252b95416e29

Contents?: true

Size: 1.78 KB

Versions: 2

Compression:

Stored size: 1.78 KB

Contents

module Sentry
  module Cron
    module MonitorCheckIns
      MAX_SLUG_LENGTH = 50

      module Patch
        def perform(*args)
          slug = self.class.sentry_monitor_slug
          monitor_config = self.class.sentry_monitor_config

          check_in_id = Sentry.capture_check_in(slug,
                                                :in_progress,
                                                monitor_config: monitor_config)

          start = Sentry.utc_now.to_i
          ret = super
          duration = Sentry.utc_now.to_i - start

          Sentry.capture_check_in(slug,
                                  :ok,
                                  check_in_id: check_in_id,
                                  duration: duration,
                                  monitor_config: monitor_config)

          ret
        rescue Exception
          duration = Sentry.utc_now.to_i - start

          Sentry.capture_check_in(slug,
                                  :error,
                                  check_in_id: check_in_id,
                                  duration: duration,
                                  monitor_config: monitor_config)

          raise
        end
      end

      module ClassMethods
        def sentry_monitor_check_ins(slug: nil, monitor_config: nil)
          @sentry_monitor_slug = slug
          @sentry_monitor_config = monitor_config

          prepend Patch
        end

        def sentry_monitor_slug
          @sentry_monitor_slug ||= begin
            slug = name.gsub('::', '-').downcase
            slug[-MAX_SLUG_LENGTH..-1] || slug
          end
        end

        def sentry_monitor_config
          @sentry_monitor_config
        end
      end

      extend ClassMethods

      def self.included(base)
        base.extend(ClassMethods)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
sentry-ruby-5.14.0 lib/sentry/cron/monitor_check_ins.rb
sentry-ruby-core-5.14.0 lib/sentry/cron/monitor_check_ins.rb