Skip to content

attach additional tags as defined in DATADOG_TAGS environment variable#114

Merged
yannmh merged 4 commits intoDataDog:masterfrom
ewdurbin:dogstatsd_env_tags
Mar 3, 2016
Merged

attach additional tags as defined in DATADOG_TAGS environment variable#114
yannmh merged 4 commits intoDataDog:masterfrom
ewdurbin:dogstatsd_env_tags

Conversation

@ewdurbin
Copy link
Copy Markdown
Contributor

creates an additional technique for adding tags to all metrics by defining a comma separated list of tags in the DOGSTATSD_TAGS environment variable.

use case:

currently we add a plethora of global tags by adding them to our dd-agent configuration on each node. as we progress towards using container technologies, it would be swell if we could seamlessly inject some of these tags on a container by container basis (app name, version, build) rather than adding them to the dd-agent which will be configured with tags for instance id, region, availability-zone etc.

@yannmh yannmh added this to the Triage milestone Jan 26, 2016
@yannmh
Copy link
Copy Markdown

yannmh commented Jan 26, 2016

Nice feature, thanks a lot @ewdurbin. We'll review and consider your changes for an upcoming release.

On a side note, I am quite confused by the use case you are describing. It sounds like you are looking for a convenient way to set constant tagging on Datadog Agent metrics (including metrics received from statsd protocol). If so, I think the following changes on dd-agent repository would be a better fit DataDog/dd-agent#2095.
Your changes would only add constant tagging to metrics sent using datadogpy library, i.e. a subset of custom metrics.
What do you think ?

@yannmh yannmh self-assigned this Jan 26, 2016
@ewdurbin
Copy link
Copy Markdown
Contributor Author

@yannmh there's a bit of finesse.

Example:

Assume we have two docker hosts hostA and hostB running in separate availability zones, and a few applications with information like name, version, build.

Currently, running dd-agent as a docker container on each docker host, we may configure it to have the following tags:

  • instance-id
  • region
  • availability-zone

Unfortunately this leaves the owners of the application to manually add the application_name, application_version and application_build_number to their code before instantiating their statsd client.

This feature allows us to inject DOGSTATSD_TAGS into the docker container with the application specific tags at launch and have it point blindly at the shared dd-agent, but still end up with the following tags:

  • instance-id
  • region
  • availability-zone
  • application_name
  • application_version
  • application_build

without needing to either manually add them in code (passing constant_tags to the client) or running a separate dd-agent for each application on the docker host.

@yannmh
Copy link
Copy Markdown

yannmh commented Jan 26, 2016

It completely makes sense. Thanks for the further explanations @ewdurbin !

@yannmh yannmh modified the milestones: 0.11.0, Triage Feb 24, 2016
self._send = self._send_to_server
self.encoding = 'utf-8'
self.constant_tags = constant_tags
self.env_tags = [tag for tag in os.environ.get('DOGSTATSD_TAGS', '').split(',') if tag]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we limit env_tags scope to the function only ? i.e.

env_tags = ...

# Instead of
self.env_tags = ...

@yannmh
Copy link
Copy Markdown

yannmh commented Feb 29, 2016

It looks great, thanks again @ewdurbin.

I simply added a few nitpicks. Please let me know your thoughts about it, so we can merge your contribution.

@yannmh
Copy link
Copy Markdown

yannmh commented Feb 29, 2016

Thanks for the quick update @ewdurbin ! Let's merge it

@yannmh
Copy link
Copy Markdown

yannmh commented Mar 1, 2016

I am thinking about adding the same feature to dogstatsd's HTTP cousin ThreadStats.
Thus, I am wondering if it wouldn't be better to rename DOGSTATSD_TAGS to DATADOG_TAGS instead. What do you think @ewdurbin ?

@ewdurbin
Copy link
Copy Markdown
Contributor Author

ewdurbin commented Mar 2, 2016

This PR already includes the addition to ThreadStats. I'm fine with renaming it to a more general DATADOG_TAGS.

@yannmh
Copy link
Copy Markdown

yannmh commented Mar 3, 2016

Thanks @ewdurbin. Let's merge it 🚢

yannmh pushed a commit that referenced this pull request Mar 3, 2016
[dogstatsd][threadstats] constant tags from `DATADOG_TAGS` environment variable
@yannmh yannmh merged commit 166051f into DataDog:master Mar 3, 2016
@ewdurbin ewdurbin deleted the dogstatsd_env_tags branch March 3, 2016 16:52
@ewdurbin ewdurbin changed the title attach additional tags as defined in DOGSTATSD_TAGS environment variable attach additional tags as defined in DATADOG_TAGS environment variable Mar 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants