chore(profiling): gate unsupported platforms - #20108
Conversation
Co-authored-by: KowalskiThomas <14239160+KowalskiThomas@users.noreply.github.com>
|
I can only run on private repositories. |
Codeowners resolved asResolved from the full PR diff against |
Circular import analysis
|
Dependency direction analysis
|
|
Description
Instrumentation telemetry was reporting error-level logs on Windows such as:
Failed to load stack module (cannot import name '_stack' from partially initialized module 'ddtrace.internal.datadog.profiling.stack' ...), disabling stack profilingRoot cause:
ddtrace/bootstrap/preload.pyimportsddtrace.internal.settings.profilingunconditionally (before theDD_PROFILING_ENABLEDgate). At import time that module ran_check_for_ddup_available()/_check_for_stack_available(), which try to import the native_ddup/_stackextensions. Those extensions are only built for 64-bit CPython < 3.15 on Linux/macOS (see the gate insetup.py), so on Windows the import always fails — surfacing as a confusing "partially initialized module ... circular import"ImportError— and the module emitted ERROR-level telemetry. Profiling was only ever disabled as a side effect of that failed import; there was no positive platform check.Changes:
_is_platform_supported()inddtrace/internal/settings/profiling.py, mirroring the build-time gate insetup.py(64-bit Linux/macOS, CPython < 3.15).config.enabled/config.stack.enabled(andexception/native_heap) quietly via a debug log, instead of attempting the native imports and emitting ERROR-level "Failed to load ... module" telemetry for an expected, advertised-as-unsupported condition. Behavior on supported platforms is unchanged.ddtrace/profiling/bootstrap/sitecustomize.pygate reuse the same helper so exotic unsupported cases (e.g. 32-bit macOS, Python 3.15+) are also caught, in addition to the existing Windows / 32-bit Linux messages.Testing
Added a regression test
test_unsupported_platform_disables_profiling_quietlyintests/profiling/test_profiler.pythat mocksplatform.system()to"Windows", imports the profiling settings, and asserts profiling is disabled and no "Failed to load" telemetry is emitted. Existingtest_stack_failure_telemetry_logging/test_libdd_failure_telemetry_loggingcontinue to assert the ERROR telemetry still fires on supported platforms.Automated validation performed in this environment:
ruff format --checkandruff checkpass on all changed files; files byte-compile; the_is_platform_supported()decision table was verified against thesetup.pygate. The native extensions are not built in this sandbox, so the profiling test suite could not be executed here.TODO (human): validate in real services in staging and confirm no new crashes.
Risks
Low. On supported platforms (64-bit Linux/macOS, CPython < 3.15) the code path is unchanged — the native probes and their ERROR telemetry still run exactly as before. On unsupported platforms the profiler was already non-functional; this change only suppresses misleading ERROR telemetry and disables the config explicitly rather than implicitly.
Additional Notes
The helper intentionally duplicates the
setup.pygate logic; a comment in both places notes they must be kept in sync.Pre-review checklist
PR by Bits - View session in Datadog
Comment @DataDog to request changes