Skip to content

Commit 3d7e822

Browse files
committed
Use ddconfig for runtime stacktrace emission
1 parent 055a5f2 commit 3d7e822

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

ddtrace/internal/core/crashtracking.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ def start(additional_tags: Optional[Dict[str, str]] = None) -> bool:
153153
print("Failed to start crashtracker: failed to construct crashtracker configuration", file=sys.stderr)
154154
return False
155155

156+
# crashtracker_init(
157+
# config, receiver_config, metadata, emit_runtime_stacks=crashtracker_config.emit_runtime_stacks
158+
# )
159+
156160
crashtracker_init(config, receiver_config, metadata)
157161

158162
def crashtracker_fork_handler():

ddtrace/internal/native/_native.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ class CrashtrackerStatus:
9696
FailedToInitialize: "CrashtrackerStatus"
9797

9898
def crashtracker_init(
99-
config: CrashtrackerConfiguration, receiver_config: CrashtrackerReceiverConfig, metadata: CrashtrackerMetadata
99+
config: CrashtrackerConfiguration,
100+
receiver_config: CrashtrackerReceiverConfig,
101+
metadata: CrashtrackerMetadata,
102+
# TODO: Add this back in post Code Freeze (need to update config registry)
103+
# emit_runtime_stacks: bool,
100104
) -> None: ...
101105
def crashtracker_on_fork(
102106
config: CrashtrackerConfiguration, receiver_config: CrashtrackerReceiverConfig, metadata: CrashtrackerMetadata

ddtrace/internal/settings/crashtracker.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ class CrashtrackingConfig(DDConfig):
121121
help="Whether to wait for the crashtracking receiver",
122122
)
123123

124+
# TODO: Add this back in post Code Freeze (need to update config registry)
125+
# emit_runtime_stacks = DDConfig.v(
126+
# bool,
127+
# "emit_runtime_stacks",
128+
# default=False,
129+
# help_type="Boolean",
130+
# help="Whether to emit runtime stacks during a crash.",
131+
# )
132+
124133

125134
config = CrashtrackingConfig()
126135
report_configuration(config)

src/native/crashtracker.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ type PyDumpTracebackThreadsFn = unsafe extern "C" fn(
2424
static mut DUMP_TRACEBACK_FN: Option<PyDumpTracebackThreadsFn> = None;
2525
static DUMP_TRACEBACK_INIT: std::sync::Once = std::sync::Once::new();
2626

27+
// We define these raw system calls here to be used within signal handler context.
28+
// These direct C functions are preferred over going through Rust wrappers
2729
extern "C" {
2830
fn pipe(pipefd: *mut [c_int; 2]) -> c_int;
2931
fn read(fd: c_int, buf: *mut c_void, count: usize) -> isize;
@@ -245,6 +247,8 @@ pub fn crashtracker_init<'py>(
245247
mut config: PyRefMut<'py, CrashtrackerConfigurationPy>,
246248
mut receiver_config: PyRefMut<'py, CrashtrackerReceiverConfigPy>,
247249
mut metadata: PyRefMut<'py, CrashtrackerMetadataPy>,
250+
// TODO: Add this back in post Code Freeze (need to update config registry)
251+
// emit_runtime_stacks: bool,
248252
) -> anyhow::Result<()> {
249253
INIT.call_once(|| {
250254
let (config_opt, receiver_config_opt, metadata_opt) = (
@@ -256,8 +260,8 @@ pub fn crashtracker_init<'py>(
256260
if let (Some(config), Some(receiver_config), Some(metadata)) =
257261
(config_opt, receiver_config_opt, metadata_opt)
258262
{
259-
let runtime_stacktrace_enabled = std::env::var("DD_CRASHTRACKER_EMIT_RUNTIME_STACKS").unwrap_or_default();
260-
if runtime_stacktrace_enabled == "true" || runtime_stacktrace_enabled == "1" {
263+
let emit_runtime_stacks = std::env::var("DD_CRASHTRACKING_EMIT_RUNTIME_STACKS").unwrap_or("false".to_string());
264+
if emit_runtime_stacks {
261265
unsafe {
262266
init_dump_traceback_fn();
263267
}

tests/internal/crashtracker/test_crashtracker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def test_crashtracker_tags_required():
460460
def test_crashtracker_runtime_stacktrace_required(run_python_code_in_subprocess):
461461
with utils.with_test_agent() as client:
462462
env = os.environ.copy()
463-
env["DD_CRASHTRACKER_EMIT_RUNTIME_STACKS"] = "true"
463+
env["DD_CRASHTRACKING_EMIT_RUNTIME_STACKS"] = "true"
464464
stdout, stderr, exitcode, _ = run_python_code_in_subprocess(auto_code, env=env)
465465

466466
# Check for expected exit condition

0 commit comments

Comments
 (0)