Sha256: e54c785963376ab352b6f223f699b530168cdcaed59bd13018fc06a7c5b51359

Contents?: true

Size: 1.09 KB

Versions: 13

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require 'elastic_apm/naively_hashable'

module ElasticAPM
  class Stacktrace
    # @api private
    class Frame
      include NaivelyHashable

      attr_accessor(
        :abs_path,
        :filename,
        :function,
        :vars,
        :pre_context,
        :context_line,
        :post_context,
        :library_frame,
        :lineno,
        :module,
        :colno
      )

      # rubocop:disable Metrics/AbcSize
      def build_context(context_line_count)
        return unless abs_path && context_line_count > 0

        padding = (context_line_count - 1) / 2
        from = lineno - padding - 1
        from = 0 if from < 0
        to = lineno + padding - 1
        file_lines = read_lines(abs_path, from..to)

        self.context_line = file_lines[padding]
        self.pre_context  = file_lines.first(padding)
        self.post_context = file_lines.last(padding)
      end
      # rubocop:enable Metrics/AbcSize

      private

      def read_lines(path, range)
        File.readlines(path)[range]
      rescue Errno::ENOENT
        []
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
elastic-apm-2.8.1 lib/elastic_apm/stacktrace/frame.rb
elastic-apm-2.8.0 lib/elastic_apm/stacktrace/frame.rb
elastic-apm-2.7.0 lib/elastic_apm/stacktrace/frame.rb
elastic-apm-2.6.1 lib/elastic_apm/stacktrace/frame.rb
elastic-apm-2.6.0 lib/elastic_apm/stacktrace/frame.rb
elastic-apm-2.5.0 lib/elastic_apm/stacktrace/frame.rb
elastic-apm-2.4.0 lib/elastic_apm/stacktrace/frame.rb
elastic-apm-2.3.1 lib/elastic_apm/stacktrace/frame.rb
elastic-apm-2.3.0 lib/elastic_apm/stacktrace/frame.rb
elastic-apm-2.2.0 lib/elastic_apm/stacktrace/frame.rb
elastic-apm-2.1.2 lib/elastic_apm/stacktrace/frame.rb
elastic-apm-2.1.1 lib/elastic_apm/stacktrace/frame.rb
elastic-apm-2.1.0 lib/elastic_apm/stacktrace/frame.rb