Skip to content

Commit 8ed2269

Browse files
committed
add excluded values test
1 parent 4f8e5a4 commit 8ed2269

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

ddtrace/internal/process_tags/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ def is_allowed_char(char: str) -> str:
5050
def _compute_process_tag(key: str, compute_value: Callable):
5151
try:
5252
value = compute_value()
53-
return normalize_tag_value(value) if value else None
53+
if value and value not in ("/", "\\", "bin"):
54+
return normalize_tag_value(value)
55+
return None
5456
except Exception as e:
5557
log.debug("failed to get process tag %s : %s", key, e)
5658
return None
@@ -67,11 +69,13 @@ def generate_process_tags() -> Tuple[Optional[str], Optional[List[str]]]:
6769
(ENTRYPOINT_TYPE_TAG, lambda: ENTRYPOINT_TYPE_SCRIPT),
6870
]
6971

70-
process_tags_list = sorted([
71-
f"{key}:{value}"
72-
for key, compute_value in tag_definitions
73-
if (value := _compute_process_tag(key, compute_value)) is not None
74-
])
72+
process_tags_list = sorted(
73+
[
74+
f"{key}:{value}"
75+
for key, compute_value in tag_definitions
76+
if (value := _compute_process_tag(key, compute_value)) is not None
77+
]
78+
)
7579

7680
# process_tags_list cannot be empty as one of the tag is a constant
7781
process_tags = ",".join(process_tags_list)

tests/internal/test_process_tags.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from ddtrace.internal.process_tags import ENTRYPOINT_NAME_TAG
99
from ddtrace.internal.process_tags import ENTRYPOINT_TYPE_TAG
1010
from ddtrace.internal.process_tags import ENTRYPOINT_WORKDIR_TAG
11+
from ddtrace.internal.process_tags import _compute_process_tag
1112
from ddtrace.internal.process_tags import normalize_tag_value
1213
from ddtrace.internal.settings.process_tags import process_tags_config as config
1314
from tests.subprocesstest import run_in_subprocess
@@ -65,15 +66,23 @@
6566
(
6667
"A0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
6768
" 00000000000",
68-
"a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
69-
"_0",
69+
"a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000_0",
7070
),
7171
],
7272
)
7373
def test_normalize_tag(input_tag, expected):
7474
assert normalize_tag_value(input_tag) == expected
7575

7676

77+
@pytest.mark.parametrize(
78+
"excluded_value",
79+
["/", "\\", "bin", "", None],
80+
)
81+
def test_compute_process_tag_excluded_values(excluded_value):
82+
result = _compute_process_tag("test_key", lambda: excluded_value)
83+
assert result is None
84+
85+
7786
class TestProcessTags(TracerTestCase):
7887
def setUp(self):
7988
super(TestProcessTags, self).setUp()
@@ -134,17 +143,12 @@ def test_process_tags_error(self):
134143
assert "failed to get process tag" in call_args1[0], (
135144
f"Expected error message not found. Got: {call_args1[0]}"
136145
)
137-
assert call_args1[1] == "entrypoint.basedir", (
138-
f"Expected tag key not found. Got: {call_args1[1]}"
139-
)
146+
assert call_args1[1] == "entrypoint.basedir", f"Expected tag key not found. Got: {call_args1[1]}"
140147

141148
assert "failed to get process tag" in call_args2[0], (
142149
f"Expected error message not found. Got: {call_args2[0]}"
143150
)
144-
assert call_args2[1] == "entrypoint.name", (
145-
f"Expected tag key not found. Got: {call_args2[1]}"
146-
)
147-
151+
assert call_args2[1] == "entrypoint.name", f"Expected tag key not found. Got: {call_args2[1]}"
148152

149153
@pytest.mark.snapshot
150154
@run_in_subprocess(env_overrides=dict(DD_TRACE_PARTIAL_FLUSH_ENABLED="true", DD_TRACE_PARTIAL_FLUSH_MIN_SPANS="2"))

0 commit comments

Comments
 (0)