open-telemetry/opentelemetry-ruby-contrib

Caught AR validation errors are resulting in `error` spans

開放

#1,459 建立於 2025年3月27日

 (6 則留言) (0 個反應) (1 位負責人)Ruby (252 個分叉)auto 404
help wantedinstrumentationinstrumentation-active_recordkeep

倉庫指標

星標
 (135 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

Our app uses ActiveRecord validations (example), and uses some create! calls in the code (example controller action, and create!).

Then a record fails the validation, an exception is thrown, and is then caught and returned as an HTTP error, with the failed validations in the body (here).

This causes the OTEL instrumentation to generate traces where the User.create! span has an error attached, but the root span does not:

Image

This causes tools like Sentry or Datadog to create a new entry in their error tracking system, even if everything is handled in the app and the error is not actionable.

Using exceptions for such control flow is a common pattern in Rails, and as an application developer or operator, I expect that errors are things that needs to be reviewed and fixed, which is not the case here.

Note: there is a relevant discussion in the Slack channel

Possible discussed solutions are marking some exceptions (such as ActiveRecord::RecordInvalid or ActiveRecord:: RecordNotFound) as non-exceptional in the AR Validations instrumentation, or having a setting to prevent those spans to be errors entirely, allowing the app developer to explicitly indicate that those exceptions are handled correctly by the app (and if thats not the case, the root span should be an error anyway).

貢獻者指南