Skip to content
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

[env] using Rails environment only when asked to do so #106

Merged
merged 3 commits into from
Apr 7, 2017
Merged
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
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 @@ -50,6 +50,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