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

Add DD_ENV environment variable #977

Merged
merged 4 commits into from
Mar 19, 2020
Merged

Conversation

delner
Copy link
Contributor

@delner delner commented Mar 17, 2020

To make it easier to tag traces with the application environment, this pull request defines DD_ENV which users can set, which will automatically:

  • Be set as a tag on all traces
  • Be set as a tag on all metrics
  • Be added as an attribute to Datadog::Correlation for logs correlation

@delner delner added core Involves Datadog core libraries feature Involves a product feature labels Mar 17, 2020
@delner delner requested review from marcotc, brettlangdon and a team March 17, 2020 20:19
@delner delner self-assigned this Mar 17, 2020
@delner
Copy link
Contributor Author

delner commented Mar 17, 2020

NOTE: Right now, this does not reconcile any conflicts between DD_ENV, Tracer#set_tags or c.tracer tags: { ... } when each define an env tag, as this reconciliation behavior still needs to be defined.

@marcotc
Copy link
Member

marcotc commented Mar 17, 2020

How does this PR relate to this one? #878

@delner
Copy link
Contributor Author

delner commented Mar 17, 2020

Hmmmmm looks duplicative in many respects; didn't realize this existed. We probably want to reconcile these differences, take the best parts of each, and close one of these.

Copy link
Member

@brettlangdon brettlangdon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need a test case that a span started when DD_ENV is set gets an env tag?

I assume not, since we assert that DD_ENV=test => tracer.tags = {env: 'test'}, and we know that tracer.tags = {anything} => span.meta = {anything}

@@ -83,7 +85,9 @@ def initialize(options = {})
end

@mutex = Mutex.new
@tags = {}
@tags = {}.tap do |tags|
tags[:env] = ENV[Ext::Environment::ENV_ENVIRONMENT] if ENV.key?(Ext::Environment::ENV_ENVIRONMENT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, I saw this as more of a:

@env = ENV[Ext::Environment::ENV_ENVIRONMENT] if ENV.key?(Ext::Environment::ENV_ENVIRONMENT)
@tags = {}

but this could work to... I'd like to have DD_ENV take precedence over other things, but I guess in this case it doesn't matter much whether you want to manage the state as a tag or a property.

e.g.

# DD_ENV='test'
tracer.set_tags(env: 'override')

# vs

# DD_ENV=test
tracer.env = 'override'

/shrug

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, per our discussion I think we will want to move this to state as you suggest above, but we will need to refactor configuration a little bit first. We're agreed that we'd like to drive towards this though.

@delner
Copy link
Contributor Author

delner commented Mar 18, 2020

So after thinking/discussing, I think the plan is:

  • We will move env to configuration as suggested by @brettlangdon and @marcotc via Add configuration for application environment #878 , however for the purposes of this PR, we won't implement that here and keep the current implementation as an intermediate step. After we clean up some tech debt within configuration (that's a hurdle for our intended implementation) we will revisit and make this change.
  • Thus keep this PR as is, unless there are other changes we might need to make that we haven't discussed (will wait for reviews for that.)
  • Keep Add configuration for application environment #878 open in the interim, as a reminder for what we'd like to do with the change outlined in bullet point number 1.

@marcotc @brettlangdon does that sound good? Please feel free to leave your reviews for the rest of the code as well. Thanks!

module Datadog
module Ext
module Environment
ENV_ENVIRONMENT = 'DD_ENV'.freeze
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like these short names :)

@delner delner merged commit e13f861 into master Mar 19, 2020
@delner delner deleted the feature/add_environment_env_var branch March 19, 2020 14:57
@delner delner added this to the 0.34.0 milestone Mar 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Involves Datadog core libraries feature Involves a product feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants