@@ -250,6 +250,73 @@ def test_batch_json_encoder():
250250 assert queue .count == 0
251251
252252
253+ def test_process_tags_are_not_included_by_default ():
254+ s = Snapshot (
255+ probe = create_snapshot_line_probe (probe_id = "batch-test" , source_file = "foo.py" , line = 42 ),
256+ frame = inspect .currentframe (),
257+ thread = threading .current_thread (),
258+ )
259+ buffer_size = 30 * (1 << 20 )
260+ queue = SignalQueue (encoder = LogSignalJsonEncoder (None ), buffer_size = buffer_size )
261+
262+ s .line ({})
263+
264+ queue = SignalQueue (encoder = LogSignalJsonEncoder ("test-service" ))
265+ queue .put (s )
266+ data = queue .flush ()
267+ assert data is not None
268+ payload , _ = data
269+ decoded = json .loads (payload .decode ())
270+ assert "process_tags" not in decoded [0 ]
271+
272+
273+ def test_process_tags_are_included ():
274+ from unittest .mock import patch
275+
276+ from ddtrace .internal .process_tags import _process_tag_reload
277+ from ddtrace .internal .process_tags .constants import ENTRYPOINT_BASEDIR_TAG
278+ from ddtrace .internal .process_tags .constants import ENTRYPOINT_NAME_TAG
279+ from ddtrace .internal .process_tags .constants import ENTRYPOINT_TYPE_SCRIPT
280+ from ddtrace .internal .process_tags .constants import ENTRYPOINT_TYPE_TAG
281+ from ddtrace .internal .process_tags .constants import ENTRYPOINT_WORKDIR_TAG
282+ from ddtrace .settings ._config import config
283+
284+ try :
285+ with patch ("sys.argv" , ["/path/to/test_script.py" ]), patch ("os.getcwd" , return_value = "/path/to/workdir" ):
286+ config ._process_tags_enabled = True
287+ _process_tag_reload ()
288+ s = Snapshot (
289+ probe = create_snapshot_line_probe (probe_id = "batch-test" , source_file = "foo.py" , line = 42 ),
290+ frame = inspect .currentframe (),
291+ thread = threading .current_thread (),
292+ )
293+ buffer_size = 30 * (1 << 20 )
294+ queue = SignalQueue (encoder = LogSignalJsonEncoder (None ), buffer_size = buffer_size )
295+
296+ s .line ({})
297+
298+ queue = SignalQueue (encoder = LogSignalJsonEncoder ("test-service" ))
299+ queue .put (s )
300+ data = queue .flush ()
301+ assert data is not None
302+ payload , _ = data
303+ decoded = json .loads (payload .decode ())
304+
305+ assert "process_tags" in decoded [0 ]
306+
307+ expected_raw = (
308+ f"{ ENTRYPOINT_BASEDIR_TAG } :to,"
309+ f"{ ENTRYPOINT_NAME_TAG } :test_script,"
310+ f"{ ENTRYPOINT_TYPE_TAG } :{ ENTRYPOINT_TYPE_SCRIPT } ,"
311+ f"{ ENTRYPOINT_WORKDIR_TAG } :workdir"
312+ )
313+
314+ assert decoded [0 ]["process_tags" ] == expected_raw
315+ finally :
316+ config ._process_tags_enabled = False
317+ _process_tag_reload ()
318+
319+
253320def test_batch_flush_reencode ():
254321 s = Snapshot (
255322 probe = create_snapshot_line_probe (probe_id = "batch-test" , source_file = "foo.py" , line = 42 ),
0 commit comments