Skip to content

Commit

Permalink
make obfuscation respect default transaction tracer configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarg committed Nov 28, 2011
1 parent b2921e2 commit d962768
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/new_relic/agent/sql_sampler.rb
Expand Up @@ -48,7 +48,7 @@ def config
control = NewRelic::Control.instance
# Default slow_sql config values to transaction tracer config
control.fetch('transaction_tracer', {}).
merge( control.fetch('slow_sql', {}) )
merge(control.fetch('slow_sql', {}))
end

# Enable the sql sampler - this also registers it with
Expand Down Expand Up @@ -247,8 +247,8 @@ def prepare_to_send

def agent_config
control = NewRelic::Control.instance
control.fetch('slow_sql',
control.fetch('transaction_tracer', {}))
control.fetch('transaction_tracer', {}).
merge(control.fetch('slow_sql', {}))
end

def need_to_obfuscate?
Expand Down
17 changes: 16 additions & 1 deletion test/new_relic/agent/sql_sampler_test.rb
Expand Up @@ -174,14 +174,29 @@ def test_sql_id_fits_in_a_mysql_int_11
end

def test_config_values_default_to_transaction_tracer_config

NewRelic::Control.instance['slow_sql'] = { "explain_enabled"=> false }

assert_equal NewRelic::Agent.instance.sql_sampler.config['stack_trace_threshold'], 0.1 # transaction_tracer default
assert_equal NewRelic::Agent.instance.sql_sampler.config['explain_enabled'], false

# put things back how we found them
NewRelic::Control.instance['slow_sql'] = { "explain_enabled"=> true }
end

def test_sends_obfuscated_queries_when_configured
NewRelic::Control.instance['transaction_tracer'] = { 'record_sql' => 'obfuscated' }

data = NewRelic::Agent::TransactionSqlData.new
data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
'guid')
data.sql_data.concat([NewRelic::Agent::SlowSql.new("select * from test where foo = 'bar'",
"Database/test/select", {}, 1.5),
NewRelic::Agent::SlowSql.new("select * from test where foo in (1,2,3,4,5)",
"Database/test/select", {}, 1.2)])
@sampler.harvest_slow_sql(data)
sql_traces = @sampler.harvest

assert_equal('select * from test where foo = ?', sql_traces[0].sql)
assert_equal('select * from test where foo in (?,?,?,?,?)', sql_traces[1].sql)
end
end

0 comments on commit d962768

Please sign in to comment.