sentry-ruby icon indicating copy to clipboard operation
sentry-ruby copied to clipboard

Add AR query time to breadcrumbs

Open sobrinho opened this issue 1 year ago • 4 comments

Describe the idea

We have breadcrumbs with the query like:

{
  name: Employee Pluck,
  sql: SELECT DISTINCT "employees"."person_id" FROM "employees" WHERE "employees"."company_id" IN ('x', 'y', 'z'),
  statement_name: null
}

Would be helpful to have the timing of that query together with the breadcrumb:

{
  name: Employee Pluck,
  sql: SELECT DISTINCT "employees"."person_id" FROM "employees" WHERE "employees"."company_id" IN ('x', 'y', 'z'),
  statement_name: null,
  duration: 5.1234 // ms
}

Why do you think it's beneficial to most of the users

That will help with exceptions that might be caused due to slow endpoints such as graphql timeout middleware, rack-timeout and etc.

Possible implementation

https://github.com/getsentry/sentry-ruby/blob/master/sentry-rails/lib/sentry/rails/breadcrumb/active_support_logger.rb#L14-L18

Could be something like:

crumb = Sentry::Breadcrumb.new(
  data: data,
  category: name,
  timestamp: started.to_i,
  duration: started - finished
)

sobrinho avatar Mar 28 '24 14:03 sobrinho

yep i can add, but also you can probably try out our Performance product and you'll get much more visibility into such things :) https://docs.sentry.io/platforms/ruby/performance/ https://docs.sentry.io/platforms/ruby/performance/instrumentation/automatic-instrumentation/

sl0thentr0py avatar Apr 02 '24 14:04 sl0thentr0py

Indeed but the point here is to track times from a very specific exception.

So, if a Rack::Timeout exception happens for instance, I can see the exception and go straight to the query that took too long to execute.

sobrinho avatar Apr 03 '24 13:04 sobrinho

we connect errors and traces together, so you can neatly go from a particular exception to the span waterfall for that entire request and can see the query immediately.

sl0thentr0py avatar Apr 03 '24 13:04 sl0thentr0py

Every error is traced on the performance? What happens with the sampling in that case?

sobrinho avatar Apr 03 '24 13:04 sobrinho