-
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
Add DD_TAGS environment variable #980
Conversation
b396e4e
to
a22c211
Compare
@@ -158,7 +155,8 @@ def default_service | |||
# | |||
# tracer.set_tags('env' => 'prod', 'component' => 'core') | |||
def set_tags(tags) | |||
@tags.update(tags) | |||
string_tags = Hash[tags.collect { |k, v| [k.to_s, v] }] |
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 fixes one of the bugs where Symbols and Strings weren't being quantized to the same key, causing duplicates.
@tags.each { |k, v| span.set_tag(k, v) } unless @tags.empty? | ||
tags.each { |k, v| span.set_tag(k, v) } unless tags.empty? |
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.
👍
@tags.each { |k, v| span.set_tag(k, v) } unless @tags.empty? | ||
tags.each { |k, v| span.set_tag(k, v) } unless tags.empty? |
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 fixes the other bug where default tags were overriding tags manually set upon the span.
@@ -77,8 +77,8 @@ | |||
expect(Datadog::Logger.log).to eq(custom_log) | |||
expect(tracer.writer.transport.current_api.adapter.hostname).to eq('tracer.host.com') | |||
expect(tracer.writer.transport.current_api.adapter.port).to eq(1234) | |||
expect(tracer.tags[:env]).to eq(:config_test) | |||
expect(tracer.tags[:foo]).to eq(:bar) | |||
expect(tracer.tags['env']).to eq(:config_test) |
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 changing this behavior is okay?
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.
hmm... I guess it depends if people are accessing tags directly via symbols?
otherwise, this shouldn't break anything on encoding or sending to the agent
This pull request adds
DD_TAGS
as a environment variable which can be used to set default tags on the tracer.It also does some minor refactoring of
DD_ENV
intoDatadog::Environment
to make things a little cleaner/more consistent, and fixes two bugs::tags
option toTracer#start_span
.Tracer#set_tags
e.g.tracer.set_tags(foo: :bar, 'foo' => :baz)
would keep duplicates for each type which would lead to an arbitrary one being used. (Problematic if you aren't consistent when using strings vs symbols.)