Skip to content

Commit c122961

Browse files
authored
chore(telemetry): fix ssi instrumentation tracking + fix failing docker_ssi test (#13609)
Fixes the collection of instrumentation telemetry for ssi. Note this is not a customer facing fix, a release note is not required. Resolves the following CI error: https://gitlab.ddbuild.io/DataDog/apm-reliability/dd-trace-py/-/jobs/968352550 ## 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)
1 parent 40eab4b commit c122961

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

ddtrace/bootstrap/sitecustomize.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ def _(threading):
166166
else:
167167
log.debug("additional sitecustomize found in: %s", sys.path)
168168

169-
if os.getenv("_DD_SSI_INJECT_SUCCESSFUL"):
170-
# _DD_SSI_INJECT_SUCCESSFUL is set in lib-injection/sources/sitecustomize.py after ssi is completed
169+
if os.getenv("_DD_PY_SSI_INJECT") == "1":
170+
# _DD_PY_SSI_INJECT is set to `1` in lib-injection/sources/sitecustomize.py when ssi is started
171+
# and doesn't abort.
171172
source = "ssi"
172173
elif os.path.join(os.path.dirname(ddtrace.__file__), "bootstrap") in sys.path:
173174
# Checks the python path to see if the bootstrap directory is present, this operation

ddtrace/settings/_config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,8 @@ def __init__(self):
647647
self._llmobs_agentless_enabled = _get_config("DD_LLMOBS_AGENTLESS_ENABLED", None, asbool)
648648

649649
self._inject_force = _get_config("DD_INJECT_FORCE", None, asbool)
650-
self._lib_was_injected = False
650+
# Telemetry for whether ssi instrumented an app is tracked by the `instrumentation_source` config
651+
self._lib_was_injected = _get_config("_DD_PY_SSI_INJECT", False, asbool, report_telemetry=False)
651652
self._inject_enabled = _get_config("DD_INJECTION_ENABLED")
652653
self._inferred_proxy_services_enabled = _get_config("DD_TRACE_INFERRED_PROXY_SERVICES_ENABLED", False, asbool)
653654
self._trace_safe_instrumentation_enabled = _get_config("DD_TRACE_SAFE_INSTRUMENTATION_ENABLED", False, asbool)

lib-injection/sources/sitecustomize.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,13 @@ def _inject():
373373
# Add the custom site-packages directory to the Python path to load the ddtrace package.
374374
sys.path.insert(-1, site_pkgs_path)
375375
_log("sys.path %s" % sys.path, level="debug")
376+
# Used to track whether the ddtrace package was successfully injected. Must be set before importing ddtrace
377+
os.environ["_DD_PY_SSI_INJECT"] = "1"
376378
try:
377379
import ddtrace # noqa: F401
378380

379381
except BaseException as e:
382+
os.environ["_DD_PY_SSI_INJECT"] = "0"
380383
_log("failed to load ddtrace module: %s" % e, level="error")
381384
TELEMETRY_DATA.append(
382385
create_count_metric(
@@ -429,10 +432,6 @@ def _inject():
429432
],
430433
),
431434
)
432-
# Track whether library injection was successful
433-
ddtrace.config._lib_was_injected = True
434-
os.environ["_DD_SSI_INJECT_SUCCESSFUL"] = "1"
435-
ddtrace.internal.telemetry.telemetry_writer.add_configuration("instrumentation_source", "ssi", "code")
436435
except Exception as e:
437436
TELEMETRY_DATA.append(
438437
create_count_metric(

0 commit comments

Comments
 (0)