Skip to content

Commit 8a47c5a

Browse files
fix(runtime metrics): ensure DD_TAGS are added to runtime metrics [backport 1.16] (#6274)
Backport 09956e4 from #6271 to 1.16. This is a fix for a bug found in testing #6121. The tests in #6121 were testing the individual tag collectors, but not the `RuntimeCollectorsIterator` which will filter out any undefined tags. The fix needed was to remove the tag filter from the `RuntimeTags` iterator. This means any tags emitted by `TracerTagCollector` or `PlatformTagCollector` will be included, instead of specifying an explicit allow list. Tests were added for the `RuntimeTags` iterator to ensure the expected behavior is followed for the new behavior. No changelog entry is needed since this fix is being added to 1.16.0rc1 before the release. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) Co-authored-by: Brett Langdon <[email protected]>
1 parent d5d4766 commit 8a47c5a

File tree

4 files changed

+62
-10
lines changed

4 files changed

+62
-10
lines changed

ddtrace/internal/runtime/constants.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,3 @@
2525
LANG_VERSION = "lang_version"
2626
LANG = "lang"
2727
TRACER_VERSION = "tracer_version"
28-
29-
TRACER_TAGS = set([SERVICE, ENV])
30-
31-
PLATFORM_TAGS = set([LANG_INTERPRETER, LANG_VERSION, LANG, TRACER_VERSION])
32-
33-
DEFAULT_RUNTIME_TAGS = TRACER_TAGS | PLATFORM_TAGS

ddtrace/internal/runtime/runtime_metrics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from ..dogstatsd import get_dogstatsd_client
1515
from ..logger import get_logger
1616
from .constants import DEFAULT_RUNTIME_METRICS
17-
from .constants import DEFAULT_RUNTIME_TAGS
1817
from .metric_collectors import GCRuntimeMetricCollector
1918
from .metric_collectors import PSUtilRuntimeMetricCollector
2019
from .tag_collectors import PlatformTagCollector
@@ -42,7 +41,8 @@ def __repr__(self):
4241

4342

4443
class RuntimeTags(RuntimeCollectorsIterable):
45-
ENABLED = DEFAULT_RUNTIME_TAGS
44+
# DEV: `None` means to allow all tags generated by PlatformTagCollector and TracerTagCollector
45+
ENABLED = None
4646
COLLECTORS = [
4747
PlatformTagCollector,
4848
TracerTagCollector,

tests/tracer/runtime/test_runtime_metrics.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import time
44

55
import mock
6+
import pytest
67

78
from ddtrace.ext import SpanTypes
89
from ddtrace.internal.runtime.constants import DEFAULT_RUNTIME_METRICS
@@ -69,6 +70,64 @@ def filter_only_env_tags(tags):
6970
assert tags == [("env", "staging.dog")]
7071

7172

73+
@pytest.mark.subprocess(env={})
74+
def test_runtime_tags_empty():
75+
from ddtrace.internal.runtime.runtime_metrics import RuntimeTags
76+
77+
tags = list(RuntimeTags())
78+
assert len(tags) == 4
79+
80+
tags = dict(tags)
81+
assert set(tags.keys()) == set(["lang", "lang_interpreter", "lang_version", "tracer_version"])
82+
83+
84+
@pytest.mark.subprocess(env={"DD_SERVICE": "my-service", "DD_ENV": "test-env", "DD_VERSION": "1.2.3"})
85+
def test_runtime_tags_usm():
86+
from ddtrace.internal.runtime.runtime_metrics import RuntimeTags
87+
88+
tags = list(RuntimeTags())
89+
assert len(tags) == 7, tags
90+
91+
tags = dict(tags)
92+
assert set(tags.keys()) == set(
93+
["lang", "lang_interpreter", "lang_version", "tracer_version", "service", "version", "env"]
94+
)
95+
assert tags["service"] == "my-service"
96+
assert tags["env"] == "test-env"
97+
assert tags["version"] == "1.2.3"
98+
99+
100+
@pytest.mark.subprocess(env={"DD_TAGS": "version:1.2.3,custom:tag,test:key", "DD_VERSION": "4.5.6"})
101+
def test_runtime_tags_dd_tags():
102+
from ddtrace.internal.runtime.runtime_metrics import RuntimeTags
103+
104+
tags = list(RuntimeTags())
105+
assert len(tags) == 7, tags
106+
107+
tags = dict(tags)
108+
assert set(tags.keys()) == set(
109+
["lang", "lang_interpreter", "lang_version", "tracer_version", "version", "custom", "test"]
110+
)
111+
assert tags["custom"] == "tag"
112+
assert tags["test"] == "key"
113+
assert tags["version"] == "4.5.6"
114+
115+
116+
@pytest.mark.subprocess()
117+
def test_runtime_tags_manual_tracer_tags():
118+
from ddtrace import tracer
119+
from ddtrace.internal.runtime.runtime_metrics import RuntimeTags
120+
121+
tracer.set_tags({"manual": "tag"})
122+
123+
tags = list(RuntimeTags())
124+
assert len(tags) == 5, tags
125+
126+
tags = dict(tags)
127+
assert set(tags.keys()) == set(["lang", "lang_interpreter", "lang_version", "tracer_version", "manual"])
128+
assert tags["manual"] == "tag"
129+
130+
72131
class TestRuntimeMetrics(BaseTestCase):
73132
def test_all_metrics(self):
74133
metrics = set([k for (k, v) in RuntimeMetrics()])

tests/tracer/runtime/test_tag_collectors.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import pytest
22

3-
from ddtrace.internal.runtime import constants
43
from ddtrace.internal.runtime import tag_collectors
54

65

76
def test_values():
87
ptc = tag_collectors.PlatformTagCollector()
98
values = dict(ptc.collect())
10-
assert constants.PLATFORM_TAGS == set(values.keys())
9+
assert set(["lang", "lang_interpreter", "lang_version", "tracer_version"]) == set(values.keys())
1110

1211

1312
@pytest.mark.subprocess(

0 commit comments

Comments
 (0)