Skip to content

Commit c9b3088

Browse files
authored
chore(telemetry): add process tags (#15227)
This PR implements this [RFC](https://docs.google.com/document/d/1AFdLUuVk70i0bJd5335-RxqsvwAV9ovAqcO2z5mEMbA/edit?pli=1&tab=t.0#heading=h.s9l1lctqlg11) for telemetry. Add process_tags to telemetry configuration ## Testing - There is already a test testing the exact config so we know that if we are not enabling the process tags, it is not in the config - Check process tags are in the telemetry configuration when enabled.
1 parent 5bcd099 commit c9b3088

File tree

5 files changed

+40
-11
lines changed

5 files changed

+40
-11
lines changed

ddtrace/internal/process_tags/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Optional
66

77
from ddtrace.internal.logger import get_logger
8-
from ddtrace.internal.settings._config import config
8+
from ddtrace.internal.settings.process_tags import process_tags_config as config
99

1010

1111
log = get_logger(__name__)
@@ -45,7 +45,7 @@ def is_allowed_char(char: str) -> str:
4545

4646

4747
def generate_process_tags() -> Optional[str]:
48-
if not config._process_tags_enabled:
48+
if not config.enabled:
4949
return None
5050

5151
try:
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from ddtrace.internal.settings._core import DDConfig
2+
3+
4+
class ProcessTagsConfig(DDConfig):
5+
__prefix__ = "dd"
6+
7+
enabled = DDConfig.v(
8+
bool,
9+
"experimental.propagate.process.tags.enabled",
10+
default=False,
11+
help="Enables process tags in products payload",
12+
)
13+
14+
15+
process_tags_config = ProcessTagsConfig()

ddtrace/internal/telemetry/data.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import List # noqa:F401
88
from typing import Tuple # noqa:F401
99

10+
from ddtrace.internal import process_tags
1011
from ddtrace.internal.constants import DEFAULT_SERVICE_NAME
1112
from ddtrace.internal.packages import get_module_distribution_versions
1213
from ddtrace.internal.runtime.container import get_container_info
@@ -58,7 +59,7 @@ def _get_application(key):
5859
"""
5960
service, version, env = key
6061

61-
return {
62+
application = {
6263
"service_name": service or DEFAULT_SERVICE_NAME, # mandatory field, can not be empty
6364
"service_version": version or "",
6465
"env": env or "",
@@ -69,6 +70,11 @@ def _get_application(key):
6970
"runtime_version": _format_version_info(sys.implementation.version),
7071
}
7172

73+
if p_tags := process_tags.process_tags:
74+
application["process_tags"] = p_tags
75+
76+
return application
77+
7278

7379
def update_imported_dependencies(already_imported: Dict[str, str], new_modules: Iterable[str]) -> List[Dict[str, str]]:
7480
deps = []

tests/internal/test_process_tags.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from ddtrace.internal.process_tags import ENTRYPOINT_TYPE_TAG
1010
from ddtrace.internal.process_tags import ENTRYPOINT_WORKDIR_TAG
1111
from ddtrace.internal.process_tags import normalize_tag_value
12-
from ddtrace.internal.settings._config import config
12+
from ddtrace.internal.settings.process_tags import process_tags_config as config
1313
from tests.subprocesstest import run_in_subprocess
1414
from tests.utils import TracerTestCase
1515
from tests.utils import process_tag_reload
@@ -79,17 +79,17 @@ def test_normalize_tag(input_tag, expected):
7979
class TestProcessTags(TracerTestCase):
8080
def setUp(self):
8181
super(TestProcessTags, self).setUp()
82-
self._original_process_tags_enabled = config._process_tags_enabled
82+
self._original_process_tags_enabled = config.enabled
8383
self._original_process_tags = process_tags.process_tags
8484

8585
def tearDown(self):
86-
config._process_tags_enabled = self._original_process_tags_enabled
86+
config.enabled = self._original_process_tags_enabled
8787
process_tags.process_tags = self._original_process_tags
8888
super().tearDown()
8989

9090
@pytest.mark.snapshot
9191
def test_process_tags_deactivated(self):
92-
config._process_tags_enabled = False
92+
config.enabled = False # type: ignore[assignment]
9393
process_tag_reload()
9494

9595
with self.tracer.trace("test"):
@@ -98,7 +98,7 @@ def test_process_tags_deactivated(self):
9898
@pytest.mark.snapshot
9999
def test_process_tags_activated(self):
100100
with patch("sys.argv", [TEST_SCRIPT_PATH]), patch("os.getcwd", return_value=TEST_WORKDIR_PATH):
101-
config._process_tags_enabled = True
101+
config.enabled = True # type: ignore[assignment]
102102
process_tag_reload()
103103

104104
with self.tracer.trace("parent"):
@@ -108,7 +108,7 @@ def test_process_tags_activated(self):
108108
@pytest.mark.snapshot
109109
def test_process_tags_edge_case(self):
110110
with patch("sys.argv", ["/test_script"]), patch("os.getcwd", return_value=TEST_WORKDIR_PATH):
111-
config._process_tags_enabled = True
111+
config.enabled = True # type: ignore[assignment]
112112
process_tag_reload()
113113

114114
with self.tracer.trace("span"):
@@ -117,7 +117,7 @@ def test_process_tags_edge_case(self):
117117
@pytest.mark.snapshot
118118
def test_process_tags_error(self):
119119
with patch("sys.argv", []), patch("os.getcwd", return_value=TEST_WORKDIR_PATH):
120-
config._process_tags_enabled = True
120+
config.enabled = True # type: ignore[assignment]
121121

122122
with self.override_global_config(dict(_telemetry_enabled=False)):
123123
with patch("ddtrace.internal.process_tags.log") as mock_log:
@@ -137,7 +137,7 @@ def test_process_tags_error(self):
137137
@run_in_subprocess(env_overrides=dict(DD_TRACE_PARTIAL_FLUSH_ENABLED="true", DD_TRACE_PARTIAL_FLUSH_MIN_SPANS="2"))
138138
def test_process_tags_partial_flush(self):
139139
with patch("sys.argv", [TEST_SCRIPT_PATH]), patch("os.getcwd", return_value=TEST_WORKDIR_PATH):
140-
config._process_tags_enabled = True
140+
config.enabled = True # type: ignore[assignment]
141141
process_tag_reload()
142142

143143
with self.override_global_config(dict(_partial_flush_enabled=True, _partial_flush_min_spans=2)):

tests/telemetry/test_data.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ def test_get_application_with_values():
4343
assert application["env"] == "staging"
4444

4545

46+
@pytest.mark.subprocess(env={"DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED": "True"})
47+
def test_get_application_with_process_tags():
48+
from ddtrace.internal.telemetry.data import get_application
49+
50+
application = get_application("", "", "")
51+
assert "process_tags" in application
52+
53+
4654
def test_application_with_setenv(run_python_code_in_subprocess, monkeypatch):
4755
"""
4856
validates the return value of get_application when DD_SERVICE, DD_VERSION, and DD_ENV environment variables are set

0 commit comments

Comments
 (0)