Skip to content

Commit 081867e

Browse files
[mq] working branch - merge a2116d0 on top of main at d239f91
{"baseBranch":"main","baseCommit":"d239f91be2c4ca1ec2ded88263ed132e28fe031b","createdAt":"2025-12-05T05:42:38.077429Z","headSha":"a2116d08880b18010356afa05ae8639376ac10eb","id":"c6a15405-a9bf-48bf-b5db-96d889c78fa7","priority":"200","pullRequestNumber":"15509","queuedAt":"2025-12-05T05:42:38.076412Z","status":"STATUS_QUEUED"}
2 parents 0792955 + a2116d0 commit 081867e

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

ddtrace/internal/core/crashtracking.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,11 @@ def _get_args(additional_tags: Optional[Dict[str, str]]):
120120
)
121121

122122
# Create crashtracker receiver configuration
123+
# Pass all environment variables to the receiver process so it can access
124+
# all env vars since it's spawned using execve() and not fork()
123125
receiver_config = CrashtrackerReceiverConfig(
124126
[], # args
125-
{}, # env
127+
dict(os.environ), # env - pass all environment variables
126128
dd_crashtracker_receiver, # path_to_receiver_binary
127129
crashtracker_config.stderr_filename,
128130
crashtracker_config.stdout_filename,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
crashtracker: Fixes missing env variables inheritance for receiver process.

tests/internal/crashtracker/test_crashtracker.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,3 +790,44 @@ def test_crashtracker_no_zombies():
790790
break
791791
except Exception as e:
792792
pytest.fail("Unexpected exception: %s" % e)
793+
794+
795+
@pytest.mark.skipif(not sys.platform.startswith("linux"), reason="Linux only")
796+
@pytest.mark.subprocess()
797+
def test_crashtracker_receiver_env_inheritance():
798+
"""
799+
The receiver is spawned using execve() and doesn't automatically inherit the
800+
env, so we need to ensure all env variables are explicitly passed
801+
when building the receiver config.
802+
"""
803+
import ctypes
804+
import os
805+
806+
import tests.internal.crashtracker.utils as utils
807+
808+
test_env_key = "MY_TEST_ENV_VAR"
809+
test_env_value = "my_test_value"
810+
os.environ[test_env_key] = test_env_value
811+
812+
with utils.with_test_agent() as client:
813+
pid = os.fork()
814+
if pid == 0:
815+
assert os.environ.get(test_env_key) == test_env_value
816+
817+
ct = utils.CrashtrackerWrapper(base_name="env_inheritance")
818+
assert ct.start()
819+
stdout_msg, stderr_msg = ct.logs()
820+
assert not stdout_msg, stdout_msg
821+
assert not stderr_msg, stderr_msg
822+
823+
ctypes.string_at(0)
824+
sys.exit(-1)
825+
826+
# Check for crash ping
827+
_ping = utils.get_crash_ping(client)
828+
# Check for crash report
829+
report = utils.get_crash_report(client)
830+
assert b"string_at" in report["body"]
831+
832+
# Clean up
833+
os.environ.pop(test_env_key, None)

0 commit comments

Comments
 (0)