Skip to content

Commit 7c41b5e

Browse files
correct env var usage
1 parent 0dd603e commit 7c41b5e

3 files changed

Lines changed: 14 additions & 29 deletions

File tree

ddtrace/internal/settings/profiling.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ def _check_for_stack_available() -> tuple[str, bool]:
7575

7676

7777
def _check_for_native_heap_available() -> tuple[str, bool]:
78-
# Importing heap_gotter dlopen's the gotter cdylib (if present) but does
79-
# NOT install anything; installation is an explicit, separate call.
80-
# The module is fail-closed and never raises on import.
78+
# Importing heap_gotter dlopen's the gotter cdylib but does NOT install
79+
# anything; installation is an explicit, separate call. Import never raises.
8180
from ddtrace.internal.datadog.profiling import heap_gotter
8281

8382
return (heap_gotter.failure_msg, heap_gotter.is_available)
@@ -694,9 +693,9 @@ def _check_for_exception_available() -> tuple[str, bool]:
694693
if not exception_is_available and config.exception.enabled:
695694
config.exception.enabled = False # pyright: ignore[reportAttributeAccessIssue]
696695

697-
# Native heap profiling only arms USDT probes via a separately-built cdylib.
696+
# Native heap profiling only arms USDT probes via the gotter cdylib.
698697
# Check availability lazily (only when requested) so the common disabled path
699-
# never dlopen's the gotter library, and fail closed if it can't be loaded.
698+
# never dlopen's the gotter library. Disable the feature if it can't be loaded.
700699
if config.native_heap.enabled:
701700
native_heap_failure_msg, native_heap_is_available = _check_for_native_heap_available()
702701
if not native_heap_is_available:

tests/profiling/test_native_heap_gotter.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
"""Smoke tests for the native (C/C++) heap profiling activator.
22
3-
The activator (``ddtrace.internal.datadog.profiling.heap_gotter``) is fail-closed
4-
and must behave correctly whether or not the opt-in gotter cdylib was built into
5-
the wheel (``DD_PROFILING_NATIVE_HEAP_ENABLED=1`` at build time):
6-
7-
* If the library is absent (the default), ``install()``/``is_installed()`` are
8-
no-ops returning ``False``.
9-
* If present (a native-heap build on Linux), ``install()`` patches the process
10-
GOT and ``is_installed()`` flips to ``True`` and stays there (idempotent).
3+
``install()`` patches the process GOT and ``is_installed()`` flips to ``True``
4+
and stays there (idempotent).
115
126
Proving that the ``ddheap`` USDT probes actually *fire* requires attaching the
137
Full Host eBPF profiler (or a ``test-support`` build exposing the hook-hit
@@ -50,15 +44,14 @@ def test_native_heap_gotter_fork_install_and_allocations() -> None:
5044
"""dlopen + install, then fork and keep allocating in parent and child.
5145
5246
Exercises the gunicorn/uWSGI-shaped path where the activator may run before
53-
fork and again in the child. When the cdylib is present, GOT overrides are
54-
inherited; when absent, install() stays a no-op. Either way, fork + alloc
55-
must not crash.
47+
fork and again in the child. GOT overrides are inherited across fork;
48+
fork + alloc must not crash.
5649
"""
5750
import os
5851

5952
from ddtrace.internal.datadog.profiling import heap_gotter
6053

61-
# Import already dlopen'd (or fail-closed). Arm in the parent.
54+
# Import already dlopen'd. Arm in the parent.
6255
armed = heap_gotter.install()
6356
if heap_gotter.is_available:
6457
assert armed is True

tests/profiling/test_profiling_config.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -237,20 +237,13 @@ def test_config_str_omits_tag_when_disabled(self, monkeypatch: pytest.MonkeyPatc
237237

238238

239239
class TestNativeHeapActivator:
240-
"""The ctypes activator must load fail-closed and never raise, regardless of
241-
platform or whether the gotter cdylib was built into the wheel.
242-
"""
240+
"""The ctypes activator must not raise on import."""
243241

244-
def test_import_is_fail_closed(self) -> None:
242+
def test_import_does_not_raise(self) -> None:
245243
from ddtrace.internal.datadog.profiling import heap_gotter
246244

247245
assert isinstance(heap_gotter.is_available, bool)
248246
assert isinstance(heap_gotter.failure_msg, str)
249-
# When the library is absent/unsupported, entry points are no-ops that
250-
# return False and do not rewrite GOT — safe to call in-process.
251-
# When available, do not call install() here: GOT patching is permanent
252-
# and would poison the shared pytest worker. That path is covered by the
253-
# subprocess smoke/fork tests in test_native_heap_gotter.py.
254-
if not heap_gotter.is_available:
255-
assert heap_gotter.install() is False
256-
assert heap_gotter.is_installed() is False
247+
# Do not call install() here: GOT patching is permanent and would poison
248+
# the shared pytest worker. That path is covered by the subprocess
249+
# smoke/fork tests in test_native_heap_gotter.py.

0 commit comments

Comments
 (0)