Telemetry-safe error reporting for native extensions
(I'll squash the commits on reviews finish)
What does this PR do?
This PR ensure errors raised from native ext/ code have enough context to be valuable in telemetry.
Motivation:
Because error information sent to telemetry cannot have arbitrary, dynamic data, we must ensure that we are only sending values that are known at gem build time.
Because our fallback is to only report the exception class, this PR adds a telemetry_message to native exceptions, so that their error information is not completely lost.
Change log entry
Yes. Telemetry: Added static error reporting for native extensions.Additional Notes:
There's a follow up PR to reduce code duplication for the datadog_ruby_common.c/h files: https://github.com/DataDog/dd-trace-rb/pull/5088
How to test the change?
Easiest and fastest test it: bundle exec rake clean compile && bundle exec rake spec:profiling
There are more products supported by libdatadog, but at that point, just run CI :)
Benchmarks
Benchmark execution time: 2025-12-01 23:29:10
Comparing candidate commit f92ebb4c08be19d59f7b29f76004f508dd474ad3 in PR branch marcotc/error-logs-remediation-custom-profiler-code with baseline commit ae94edc1bfb4c019405aac090504cecfecbbc510 in branch master.
Found 0 performance improvements and 0 performance regressions! Performance is the same for 44 metrics, 2 unstable metrics.
Typing analysis
This PR does not change typing compared to the base branch.
Thank you for updating Change log entry section :clap:
Visited at: 2025-11-28 00:09:06 UTC
✅ Tests
🎉 All green!
❄️ No new flaky tests detected
🧪 All tests passed
🎯 Code Coverage
• Patch Coverage: 88.20%
• Total Coverage: 95.23% (-0.00%)
View detailed report
🔗 Commit SHA: 976a297 | Docs | Datadog PR Page | Was this helpful? Give us feedback!
The failure in the benchmarks...
+ bundle exec ruby benchmarks/profiling_sample_gvl.rb
Current pid is 3296
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-linux]
Warming up --------------------------------------
profiling - gvl benchmark samples
benchmarks/profiling_sample_gvl.rb:64:in `_native_sample_after_gvl_running': wrong number of arguments (given 3, expected 2) (ArgumentError)
Datadog::Profiling::Collectors::ThreadContext::Testing._native_sample_after_gvl_running(@collector, @target_thread, false)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
from benchmarks/profiling_sample_gvl.rb:64:in `block (2 levels) in run_benchmark'
from (eval at /usr/local/bundle/gems/benchmark-ips-2.14.0/lib/benchmark/ips/job/entry.rb:63):6:in `call_times'
from /usr/local/bundle/gems/benchmark-ips-2.14.0/lib/benchmark/ips/job.rb:285:in `block in run_warmup'
from /usr/local/bundle/gems/benchmark-ips-2.14.0/lib/benchmark/ips/job.rb:268:in `each'
from /usr/local/bundle/gems/benchmark-ips-2.14.0/lib/benchmark/ips/job.rb:268:in `run_warmup'
from /usr/local/bundle/gems/benchmark-ips-2.14.0/lib/benchmark/ips/job.rb:253:in `block in run'
is because the "use the test code from this branch with master" doesn't work if master isn't API-compatible with this branch.
TBH what I've done in the past is just disable the benchmark and re-enable it later, but it's kinda meh workaround. Suggestions welcome :sweat_smile: