Skip to content

Commit 0428dcd

Browse files
committed
brett review
1 parent 7416466 commit 0428dcd

9 files changed

+232
-74
lines changed

.riot/requirements/1645326.txt

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/internal/test_process_tags.py

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import pytest
44

5-
from ddtrace.internal.constants import PROCESS_TAGS
5+
from ddtrace.internal import process_tags
66
from ddtrace.internal.process_tags import _process_tag_reload
77
from ddtrace.internal.process_tags import normalize_tag
88
from ddtrace.settings._config import config
9+
from tests.subprocesstest import run_in_subprocess
910
from tests.utils import TracerTestCase
1011

1112

@@ -30,31 +31,70 @@ def test_normalize_tag(input_tag, expected):
3031

3132

3233
class TestProcessTags(TracerTestCase):
34+
def setUp(self):
35+
super(TestProcessTags, self).setUp()
36+
self._original_process_tags_enabled = config._process_tags_enabled
37+
self._original_process_tags = process_tags.process_tags
38+
39+
def tearDown(self):
40+
config._process_tags_enabled = self._original_process_tags_enabled
41+
process_tags.process_tags = self._original_process_tags
42+
super().tearDown()
43+
44+
@pytest.mark.snapshot
3345
def test_process_tags_deactivated(self):
3446
config._process_tags_enabled = False
3547
_process_tag_reload()
3648

3749
with self.tracer.trace("test"):
3850
pass
3951

40-
span = self.get_spans()[0]
41-
assert span is not None
42-
assert PROCESS_TAGS not in span._meta
43-
4452
@pytest.mark.snapshot
4553
def test_process_tags_activated(self):
4654
with patch("sys.argv", ["/path/to/test_script.py"]), patch("os.getcwd", return_value="/path/to/workdir"):
4755
config._process_tags_enabled = True
4856
_process_tag_reload()
4957

50-
with self.tracer.trace("test"):
58+
with self.tracer.trace("parent"):
59+
with self.tracer.trace("child"):
60+
pass
61+
62+
@pytest.mark.snapshot
63+
def test_process_tags_edge_case(self):
64+
with patch("sys.argv", ["/test_script"]), patch("os.getcwd", return_value="/path/to/workdir"):
65+
config._process_tags_enabled = True
66+
_process_tag_reload()
67+
68+
with self.tracer.trace("span"):
5169
pass
5270

5371
@pytest.mark.snapshot
54-
def test_process_tags_only_on_local_root_span(self):
72+
def test_process_tags_error(self):
73+
with patch("sys.argv", []), patch("os.getcwd", return_value="/path/to/workdir"):
74+
config._process_tags_enabled = True
75+
76+
with self.override_global_config(dict(_telemetry_enabled=False)):
77+
with patch("ddtrace.internal.process_tags.log") as mock_log:
78+
_process_tag_reload()
79+
80+
with self.tracer.trace("span"):
81+
pass
82+
83+
# Check if debug log was called
84+
mock_log.debug.assert_called_once()
85+
call_args = mock_log.debug.call_args[0]
86+
assert "failed to get process_tags" in call_args[0]
87+
88+
@pytest.mark.snapshot
89+
@run_in_subprocess(env_overrides=dict(DD_TRACE_PARTIAL_FLUSH_ENABLED="true", DD_TRACE_PARTIAL_FLUSH_MIN_SPANS="2"))
90+
def test_process_tags_partial_flush(self):
5591
with patch("sys.argv", ["/path/to/test_script.py"]), patch("os.getcwd", return_value="/path/to/workdir"):
5692
config._process_tags_enabled = True
5793
_process_tag_reload()
58-
with self.tracer.trace("parent"):
59-
with self.tracer.trace("child"):
60-
pass
94+
95+
with self.override_global_config(dict(_partial_flush_enabled=True, _partial_flush_min_spans=2)):
96+
with self.tracer.trace("parent"):
97+
with self.tracer.trace("child1"):
98+
pass
99+
with self.tracer.trace("child2"):
100+
pass
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[[
2+
{
3+
"name": "span",
4+
"service": "tests.internal",
5+
"resource": "span",
6+
"trace_id": 0,
7+
"span_id": 1,
8+
"parent_id": 0,
9+
"type": "",
10+
"error": 0,
11+
"meta": {
12+
"_dd.p.dm": "-0",
13+
"_dd.p.tid": "6911da3a00000000",
14+
"_dd.tags.process": "entrypoint.basedir:,entrypoint.name:test_script,entrypoint.type:script,entrypoint.workdir:workdir",
15+
"language": "python",
16+
"runtime-id": "c9342b8003de45feb0bf56d32ece46a1"
17+
},
18+
"metrics": {
19+
"_dd.top_level": 1,
20+
"_dd.tracer_kr": 1.0,
21+
"_sampling_priority_v1": 1,
22+
"process_id": 605
23+
},
24+
"duration": 105292,
25+
"start": 1762777658431833668
26+
}]]
Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
11
[[
22
{
3-
"name": "test",
3+
"name": "parent",
44
"service": "tests.internal",
5-
"resource": "test",
5+
"resource": "parent",
66
"trace_id": 0,
77
"span_id": 1,
88
"parent_id": 0,
99
"type": "",
1010
"error": 0,
1111
"meta": {
1212
"_dd.p.dm": "-0",
13-
"_dd.p.tid": "690dc7bc00000000",
13+
"_dd.p.tid": "6911dc5a00000000",
1414
"_dd.tags.process": "entrypoint.basedir:to,entrypoint.name:test_script,entrypoint.type:script,entrypoint.workdir:workdir",
1515
"language": "python",
16-
"runtime-id": "97a0041576ed4e53a93eff9971a69fca"
16+
"runtime-id": "2d5de91f8dd9442cad7faca5554a09f1"
1717
},
1818
"metrics": {
1919
"_dd.top_level": 1,
2020
"_dd.tracer_kr": 1.0,
2121
"_sampling_priority_v1": 1,
2222
"process_id": 605
2323
},
24-
"duration": 94000,
25-
"start": 1762510780675377553
26-
}]]
24+
"duration": 231542,
25+
"start": 1762778202287875128
26+
},
27+
{
28+
"name": "child",
29+
"service": "tests.internal",
30+
"resource": "child",
31+
"trace_id": 0,
32+
"span_id": 2,
33+
"parent_id": 1,
34+
"type": "",
35+
"error": 0,
36+
"duration": 55500,
37+
"start": 1762778202287999128
38+
}]]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[[
2+
{
3+
"name": "test",
4+
"service": "tests.internal",
5+
"resource": "test",
6+
"trace_id": 0,
7+
"span_id": 1,
8+
"parent_id": 0,
9+
"type": "",
10+
"error": 0,
11+
"meta": {
12+
"_dd.p.dm": "-0",
13+
"_dd.p.tid": "6911dc5a00000000",
14+
"language": "python",
15+
"runtime-id": "2d5de91f8dd9442cad7faca5554a09f1"
16+
},
17+
"metrics": {
18+
"_dd.top_level": 1,
19+
"_dd.tracer_kr": 1.0,
20+
"_sampling_priority_v1": 1,
21+
"process_id": 605
22+
},
23+
"duration": 22292,
24+
"start": 1762778202327669586
25+
}]]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[[
2+
{
3+
"name": "span",
4+
"service": "tests.internal",
5+
"resource": "span",
6+
"trace_id": 0,
7+
"span_id": 1,
8+
"parent_id": 0,
9+
"type": "",
10+
"error": 0,
11+
"meta": {
12+
"_dd.p.dm": "-0",
13+
"_dd.p.tid": "6911dc5a00000000",
14+
"_dd.tags.process": "entrypoint.basedir:,entrypoint.name:test_script,entrypoint.type:script,entrypoint.workdir:workdir",
15+
"language": "python",
16+
"runtime-id": "2d5de91f8dd9442cad7faca5554a09f1"
17+
},
18+
"metrics": {
19+
"_dd.top_level": 1,
20+
"_dd.tracer_kr": 1.0,
21+
"_sampling_priority_v1": 1,
22+
"process_id": 605
23+
},
24+
"duration": 35458,
25+
"start": 1762778202321224878
26+
}]]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[[
2+
{
3+
"name": "span",
4+
"service": "tests.internal",
5+
"resource": "span",
6+
"trace_id": 0,
7+
"span_id": 1,
8+
"parent_id": 0,
9+
"type": "",
10+
"error": 0,
11+
"meta": {
12+
"_dd.p.dm": "-0",
13+
"_dd.p.tid": "6911db6e00000000",
14+
"language": "python",
15+
"runtime-id": "c59cb90aad3246579bc4421d1cca07c8"
16+
},
17+
"metrics": {
18+
"_dd.top_level": 1,
19+
"_dd.tracer_kr": 1.0,
20+
"_sampling_priority_v1": 1,
21+
"process_id": 605
22+
},
23+
"duration": 102833,
24+
"start": 1762777966446950922
25+
}]]

tests/snapshots/tests.internal.test_process_tags.TestProcessTags.test_process_tags_only_on_local_root_span.json

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
[[
2+
{
3+
"name": "parent",
4+
"service": "",
5+
"resource": "parent",
6+
"trace_id": 0,
7+
"span_id": 1,
8+
"parent_id": 0,
9+
"type": "",
10+
"error": 0,
11+
"meta": {
12+
"_dd.p.dm": "-0",
13+
"_dd.p.tid": "6911e0a800000000",
14+
"_dd.tags.process": "entrypoint.basedir:to,entrypoint.name:test_script,entrypoint.type:script,entrypoint.workdir:workdir",
15+
"language": "python",
16+
"runtime-id": "9e17705896a74bc5ba68a054ff29e42e"
17+
},
18+
"metrics": {
19+
"_dd.top_level": 1,
20+
"_dd.tracer_kr": 1.0,
21+
"_sampling_priority_v1": 1,
22+
"process_id": 629
23+
},
24+
"duration": 308417,
25+
"start": 1762779304752393180
26+
},
27+
{
28+
"name": "child1",
29+
"service": "",
30+
"resource": "child1",
31+
"trace_id": 0,
32+
"span_id": 2,
33+
"parent_id": 1,
34+
"type": "",
35+
"error": 0,
36+
"meta": {
37+
"_dd.p.dm": "-0",
38+
"_dd.p.tid": "6911e0a800000000",
39+
"_dd.tags.process": "entrypoint.basedir:to,entrypoint.name:test_script,entrypoint.type:script,entrypoint.workdir:workdir",
40+
"language": "python"
41+
},
42+
"metrics": {
43+
"_dd.py.partial_flush": 2,
44+
"_dd.tracer_kr": 1.0,
45+
"_sampling_priority_v1": 1
46+
},
47+
"duration": 11500,
48+
"start": 1762779304752417264
49+
},
50+
{
51+
"name": "child2",
52+
"service": "",
53+
"resource": "child2",
54+
"trace_id": 0,
55+
"span_id": 3,
56+
"parent_id": 1,
57+
"type": "",
58+
"error": 0,
59+
"duration": 8167,
60+
"start": 1762779304752455930
61+
}]]

0 commit comments

Comments
 (0)