Skip to content

Commit

Permalink
Merge branch 'christian/railsdefaultenv'
Browse files Browse the repository at this point in the history
  • Loading branch information
ufoot committed Apr 7, 2017
2 parents b37648a + cc08a18 commit 0b5b9b3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ of the Datadog tracer, you can override the following defaults:
debug: false,
trace_agent_hostname: 'localhost',
trace_agent_port: 8126,
env: Rails.env,
env: nil,
tags: {}
}

Expand All @@ -88,7 +88,7 @@ Available settings are:
* ``debug``: set to true to enable debug logging.
* ``trace_agent_hostname``: set the hostname of the trace agent.
* ``trace_agent_port``: set the port the trace agent is listening on.
* ``env``: set the environment. Defaults to the Rails environment
* ``env``: set the environment. Rails users may set it to ``Rails.env`` to use their application settings.
* ``tags``: set global tags that should be applied to all spans. Defaults to an empty hash

### Sinatra
Expand Down
3 changes: 2 additions & 1 deletion lib/ddtrace/contrib/rails/framework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module Framework
debug: false,
trace_agent_hostname: Datadog::Writer::HOSTNAME,
trace_agent_port: Datadog::Writer::PORT,
env: ::Rails.env,
env: nil,
tags: {}
}.freeze

Expand All @@ -51,6 +51,7 @@ def self.configure(config)

# set default tracer tags
datadog_config[:tracer].set_tags(datadog_config[:tags])

datadog_config[:tracer].set_tags('env' => datadog_config[:env]) if datadog_config[:env]

# set default service details
Expand Down
13 changes: 10 additions & 3 deletions test/contrib/rails/tracer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class TracerTest < ActionController::TestCase
assert !Rails.configuration.datadog_trace[:debug]
assert_equal(Rails.configuration.datadog_trace[:trace_agent_hostname], Datadog::Writer::HOSTNAME)
assert_equal(Rails.configuration.datadog_trace[:trace_agent_port], Datadog::Writer::PORT)
assert_equal(Rails.configuration.datadog_trace[:env], 'test')
assert_equal(Rails.configuration.datadog_trace[:tags], {})
assert_nil(Rails.configuration.datadog_trace[:env], 'no env should be set by default')
assert_equal(Rails.configuration.datadog_trace[:tags], {}, 'no tags should be set by default')
end

test 'a default service and database should be properly set' do
Expand Down Expand Up @@ -133,19 +133,26 @@ class TracerTest < ActionController::TestCase
assert_equal(tracer.tags['section'], 'users')
end

test 'tracer env setting has precedence over tags setting' do
test 'tracer env and env tag setting precedence' do
# default case
tracer = Rails.configuration.datadog_trace[:tracer]
assert_nil(tracer.tags['env'])

# use the Rails value
update_config(:env, ::Rails.env)
update_config(:tags, 'env' => 'foo')
tracer = Rails.configuration.datadog_trace[:tracer]
assert_equal(tracer.tags['env'], 'test')

# explicit set
update_config(:use_rails_env, false)
update_config(:env, 'dev')
update_config(:tags, 'env' => 'bar')
tracer = Rails.configuration.datadog_trace[:tracer]
assert_equal(tracer.tags['env'], 'dev')

# env is not valid but tags is set
update_config(:use_rails_env, false)
update_config(:env, nil)
update_config(:tags, 'env' => 'bar')
tracer = Rails.configuration.datadog_trace[:tracer]
Expand Down

0 comments on commit 0b5b9b3

Please sign in to comment.