dd-trace-rb
dd-trace-rb copied to clipboard
feat: add record_exception in the datadog api
What does this PR do? This PR adds a record_exception call in the tracer API. It mimics the behavior of the OTEL one for which you can find the documentation here: https://opentelemetry.io/docs/specs/otel/trace/exceptions/
Motivation: Some customers using Sentry complained they were not capable of recording an exception. It appears that if they are using the OTEL api from our tracer, they can. However, as we want to be a competitor to Sentry, I found that it is not a good solution as it is simpler to use this capability directly from our tracer. In addition the feature is easy to emplement
Change log entry
Yes. Record an exception through span events with the record_exceptioncall.
How to test the change?
- Tests we added in the span_operation spec
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 97.76%. Comparing base (
6a04b2f) to head (38be961).
Additional details and impacted files
@@ Coverage Diff @@
## master #4567 +/- ##
=======================================
Coverage 97.76% 97.76%
=======================================
Files 1404 1404
Lines 86173 86220 +47
Branches 4354 4356 +2
=======================================
+ Hits 84247 84295 +48
+ Misses 1926 1925 -1
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Datadog Report
Branch report: dubloom/record-exception
Commit report: a58f267
Test service: dd-trace-rb
:x: 4 Failed (0 Known Flaky), 20386 Passed, 1366 Skipped, 3m 41.29s Total Time
:x: Failed Tests (4)
-
Datadog::OpenTelemetry with Datadog TraceProvider #record_exception attributes is nil sets records an exception event and sets span error tags using the Exception object-rspec- DetailsExpand for error
o implicit conversion of nil into Hash ailure/Error: event_attributes.merge!(attributes) ypeError: no implicit conversion of nil into Hash /lib/datadog/tracing/span_operation.rb:300:in \`merge!' /lib/datadog/tracing/span_operation.rb:300:in \`record_exception' /lib/datadog/opentelemetry/sdk/trace/span.rb:31:in \`record_exception' /spec/datadog/opentelemetry_spec.rb:611:in \`block (4 levels) in <top (required)>' .. -
Datadog::OpenTelemetry with Datadog TraceProvider #record_exception attributes is {} sets records an exception event and sets span error tags using the Exception object-rspec- DetailsExpand for error
xpected Span with error message nil to have error message "Error" ailure/Error: expect(span).to have_error_message('Error') expected Span with error message nil to have error message "Error" /spec/datadog/opentelemetry_spec.rb:637:in \`block (6 levels) in <top (required)>' /spec/spec_helper.rb:261:in \`block (2 levels) in <top (required)>' /spec/spec_helper.rb:146:in \`block (2 levels) in <top (required)>' usr/local/bundle/gems/webmock-3.13.0/lib/webmock/rspec.rb:37:in \`block (2 levels) in <top (required)>' usr/local/bundle/gems/rspec-wait-0.0.9/lib/rspec/wait.rb:46:in \`block (2 levels) in <top (required)>' -
Datadog::OpenTelemetry with Datadog TraceProvider #record_exception with attributes containing exception stacktrace, type and message sets records an exception event and sets span error tags using the attributes hash-rspec- DetailsExpand for error
xpected Span with error message nil to have error message "NewError" ailure/Error: expect(span).to have_error_message('NewError') expected Span with error message nil to have error message "NewError" /spec/datadog/opentelemetry_spec.rb:684:in \`block (5 levels) in <top (required)>' /spec/spec_helper.rb:261:in \`block (2 levels) in <top (required)>' /spec/spec_helper.rb:146:in \`block (2 levels) in <top (required)>' usr/local/bundle/gems/webmock-3.13.0/lib/webmock/rspec.rb:37:in \`block (2 levels) in <top (required)>' usr/local/bundle/gems/rspec-wait-0.0.9/lib/rspec/wait.rb:46:in \`block (2 levels) in <top (required)>' -
Datadog::OpenTelemetry with Datadog TraceProvider #record_exception with attributes containing nil values sets records an exception event and sets span error tags using the Exception object-rspec- DetailsExpand for error
xpected Span with error message nil to have error message "Error" ailure/Error: expect(span).to have_error_message('Error') expected Span with error message nil to have error message "Error" /spec/datadog/opentelemetry_spec.rb:652:in \`block (5 levels) in <top (required)>' /spec/spec_helper.rb:261:in \`block (2 levels) in <top (required)>' /spec/spec_helper.rb:146:in \`block (2 levels) in <top (required)>' usr/local/bundle/gems/webmock-3.13.0/lib/webmock/rspec.rb:37:in \`block (2 levels) in <top (required)>' usr/local/bundle/gems/rspec-wait-0.0.9/lib/rspec/wait.rb:46:in \`block (2 levels) in <top (required)>'
Benchmarks
Benchmark execution time: 2025-04-10 15:15:32
Comparing candidate commit a58f267004cebafc68a5b0dbd26252c55f018722 in PR branch dubloom/record-exception with baseline commit ed683926d2f10b0969d30660099c23be7b756834 in branch master.
Found 0 performance improvements and 1 performance regressions! Performance is the same for 30 metrics, 2 unstable metrics.
scenario:profiler - gvl benchmark samples
- 🟥
throughput[-772.394op/s; -763.606op/s] or [-6.627%; -6.552%]