Skip to content

option to exclude env_vars #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/squash/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion spec/squash_ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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|
Expand All @@ -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
Expand Down