Skip to content

Conversation

@gyuheon0h
Copy link
Contributor

@gyuheon0h gyuheon0h commented Oct 16, 2025

What does this PR do?
We want to collect runtime frames for the crashtracker. This approach follows how we access the call stack for profiling.

CI fails currently because we are not on libdatadog v24 yet. Once this PR is merged and this PR is rebased, we should be green

Motivation:

Change log entry

Additional Notes:

How to test the change?

"Ruby and C method runtime stack capture" RSpec test

Run a ruby program with the crashtracker initialized. Runtime stacks should be visible in the experimental section of the crash report. Stacktrace emitted from an example script I wrote to test

{
  "format": "Datadog Runtime Callback 1.0",
  "frames": [
    {
      "file": "<Fiddle (C extension)>",
      "function": "free"
    },
    {
      "file": "debug_runtime_callback.rb",
      "function": "final_crash_point",
      "line": 244
    },
    {
      "file": "<Integer (C extension)>",
      "function": "times"
    },
    {
      "file": "debug_runtime_callback.rb",
      "function": "final_crash_point",
      "line": 243
    },
   .....
    {
      "file": "debug_runtime_callback.rb",
      "function": "main_crash_test",
      "line": 251
    },
    {
      "file": "debug_runtime_callback.rb",
      "function": "<main>",
      "line": 276
    },
    {
      "file": "<Kernel (C extension)>",
      "function": "fork"
    }
  ]
}

@gyuheon0h gyuheon0h requested review from a team as code owners October 16, 2025 09:34
@gyuheon0h gyuheon0h marked this pull request as draft October 16, 2025 09:34
@github-actions
Copy link

github-actions bot commented Oct 16, 2025

👋 Hey @DataDog/ruby-guild, please fill "Change log entry" section in the pull request description.

If changes need to be present in CHANGELOG.md you can state it this way

**Change log entry**

Yes. A brief summary to be placed into the CHANGELOG.md

(possible answers Yes/Yep/Yeah)

Or you can opt out like that

**Change log entry**

None.

(possible answers No/Nope/None)

Visited at: 2025-11-17 03:53:49 UTC

@github-actions github-actions bot added the core Involves Datadog core libraries label Oct 16, 2025
@github-actions
Copy link

github-actions bot commented Oct 16, 2025

Typing analysis

This PR does not change typing compared to the base branch.

@datadog-datadog-prod-us1

This comment has been minimized.

@gyuheon0h gyuheon0h force-pushed the gyuheon0h/prof-12743-runtime-stack-callback branch from e628919 to 564c828 Compare October 24, 2025 15:37
Copy link
Contributor Author

gyuheon0h commented Oct 24, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@gyuheon0h gyuheon0h force-pushed the gyuheon0h/prof-12743-runtime-stack-callback branch 3 times, most recently from f102a46 to 53afc20 Compare October 31, 2025 15:19
@gyuheon0h
Copy link
Contributor Author

gyuheon0h commented Nov 8, 2025

Paper trail

[ ] Checking unreasonable string sizes
[ ] Checking that string pointers point to valid strings
[ ] Checking that control frames are valid
[ ] Checking that iseq is valid, and the instruction size is not unreasonable
[ ] Validating that pointers are readable using mincore
[ ] Checking for recursive frames
[ ] Strings can have different representations, take that into account
[ ] Ruby apps commonly have very deep stacks. We default in the profiler to collecting 400 and we've seen GitHub go close to 600, handle this
[ ] Pay attention to structure keeping the bytecode-to-line mapping

@gyuheon0h gyuheon0h force-pushed the gyuheon0h/prof-12743-runtime-stack-callback branch 6 times, most recently from 77d1391 to 1ebb325 Compare November 17, 2025 02:56
# * by msgpack, another datadog gem dependency
# (https://github.com/msgpack/msgpack-ruby/blob/18ce08f6d612fe973843c366ac9a0b74c4e50599/ext/msgpack/extconf.rb#L8)
append_cflags '-std=gnu99'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken from ext/datadog_profiling_native_extension/extconf.rb, so that we can access private Ruby headers

@gyuheon0h gyuheon0h force-pushed the gyuheon0h/prof-12743-runtime-stack-callback branch from 1ebb325 to 4e51bf3 Compare November 17, 2025 03:40

# Benchmark result files
/benchmarks/*.json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be removed when this repo is updated to use libdatadog v24; just for lower friction when local dev rn

@@ -1,7 +1,49 @@
#include <ruby.h>
#include <datadog/crashtracker.h>
#include "extconf.h"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken from ext/datadog_profiling_native_extension/private_vm_api_access.c so that we can access internal Ruby structures

@gyuheon0h gyuheon0h force-pushed the gyuheon0h/prof-12743-runtime-stack-callback branch 2 times, most recently from 3c782d0 to 8d957bf Compare November 17, 2025 03:48
@github-actions github-actions bot added the profiling Involves Datadog profiling label Nov 17, 2025
@gyuheon0h gyuheon0h marked this pull request as ready for review November 17, 2025 03:52
@gyuheon0h gyuheon0h changed the title [WIP][crashtracking] Runtime stack collection callback registration [crashtracking] Runtime stack collection callback registration Nov 17, 2025
@gyuheon0h gyuheon0h changed the title [crashtracking] Runtime stack collection callback registration [PROF-12743] Runtime stack collection callback registration Nov 17, 2025
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@gyuheon0h gyuheon0h force-pushed the gyuheon0h/prof-12743-runtime-stack-callback branch from 8d957bf to 98cb61e Compare November 17, 2025 04:17
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@gyuheon0h gyuheon0h force-pushed the gyuheon0h/prof-12743-runtime-stack-callback branch from 98cb61e to 77de730 Compare November 17, 2025 04:24
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@gyuheon0h gyuheon0h force-pushed the gyuheon0h/prof-12743-runtime-stack-callback branch from 77de730 to 16fede1 Compare November 17, 2025 04:36
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 57 to +60
Utils::AtForkMonkeyPatch.apply!

start_or_update_on_fork(action: :start, tags: tags)
register_runtime_stack_callback

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Guard runtime callback registration on repeated starts

The new start path always invokes register_runtime_stack_callback, and register_runtime_stack_callback raises whenever the native call returns false (e.g. callback already registered). Because the crash tracker component is process‑wide and Datadog.configure can instantiate and start a new component multiple times, the second start now raises Failed to register runtime stack callback and prevents reconfiguration or restarts from succeeding. Consider checking _native_is_runtime_callback_registered or otherwise making the registration idempotent so that later start calls do not blow up.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not true, if a callback is already registered, it should replace it

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@gyuheon0h gyuheon0h force-pushed the gyuheon0h/prof-12743-runtime-stack-callback branch 2 times, most recently from 989188a to 5309fef Compare November 17, 2025 13:16
@gyuheon0h gyuheon0h requested a review from ivoanjo November 17, 2025 13:17
@gyuheon0h gyuheon0h force-pushed the gyuheon0h/prof-12743-runtime-stack-callback branch from 5309fef to 50da69c Compare November 17, 2025 14:30
@gyuheon0h gyuheon0h marked this pull request as draft November 17, 2025 15:17
@gyuheon0h gyuheon0h force-pushed the gyuheon0h/prof-12743-runtime-stack-callback branch from 3ff1774 to af340dd Compare November 17, 2025 16:15
@gyuheon0h gyuheon0h force-pushed the gyuheon0h/prof-12743-runtime-stack-callback branch from af340dd to bc7eb46 Compare November 17, 2025 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Involves Datadog core libraries profiling Involves Datadog profiling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants