Sha256: 14a939caadce659dc6d487f2dc98870cbb0b22485c5ea1dc9594dfdc96145999

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module Sentry
  class Breadcrumb
    DATA_SERIALIZATION_ERROR_MESSAGE = "[data were removed due to serialization issues]"

    attr_accessor :category, :data, :level, :timestamp, :type
    attr_reader :message

    def initialize(category: nil, data: nil, message: nil, timestamp: nil, level: nil, type: nil)
      @category = category
      @data = data || {}
      @level = level
      @timestamp = timestamp || Sentry.utc_now.to_i
      @type = type
      self.message = message
    end

    def to_hash
      {
        category: @category,
        data: serialized_data,
        level: @level,
        message: @message,
        timestamp: @timestamp,
        type: @type
      }
    end

    def message=(msg)
      @message = (msg || "").byteslice(0..Event::MAX_MESSAGE_SIZE_IN_BYTES)
    end

    private

    def serialized_data
      begin
        ::JSON.parse(::JSON.generate(@data))
      rescue Exception => e
        Sentry.logger.debug(LOGGER_PROGNAME) do
          <<~MSG
can't serialize breadcrumb data because of error: #{e}
data: #{@data}
          MSG
        end

        DATA_SERIALIZATION_ERROR_MESSAGE
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sentry-ruby-core-4.8.3 lib/sentry/breadcrumb.rb
sentry-ruby-core-4.8.2 lib/sentry/breadcrumb.rb
sentry-ruby-core-4.8.1 lib/sentry/breadcrumb.rb