diff --git a/lib/squash/ruby.rb b/lib/squash/ruby.rb index 7321f51..f61a39f 100644 --- a/lib/squash/ruby.rb +++ b/lib/squash/ruby.rb @@ -44,6 +44,7 @@ module Ruby timeout_protection: proc { |timeout, &block| timeout_protection(timeout, &block) }, + include_env: true, } # Types that are serialized directly to JSON, rather than to a hash of # object information. Subclasses are not considered members of this array. @@ -423,7 +424,12 @@ def self.http_options(uri) end def self.configuration(key) - (@configuration || CONFIGURATION_DEFAULTS)[key] || CONFIGURATION_DEFAULTS[key] + cfg = (@configuration || CONFIGURATION_DEFAULTS) + if cfg.key?(key) + cfg[key] + else + CONFIGURATION_DEFAULTS[key] + end end def self.ignored?(exception, user_data) @@ -652,12 +658,15 @@ def self.constantize(class_name) # @private def self.environment_data - { + data = { 'pid' => Process.pid, 'hostname' => Socket.gethostname, - 'env_vars' => ENV.inject({}) { |hsh, (k, v)| hsh[k.to_s] = valueify(v); hsh }, 'arguments' => ARGV.join(' ') } + if configuration(:include_env) + data['env_vars'] = ENV.inject({}) { |hsh, (k, v)| hsh[k.to_s] = valueify(v); hsh } + end + data end # @private diff --git a/spec/squash_ruby_spec.rb b/spec/squash_ruby_spec.rb index 3fad95f..c560840 100644 --- a/spec/squash_ruby_spec.rb +++ b/spec/squash_ruby_spec.rb @@ -425,7 +425,7 @@ def to_s() raise ArgumentError, "oops!"; end end context "[request body]" do - before :each do + def send_exception @exception.send :instance_variable_set, :@custom_ivar, 'foobar' http = double('Net:HTTP') @@ -446,6 +446,7 @@ def to_s() raise ArgumentError, "oops!"; end end it "should transmit information about the exception" do + send_exception expect(@json).to include('class_name') expect(@json).to include('message') expect(@json).to include('backtraces') @@ -457,6 +458,7 @@ def to_s() raise ArgumentError, "oops!"; end end it "should properly tokenize and normalize backtraces" do + send_exception bt = @exception.backtrace.reject { |line| line.include?('.java') } serialized = @json['backtraces'].first['backtrace'].reject { |elem| elem['type'] } expect(serialized).to eql(bt.map do |element| @@ -471,17 +473,29 @@ def to_s() raise ArgumentError, "oops!"; end end it "should transmit information about the environment" do + send_exception expect(@json).to include('pid') expect(@json).to include('hostname') expect(@json['env_vars']).to eql(ENV.to_hash) expect(@json).to include('arguments') end + it "should not transmit env_vars if configured to exclude them" do + Squash::Ruby.configure include_env: false + send_exception + expect(@json).to include('pid') + expect(@json).to include('hostname') + expect(@json['env_vars']).to eql(nil) + expect(@json).to include('arguments') + end + it "should transmit the user data" do + send_exception expect(@json['user_data']).to include('custom_data') end it "should transmit the exception instance variables" do + send_exception expect(@json['ivars']).to include('custom_ivar') end end