Skip to content

Commit fe4c7ab

Browse files
feat: add injection metadata fields to telemetry forwarder (#13679)
## Overview This change adds additional fields to the telemetry forwarder used during injection. These fields will be used to add additional context that will be surfaced to the end user in the following Figma: <img width="1272" alt="Screenshot 2025-06-16 at 11 13 35 AM" src="https://github.com/user-attachments/assets/c2070b96-fc55-4d38-bd4d-d43179c5a398" /> See [Injection Metadata](https://docs.google.com/document/d/1wydXj2fW0V0jaWU6W9pIbipT_AXD15tmbTtOPXFBEy4/edit?tab=t.f3vpy615c2dp) for more details. ## Testing Strategy I used this forwarder file to write output.json ```bash #!/bin/bash TELEMETRY_PAYLOAD=$(cat) echo $TELEMETRY_PAYLOAD > /Users/sydney.tung/go/src/github.com/DataDog/sydney/output.json ``` I used this python app ```python #!/usr/bin/env python3 print("app complete") ``` I used this script ```bash #!/bin/bash [ -f /Users/sydney.tung/go/src/github.com/DataDog/sydney/output.json ] && rm /Users/sydney.tung/go/src/github.com/DataDog/sydney/output.json export DD_APM_INSTRUMENTATION_DEBUG="true" #injector debug logging export DD_INJECTION_ENABLED=true #injecting enable & forwarding export DD_TRACE_DEBUG=true #debug logging for dd-trace-py export PYTHONPATH=/Users/sydney.tung/go/src/github.com/DataDog/dd-trace-py/lib-injection/sources:$PYTHONPATH #path -> sitecustomize.py export DD_TELEMETRY_FORWARDER_PATH=/Users/sydney.tung/go/src/github.com/DataDog/sydney/forwarder.sh #which forwarder excuted python3 /Users/sydney.tung/go/src/github.com/DataDog/sydney/app.py #random app cat /Users/sydney.tung/go/src/github.com/DataDog/sydney/output.json | jq ``` This is a sample output ```json { "metadata": { "language_name": "python", "language_version": "3.13.3", "runtime_name": "cpython", "runtime_version": "3.13.3", "tracer_version": "unknown", "pid": 49533, "result": "unknown", "result_reason": "unknown", "result_class": "unknown" }, "points": [ { "name": "library_entrypoint.error", "tags": [ "error_type:main_filenotfounderror" ] } ] } ``` ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) --------- Co-authored-by: brettlangdon <[email protected]>
1 parent b0c1496 commit fe4c7ab

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

lib-injection/sources/sitecustomize.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ def parse_version(version):
5656
PYTHON_VERSION = "unknown"
5757
PYTHON_RUNTIME = "unknown"
5858
DDTRACE_REQUIREMENTS = {}
59+
RESULT = "unknown"
60+
RESULT_REASON = "unknown"
61+
RESULT_CLASS = "unknown"
5962
EXECUTABLES_DENY_LIST = set()
6063
REQUIREMENTS_FILE_LOCATIONS = (
6164
os.path.abspath(os.path.join(SCRIPT_DIR, "../datadog-lib/requirements.csv")),
@@ -162,6 +165,9 @@ def gen_telemetry_payload(telemetry_events, ddtrace_version):
162165
"runtime_version": PYTHON_VERSION,
163166
"tracer_version": ddtrace_version,
164167
"pid": os.getpid(),
168+
"result": RESULT,
169+
"result_reason": RESULT_REASON,
170+
"result_class": RESULT_CLASS,
165171
},
166172
"points": telemetry_events,
167173
}
@@ -275,6 +281,9 @@ def _inject():
275281
global DDTRACE_REQUIREMENTS
276282
global EXECUTABLES_DENY_LIST
277283
global TELEMETRY_DATA
284+
global RESULT
285+
global RESULT_REASON
286+
global RESULT_CLASS
278287
# Try to get the version of the Python runtime first so we have it for telemetry
279288
PYTHON_VERSION = platform.python_version()
280289
PYTHON_RUNTIME = platform.python_implementation().lower()
@@ -321,6 +330,9 @@ def _inject():
321330
"library_entrypoint.abort.integration",
322331
)
323332
)
333+
RESULT = "abort"
334+
RESULT_REASON = "Found incompatible executable: %s." % incompatible_sysarg
335+
RESULT_CLASS = "incompatible_runtime"
324336
else:
325337
_log(
326338
"DD_INJECT_FORCE set to True, allowing unsupported executables and continuing.",
@@ -351,6 +363,9 @@ def _inject():
351363
)
352364
)
353365

366+
RESULT = "abort"
367+
RESULT_REASON = "Found incompatible packages: %s." % incompatible_packages
368+
RESULT_CLASS = "incompatible_runtime"
354369
else:
355370
_log(
356371
"DD_INJECT_FORCE set to True, allowing unsupported dependencies and continuing.",
@@ -368,6 +383,13 @@ def _inject():
368383
abort = True
369384

370385
TELEMETRY_DATA.append(create_count_metric("library_entrypoint.abort.runtime"))
386+
RESULT = "abort"
387+
RESULT_REASON = "Found incompatible runtime: %s %s. Supported runtimes: %s" % (
388+
PYTHON_RUNTIME,
389+
PYTHON_VERSION,
390+
RUNTIMES_ALLOW_LIST,
391+
)
392+
RESULT_CLASS = "incompatible_runtime"
371393
else:
372394
_log(
373395
"DD_INJECT_FORCE set to True, allowing unsupported runtimes and continuing.",
@@ -393,6 +415,9 @@ def _inject():
393415
TELEMETRY_DATA.append(
394416
create_count_metric("library_entrypoint.abort", ["reason:missing_" + site_pkgs_path]),
395417
)
418+
RESULT = "error"
419+
RESULT_REASON = "ddtrace site-packages not found in %r, aborting" % site_pkgs_path
420+
RESULT_CLASS = "incorrect_installation"
396421
return
397422

398423
# Add the custom site-packages directory to the Python path to load the ddtrace package.
@@ -411,7 +436,9 @@ def _inject():
411436
"library_entrypoint.error", ["error_type:import_ddtrace_" + type(e).__name__.lower()]
412437
),
413438
)
414-
439+
RESULT = "error"
440+
RESULT_REASON = "Failed to load ddtrace module: %s" % e
441+
RESULT_CLASS = "internal_error"
415442
return
416443
else:
417444
try:
@@ -457,12 +484,18 @@ def _inject():
457484
],
458485
),
459486
)
487+
RESULT = "success"
488+
RESULT_REASON = "Successfully configured ddtrace package"
489+
RESULT_CLASS = "success" if not (runtime_incomp or integration_incomp) else "success_forced"
460490
except Exception as e:
461491
TELEMETRY_DATA.append(
462492
create_count_metric(
463493
"library_entrypoint.error", ["error_type:init_ddtrace_" + type(e).__name__.lower()]
464494
),
465495
)
496+
RESULT = "error"
497+
RESULT_REASON = "Failed to load ddtrace.bootstrap.sitecustomize: %s" % e
498+
RESULT_CLASS = "internal_error"
466499
_log("failed to load ddtrace.bootstrap.sitecustomize: %s" % e, level="error")
467500
return
468501
else:
@@ -476,6 +509,9 @@ def _inject():
476509
],
477510
)
478511
)
512+
RESULT = "abort"
513+
RESULT_REASON = "User-installed ddtrace found: %s, aborting site-packages injection" % module_origin
514+
RESULT_CLASS = "already_instrumented"
479515

480516

481517
try:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
other:
3+
- |
4+
lib-injection: Additional fields have been added to the telemetry forwarder used during Single Step to surface troubleshooting insights in the Datadog UI.

0 commit comments

Comments
 (0)