-
Notifications
You must be signed in to change notification settings - Fork 375
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
Update env var conventions and make consistent across language clients #1115
Conversation
…racer, trace agent url
…spec and formattinng
@@ -5,6 +5,7 @@ module ActionPack | |||
module Ext | |||
APP = 'action_pack'.freeze | |||
ENV_ANALYTICS_ENABLED = 'DD_ACTION_PACK_ANALYTICS_ENABLED'.freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ENV_ANALYTICS_ENABLED = 'DD_ACTION_PACK_ANALYTICS_ENABLED'.freeze | |
ENV_ANALYTICS_ENABLED = 'DD_TRACE_ACTION_PACK_ANALYTICS_ENABLED'.freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 updated
@@ -4,7 +4,8 @@ module ActionCable | |||
# ActionCable integration constants | |||
module Ext | |||
APP = 'action_cable'.freeze | |||
ENV_ANALYTICS_ENABLED = 'DD_ACTION_CABLE_ANALYTICS_ENABLED'.freeze | |||
ENV_ANALYTICS_ENABLED = 'DD_TRACE_ACTION_CABLE_ANALYTICS_ENABLED'.freeze | |||
ENV_ANALYTICS_ENABLED_OLD = 'DD_ACTION_CABLE_ANALYTICS_ENABLED'.freeze | |||
ENV_ANALYTICS_SAMPLE_RATE = 'DD_ACTION_CABLE_ANALYTICS_SAMPLE_RATE'.freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These need to change as well, DD_TRACE_<INTEGRATION>_ANALYTICS_SAMPLE_RATE
, sorry if the spec wasn't clear about that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotcha, updated
lib/ddtrace/contrib/extensions.rb
Outdated
def integration_disabled?(name) | ||
env_to_bool( | ||
"#{ENV_INTEGRATION_DISABLED_PREFIX}_"\ | ||
"#{name.to_s.sub(':', '').upcase}"\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this always match the same name used in DD_TRACE_<NAME>_ANALYTICS_ENABLED
that you set above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, it's the key being passed into c.use
which are all either one word or snake case. I think this is just a convention though and not enforced anywhere afaik, so should probably add a test to prevent a regression at some point.
lib/ddtrace/environment.rb
Outdated
@@ -6,7 +6,12 @@ module Environment | |||
# Defines helper methods for environment | |||
module Helpers | |||
def env_to_bool(var, default = nil) | |||
ENV.key?(var) ? ENV[var].to_s.strip.downcase == 'true' : default | |||
if var.is_a?(Array) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could do:
var = [var] unless var.is_a?(Array)
env_match = var.find { |env_var| ENV.key?(env_var) }
env_match ? ENV[env_match].to_s.strip.downcase == 'true' : default
or:
if var.is_a?(Array)
env_match = var.find { |env_var| ENV.key?(env_var) }
else
env_match = ENV.key?(var)
end
env_match ? ENV[env_match].to_s.strip.downcase == 'true' : default
Either could simplify/DRY this a little bit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(just a suggestion, not a requirement)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to be a bit dry'er
lib/ddtrace/ext/diagnostics.rb
Outdated
@@ -2,7 +2,8 @@ module Datadog | |||
module Ext | |||
module Diagnostics | |||
DD_TRACE_STARTUP_LOGS = 'DD_TRACE_STARTUP_LOGS'.freeze | |||
|
|||
DD_TRACE_DEBUG_LOGS = 'DD_TRACE_DEBUG'.freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/_LOGS//
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, updated
ENV.fetch(Datadog::Ext::Transport::HTTP::ENV_DEFAULT_PORT, Datadog::Ext::Transport::HTTP::DEFAULT_PORT).to_i | ||
end | ||
|
||
def default_url |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what we've done in other languages is use DD_AGENT_HOST
and DD_TRACE_AGENT_PORT
to build the url, that way once the app loads/is configured, then we only have a url we are working with.
Not sure exactly how that translates here, since I am guessing default_hostname
/default_port
are what are used to create the connection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a bit lower down hostname
and port
get coerced into a url, but it's a bit tricky since we're resolving the priority of host / port in code
> url env var
> host/port env vars
here, before the url gets formed. which is why there's this roundabout "extract the hostname/port from the url being set via env var", to avoid having to re-structure the other parts of transport too much. @marcotc may have a cleaner solution/idea here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is ok for now, but I agree that supporting only url
input is a better way forward.
It requires more changes to the transport that it would be comfortable for this PR, though.
if url_env | ||
uri_parsed = URI.parse(url_env) | ||
|
||
uri_parsed if %w[http https].include?(uri_parsed.scheme) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is https
honored anywhere? if I set https://127.0.0.1:8106/
will that actually use TLS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ...don't think so? mainly I just wanted to avoid a malformed url being passed in
…ys in env conversion helpers
…w env vars, use simpler env var names
lib/ddtrace/environment.rb
Outdated
else | ||
ENV.key?(var) ? ENV[var].to_s.strip.downcase == 'true' : default | ||
end | ||
var = var.find { |env_var| ENV.key?(env_var) } if var.is_a?(Array) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good overall, great stuff!
I left a few suggestions in the review.
lib/ddtrace/contrib/extensions.rb
Outdated
@@ -56,7 +58,7 @@ def [](integration_name, configuration_name = :default) | |||
def instrument(integration_name, options = {}, &block) | |||
integration = fetch_integration(integration_name) | |||
|
|||
unless integration.nil? | |||
unless integration.nil? || !integration_enabled?(integration_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be more cleanly implemented by checking !integration.default_configuration.enabled
.
All integrations already have a default_configuration
method, but they don't all have enabled
defined.
You would define enabled
in this shared class: https://github.com/DataDog/dd-trace-rb/blob/master/lib/ddtrace/contrib/configuration/settings.rb
An integration-specific overwrite would still need to be created to support environment variable configuration, like we do for analytics_enabled
today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, i went ahead and took this approach and defined enabled
in the shared class as well as each Contrib's setting's, and added the relevant Env var constants the respective ext
files.
- One thing is that it required me to modify some of the fixtures in the
extensions_spec
, and that i added a very small test in theconfigurable_spec
to test the shared class. I found this pretty difficult to easily test at the individual contrib level, and i've punted on it in this PR for now. I think it will take some work done ala theanalytics_examples
/analytics_spec
that abstracts everything out into shared helpers but the scope of that work could take a bit and didn't want it to be a blocker for this PR.
ENV.fetch(Datadog::Ext::Transport::HTTP::ENV_DEFAULT_PORT, Datadog::Ext::Transport::HTTP::DEFAULT_PORT).to_i | ||
end | ||
|
||
def default_url |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is ok for now, but I agree that supporting only url
input is a better way forward.
It requires more changes to the transport that it would be comfortable for this PR, though.
…rray support to all env_to_x helpers
@marcotc tried to address all the feedback here, i've re-requested a review when you have time. had one note on testing the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
This PR updates the conventions of currently existing key environment variables used for configuration the tracer and it's integrations, as well as adds a few new environment variables for key configurability that are supported in some other language clients. The goal of this PR is to standardise the env var's available for configuring the tracer while still supporting older environment variables
New Env Vars
DD_TRACE_AGENT_URL
: The URL of the Trace Agent that the tracer submits to. Takes priority over hostname (DD_AGENT_HOST
) and port (DD_TRACE_AGENT_PORT
), if set. currently only supports http/https.DD_TRACE_DEBUG
: Enables or disables debug logging.DD_TRACE_<INTEGRATION>_ENABLED
: Allows user to ensure instrumentation for a specific integration (eg:DD_TRACE_RAILS_ENABLED
) is disabled. the standard across languages is_ENABLED
but since it isn't possible to enable solely via env var at the moment, and must be done in code, this could be confusing to users.So addingAdding documentation on this restriction._DISABLED
so users still have the functionality to disable instrumentation for testing or performance purposes.DD_TRACE_ENABLED
: Allows user to disable the tracer. The spans are still created but will not be flushed to the agentUpdated Env Vars
Migration
DD_<INTEGRATION>_ANALYTICS_ENABLED
toDD_TRACE_<INTEGRATION>_ANALYTICS_ENABLED
: Updates naming convention for enabling/disabled analyzed spans for a specific integration, such asDD_TRACE_RAILS_ANALYTICS_ENABLED
. DeprecatedDD_<INTEGRATION>_ANALYTICS_ENABLED
is still supported.Migration
DD_<INTEGRATION>_ANALYTICS_SAMPLE_RATE
toDD_TRACE_<INTEGRATION>_ANALYTICS_SAMPLE_RATE
: Updates naming convention for enabling/disabled analyzed spans for a specific integration, such asDD_TRACE_RAILS_ANALYTICS_SAMPLE_RATE
. DeprecatedDD_<INTEGRATION>_ANALYTICS_SAMPLE_RATE
is still supported.Notes
should we scrap theupdated toDD_TRACE_INTEGRATION_DISABLED
since it's off spec or move toDD_TRACE_INTEGRATION_ENABLED
to stay on spec(but document that it only can be used to disable instrumentation)? i think it could provide value for users either way.DD_TRACE_INTEGRATION_ENABLED
with a note that onlyfalse
is a valid option.Not all of these env vars are clearly documented in docs, or don't have a clear place to add documentation., such asAdded to docsDD_TRACE_<INTEGRATION>_ANALYTICS_ENABLED
,DD_TRACE_AGENT_URL
,DD_TRACE_<INTEGRATION>_DISABLED
. Not sure why a lot of these existing env vars haven't been documented but if we need to document them now we could add a seperate 'misc env vars` section to the docs maybe?In general, would be good to have feedback on the way the new env vars have been implemented. I tried to fit them into the existing conventions we have.