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

Fix tracer ignoring value for service tag (service name) in DD_TAGS #1543

Merged
merged 2 commits into from
Jun 7, 2021

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Jun 4, 2021

As documented in https://docs.datadoghq.com/tracing/setup_overview/setup/ruby/#environment-and-tags:

If DD_ENV, DD_SERVICE or DD_VERSION are NOT set, tags defined in DD_TAGS will be used to populate env/service/version respectively.

Unfortunately, the previous implementation was missing a weird corner case: the service/env/version in the settings object were only set as a side-effect of trying to access or write to the tags option.

This meant that in a situation where service/env/version were defined in DD_TAGS only AND those values were accessed BEFORE calling tags, the accessing code would not see the correct values (it would still see them as nil).

In particular, this happened during tracer initialization inside Components#build_tracer, and meant that rather than using the service name defined in DD_TAGS, the fallback default from Tracer#default_service would be used instead.

I'm not very happy with the fix (hence it's more of a workaround), see the huge comment I left on the code for more details on why I'm not happy and why it works.

As documented in
<https://docs.datadoghq.com/tracing/setup_overview/setup/ruby/#environment-and-tags>:

> If `DD_ENV`, `DD_SERVICE` or `DD_VERSION` are NOT set, tags defined in
> `DD_TAGS` will be used to populate `env`/`service`/`version` respectively.

Unfortunately, the previous implementation was missing a weird corner
case: the `service`/`env`/`version` in the settings object were only
set as a side-effect of trying to access or write to the tags option.

This meant that in a situation where `service`/`env`/`version` were
defined in `DD_TAGS` only AND those values were accessed BEFORE `tags`,
the accessing code would not see the correct values (it would still
see them as nil).

In particular, this happened during tracer initialization inside
`Components#build_tracer`, and meant that rather than using the service
name defined in `DD_TAGS`, the fallback default from
`Tracer#default_service` would be used instead.

I'm not very happy with the fix (hence it's more of a workaround),
see the huge comment I left on the code for more details on why
I'm not happy and why it works.
@ivoanjo ivoanjo requested a review from a team June 4, 2021 14:59
@ericmustin
Copy link
Contributor

Does this impact any resolution priority that should be given to DD_ENV,DD_SERVICE,DD_VERSION like we mention here? https://github.com/DataDog/dd-trace-rb/blob/b05fddf41ac844152b00cf834ea0e76e3fb86e9a/docs/GettingStarted.md#environment-and-tags

Copy link
Member

@marcotc marcotc left a comment

Choose a reason for hiding this comment

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

My feeling is that DD_TAGS unlikely to be the best source for env, service, and version in the future.

@marcotc
Copy link
Member

marcotc commented Jun 4, 2021

@ericmustin it now respects correctly what's documented in the GettingStarted.md.

@ivoanjo
Copy link
Member Author

ivoanjo commented Jun 7, 2021

Does this impact any resolution priority that should be given to DD_ENV,DD_SERVICE,DD_VERSION like we mention here?

Yeap, what Marco said: up until now, the docs weren't actually being respected for setting the service name from DD_TAGS. I actually tested many different configurations for tracing/profiling in this spreadsheet (datadog only), if you're curious about the exact behavior before my fix.

@ivoanjo ivoanjo merged commit b457fa4 into master Jun 7, 2021
@ivoanjo ivoanjo deleted the ivoanjo/fix-service-names branch June 7, 2021 08:28
@github-actions github-actions bot added this to the 0.50.0 milestone Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants