Skip to content

Commit fdd6480

Browse files
authored
chore(di): add process_tags (#15225)
This PR implements this [RFC](https://docs.google.com/document/d/1AFdLUuVk70i0bJd5335-RxqsvwAV9ovAqcO2z5mEMbA/edit?pli=1&tab=t.0#heading=h.s9l1lctqlg11) for dynamic instrumentation. Add process_tags to dynamic instrumentation payload ## Testing - Check that process tags are not included if deactivated - Check the right process tags are set in the payload when activated
1 parent 914d52a commit fdd6480

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

ddtrace/debugging/_encoding.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from ddtrace.debugging._signal.log import LogSignal
2121
from ddtrace.debugging._signal.snapshot import Snapshot
2222
from ddtrace.internal import forksafe
23+
from ddtrace.internal import process_tags
2324
from ddtrace.internal._encoding import BufferFull
2425
from ddtrace.internal.logger import get_logger
2526
from ddtrace.internal.utils.formats import format_trace_id
@@ -113,6 +114,9 @@ def _build_log_track_payload(
113114
"timestamp": int(signal.timestamp * 1e3), # milliseconds,
114115
}
115116

117+
if p_tags := process_tags.process_tags:
118+
payload["process_tags"] = p_tags
119+
116120
# Add the correlation IDs if available
117121
if context is not None and context.trace_id is not None:
118122
payload["dd"] = {

tests/debugging/test_encoding.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,61 @@ 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+
@pytest.mark.subprocess(
274+
env=dict(
275+
DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED="true",
276+
)
277+
)
278+
def test_process_tags_are_included():
279+
import inspect
280+
import json
281+
import threading
282+
283+
from ddtrace.debugging._encoding import LogSignalJsonEncoder
284+
from ddtrace.debugging._encoding import SignalQueue
285+
from ddtrace.debugging._signal.snapshot import Snapshot
286+
from tests.debugging.utils import create_snapshot_line_probe
287+
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+
253308
def test_batch_flush_reencode():
254309
s = Snapshot(
255310
probe=create_snapshot_line_probe(probe_id="batch-test", source_file="foo.py", line=42),

0 commit comments

Comments
 (0)