<commit_before>require 'logger'

require 'aws/xray/version'
require 'aws/xray/errors'
require 'aws/xray/trace'
require 'aws/xray/client'
require 'aws/xray/context'
require 'aws/xray/worker'

require 'aws/xray/configuration'
require 'aws/xray/sockets'

require 'aws/xray/rack'

module Aws
  module Xray
    TRACE_HEADER = 'X-Amzn-Trace-Id'.freeze

    @config = Configuration.new
    class << self
      attr_reader :config
    end
    Worker.reset(Worker::Configuration.new)

    # @param [String] name a logical name of this tracing context.
    def self.trace(name: nil)
      name = name || config.name || raise(MissingNameError)
      Context.with_new_context(name, Trace.generate) do
        Context.current.start_segment do |seg|
          yield seg
        end
      end
    end

    # Overwrite under lying tracing name at once. If current context does not
    # set to current thread, do nothing.
    # @param [String] name
    def self.overwrite(name:, &block)
      if Context.started?
        Context.current.overwrite(name: name, &block)
      else
        block.call
      end
    end
  end
end<commit_msg>Open singleton class context again<commit_after>require 'logger'

require 'aws/xray/version'
require 'aws/xray/errors'
require 'aws/xray/trace'
require 'aws/xray/client'
require 'aws/xray/context'
require 'aws/xray/worker'

require 'aws/xray/configuration'
require 'aws/xray/sockets'

require 'aws/xray/rack'

module Aws
  module Xray
    TRACE_HEADER = 'X-Amzn-Trace-Id'.freeze

    @config = Configuration.new
    class << self
      attr_reader :config
    end
    Worker.reset(Worker::Configuration.new)

    class << self
      # @param [String] name a logical name of this tracing context.
      def trace(name: nil)
        name = name || config.name || raise(MissingNameError)
        Context.with_new_context(name, Trace.generate) do
          Context.current.start_segment do |seg|
            yield seg
          end
        end
      end

      # Overwrite under lying tracing name at once. If current context does not
      # set to current thread, do nothing.
      # @param [String] name
      def overwrite(name:, &block)
        if Context.started?
          Context.current.overwrite(name: name, &block)
        else
          block.call
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.0958963282937365, 'fraction_numerical': 0.0, 'mean_word_length': 2.6357927786499213, 'pattern_counts': {'":': 0, '<': 9, '<?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': '7271002', 'n_tokens_mistral': 722, 'n_tokens_neox': 705, 'n_words': 200}