Skip to content

Fix raise_error() and grab_gvl_and_raise() to use rb_vsprintf() so PRIsVALUE works#5857

Merged
eregon merged 4 commits into
masterfrom
fix-raise_error-helper
Jun 3, 2026
Merged

Fix raise_error() and grab_gvl_and_raise() to use rb_vsprintf() so PRIsVALUE works#5857
eregon merged 4 commits into
masterfrom
fix-raise_error-helper

Conversation

@eregon

@eregon eregon commented Jun 3, 2026

Copy link
Copy Markdown
Member
  • So raise_error(rb_eRuntimeError, "foo %"PRIsVALUE" bar", some_ruby_object) calls #to_s and doesn't print an integer.
    (or "%+"PRIsVALUE which calls #inspect and not print "+123")
  • Pass the va_list through rb_thread_call_with_gvl and call rb_vsprintf()
    inside the callback where the GVL is held (rb_vsprintf allocates Ruby
    objects). This is safe because rb_thread_call_with_gvl is synchronous so
    the parent stack frame (where the va_list lives) is still alive.

What does this PR do?
^

Motivation:
Correctness and useful error messages.

Change log entry

Yes. Fix some exception messages which were not formatted correctly.

Additional Notes:

How to test the change?

@eregon
eregon requested review from a team as code owners June 3, 2026 14:57
@dd-octo-sts dd-octo-sts Bot added the profiling Involves Datadog profiling label Jun 3, 2026
@datadog-official

datadog-official Bot commented Jun 3, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 97.08% (-0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 133e02e | Docs | Datadog PR Page | Give us feedback!

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

Copy link
Copy Markdown

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.

Reviewed commit: cfcfb720c1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread ext/datadog_profiling_native_extension/datadog_ruby_common.c
Comment thread ext/datadog_profiling_native_extension/ruby_helpers.c Outdated
@eregon
eregon force-pushed the fix-raise_error-helper branch 2 times, most recently from 6f6e08b to 2ec7ba2 Compare June 3, 2026 15:22

@ivoanjo ivoanjo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 LGTM, great catch

Comment thread ext/datadog_profiling_native_extension/ruby_helpers.c Outdated
@pr-commenter

pr-commenter Bot commented Jun 3, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-06-03 19:48:58

Comparing candidate commit 133e02e in PR branch fix-raise_error-helper with baseline commit ef09ce5 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 45 metrics, 1 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

eregon and others added 3 commits June 3, 2026 21:22
…IsVALUE works

* So `raise_error(rb_eRuntimeError, "foo %"PRIsVALUE" bar", some_ruby_object)` calls #to_s and doesn't print an integer.
  (or `"%+"PRIsVALUE` which calls #inspect and not print "+123")
* Pass the va_list through rb_thread_call_with_gvl and call rb_vsprintf()
  inside the callback where the GVL is held (rb_vsprintf allocates Ruby
  objects). This is safe because rb_thread_call_with_gvl is synchronous so
  the parent stack frame (where the va_list lives) is still alive.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Now that rb_vsprintf() produces Ruby strings directly, there is no
fixed-size C buffer limiting the message length. The artificial 255-char
cap is no longer needed.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Test raise_error() via _native_raise_error_value_arg and also through
the otel_context_enabled production code path in ThreadContext.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@eregon
eregon force-pushed the fix-raise_error-helper branch from 074e7dc to 133e02e Compare June 3, 2026 19:23
@eregon
eregon enabled auto-merge June 3, 2026 19:28
@eregon
eregon merged commit 1c780c6 into master Jun 3, 2026
590 checks passed
@eregon
eregon deleted the fix-raise_error-helper branch June 3, 2026 19:51
@dd-octo-sts dd-octo-sts Bot added this to the 2.36.0 milestone Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

profiling Involves Datadog profiling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants