<commit_before>require 'rollbar/truncation/mixin'

module Rollbar
  module Truncation
    class FramesStrategy
      include ::Rollbar::Truncation::Mixin

      def self.call(payload)
        new.call(payload)
      end

      def call(payload)
        new_payload = payload.clone
        body = new_payload['data'][:body]
        trace_key = body[:trace_chain] ? :trace_chain : :trace

        if trace_key == :trace_chain
          truncate_trace_chain(body)
        elsif trace_key == :trace
          truncate_trace(body)
        end

        dump(new_payload)
      end

      def truncate_trace(body)
        trace_data = body[:trace]
        frames = trace_data[:frames]
        trace_data[:frames] = select_frames(frames)

        body[:trace][:frames] = select_frames(body[:trace][:frames])
      end

      def truncate_trace_chain(body)
        chain = body[:trace_chain]

        body[:trace_chain] = chain.map do |trace_data|
          frames = trace_data[:frames]
          trace_data[:frames] = select_frames(frames)
          trace_data
        end
      end
    end
  end
end
<commit_msg>Remove unneeded trace_key variable in StringsStrategy.<commit_after>require 'rollbar/truncation/mixin'

module Rollbar
  module Truncation
    class FramesStrategy
      include ::Rollbar::Truncation::Mixin

      def self.call(payload)
        new.call(payload)
      end

      def call(payload)
        new_payload = payload.clone
        body = new_payload['data'][:body]

        if body[:trace_chain]
          truncate_trace_chain(body)
        else
          truncate_trace(body)
        end

        dump(new_payload)
      end

      def truncate_trace(body)
        trace_data = body[:trace]
        frames = trace_data[:frames]
        trace_data[:frames] = select_frames(frames)

        body[:trace][:frames] = select_frames(body[:trace][:frames])
      end

      def truncate_trace_chain(body)
        chain = body[:trace_chain]

        body[:trace_chain] = chain.map do |trace_data|
          frames = trace_data[:frames]
          trace_data[:frames] = select_frames(frames)
          trace_data
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.09259259259259259, 'fraction_numerical': 0.0, 'mean_word_length': 2.340030911901082, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1999009', 'n_tokens_mistral': 655, 'n_tokens_neox': 635, 'n_words': 126}