Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions ddtrace/internal/core/crashtracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from ddtrace.internal.native._native import crashtracker_init
from ddtrace.internal.native._native import crashtracker_on_fork
from ddtrace.internal.native._native import crashtracker_status
from ddtrace.internal.native._native import crashtracker_register_native_runtime_callback
from ddtrace.internal.native._native import CallbackResult
except ImportError:
is_available = False

Expand Down Expand Up @@ -169,3 +171,26 @@ def crashtracker_fork_handler():
print(f"Failed to start crashtracker: {e}", file=sys.stderr)
return False
return True


def register_runtime_callback() -> bool:
"""
Register the native runtime callback for stack collection during crashes.

This should be called after crashtracker initialization to enable Python
runtime stack trace collection in crash reports.

Returns:
bool: True if callback was registered successfully, False otherwise
"""
if not is_available:
return False
if not is_started():
return False

try:
result = crashtracker_register_native_runtime_callback()
return result == CallbackResult.Ok
except Exception as e:
print(f"Failed to register runtime callback: {e}", file=sys.stderr)
return False
103 changes: 103 additions & 0 deletions experimental_debug.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"runtime_stack": {
"format": "Datadog Runtime Callback 1.0",
"frames": [
{
"function": "<module>",
"file": "<string>",
"line": 1
},
{
"function": "string_at",
"file": "/home/bits/.pyenv/versions/3.13.5/lib/python3.13/ctypes/__init__.py",
"line": 538
},
{
"function": "func16",
"file": "tests/internal/crashtracker/test_crashtracker.py",
"line": 679
},
{
"function": "func15",
"file": "tests/internal/crashtracker/test_crashtracker.py",
"line": 676
},
{
"function": "func14",
"file": "tests/internal/crashtracker/test_crashtracker.py",
"line": 673
},
{
"function": "func13",
"file": "tests/internal/crashtracker/test_crashtracker.py",
"line": 670
},
{
"function": "func12",
"file": "tests/internal/crashtracker/test_crashtracker.py",
"line": 667
},
{
"function": "func11",
"file": "tests/internal/crashtracker/test_crashtracker.py",
"line": 664
},
{
"function": "func10",
"file": "tests/internal/crashtracker/test_crashtracker.py",
"line": 661
},
{
"function": "func9",
"file": "tests/internal/crashtracker/test_crashtracker.py",
"line": 658
},
{
"function": "func8",
"file": "tests/internal/crashtracker/test_crashtracker.py",
"line": 655
},
{
"function": "func7",
"file": "tests/internal/crashtracker/test_crashtracker.py",
"line": 652
},
{
"function": "func6",
"file": "tests/internal/crashtracker/test_crashtracker.py",
"line": 649
},
{
"function": "func5",
"file": "tests/internal/crashtracker/test_crashtracker.py",
"line": 646
},
{
"function": "func4",
"file": "tests/internal/crashtracker/test_crashtracker.py",
"line": 643
},
{
"function": "func3",
"file": "tests/internal/crashtracker/test_crashtracker.py",
"line": 640
},
{
"function": "func2",
"file": "tests/internal/crashtracker/test_crashtracker.py",
"line": 637
},
{
"function": "func1",
"file": "tests/internal/crashtracker/test_crashtracker.py",
"line": 634
},
{
"function": "<module>",
"file": "tests/internal/crashtracker/test_crashtracker.py",
"line": 699
}
],
"runtime_type": "unknown"
}
}
69 changes: 35 additions & 34 deletions src/native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions src/native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ profiling = ["dep:datadog-profiling-ffi"]

[dependencies]
anyhow = { version = "1.0", optional = true }
datadog-crashtracker = { git = "https://github.com/DataDog/libdatadog", rev = "v21.0.0", optional = true }
datadog-ddsketch = { git = "https://github.com/DataDog/libdatadog", rev = "v21.0.0" }
datadog-library-config = { git = "https://github.com/DataDog/libdatadog", rev = "v21.0.0" }
data-pipeline = { git = "https://github.com/DataDog/libdatadog", rev = "v21.0.0" }
datadog-profiling-ffi = { git = "https://github.com/DataDog/libdatadog", rev = "v21.0.0", optional = true, features = [
datadog-crashtracker = { git = "https://github.com/DataDog/libdatadog", rev = "488d39573f008957784aa4ef726fadb4bee5a302", optional = true }
datadog-ddsketch = { git = "https://github.com/DataDog/libdatadog", rev = "488d39573f008957784aa4ef726fadb4bee5a302" }
datadog-library-config = { git = "https://github.com/DataDog/libdatadog", rev = "488d39573f008957784aa4ef726fadb4bee5a302" }
data-pipeline = { git = "https://github.com/DataDog/libdatadog", rev = "488d39573f008957784aa4ef726fadb4bee5a302" }
datadog-profiling-ffi = { git = "https://github.com/DataDog/libdatadog", rev = "488d39573f008957784aa4ef726fadb4bee5a302", optional = true, features = [
"cbindgen",
] }
ddcommon = { git = "https://github.com/DataDog/libdatadog", rev = "v21.0.0" }
ddcommon = { git = "https://github.com/DataDog/libdatadog", rev = "488d39573f008957784aa4ef726fadb4bee5a302" }
pyo3 = { version = "0.25", features = ["extension-module", "anyhow"] }
pyo3-ffi = "0.25"

[build-dependencies]
pyo3-build-config = "0.25"
build_common = { git = "https://github.com/DataDog/libdatadog", rev = "v21.0.0", features = [
build_common = { git = "https://github.com/DataDog/libdatadog", rev = "488d39573f008957784aa4ef726fadb4bee5a302", features = [
"cbindgen",
] }

Expand Down
Loading
Loading