Skip to content

Commit

Permalink
Add "db." prefix for ActiveRecord Sentry traces
Browse files Browse the repository at this point in the history
This incorporates a change from `sentry-ruby` to add the `db.` prefix to
recorded ActiveRecord traces. This enables the "Slow DB ops" dashboard in
Sentry.

flag=none

test plan:
- verify SQL traces are recorded like normal
- verify they populate into the "Slow DB ops" dashboard in Sentry

Change-Id: I530a20324913036fa9560b4df2b4845f87e91573
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/287982
Reviewed-by: Andrea Cirulli <[email protected]>
Tested-by: Service Cloud Jenkins <[email protected]>
QA-Review: Isaac Moore <[email protected]>
Product-Review: Isaac Moore <[email protected]>
  • Loading branch information
rmsy committed Mar 25, 2022
1 parent 4b6af0d commit 5b1e0d1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/sentry_extensions/tracing/active_record_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ module Tracing
class ActiveRecordSubscriber < Sentry::Rails::Tracing::AbstractSubscriber
SQL_REGEX = /^(\d+::)?(.*)/m.freeze
EVENT_NAMES = ["sql.active_record"].freeze
SPAN_PREFIX = "db."
EXCLUDED_EVENTS = %w[SCHEMA TRANSACTION].freeze

def self.subscribe!
subscribe_to_event(EVENT_NAMES) do |event_name, duration, payload|
next if EXCLUDED_EVENTS.include? payload[:name]

record_on_current_span(op: event_name, start_timestamp: payload[Sentry::Rails::Tracing::START_TIMESTAMP_NAME], description: payload[:sql], duration: duration) do |span|
record_on_current_span(op: SPAN_PREFIX + event_name, start_timestamp: payload[Sentry::Rails::Tracing::START_TIMESTAMP_NAME], description: payload[:sql], duration: duration) do |span|
begin
if payload[:sql]
# $1 is the Switchman shard prefix (which PgQuery doesn't understand), $2 is the standard SQL statement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def perform_transaction(sampled: true)
expect(transaction[:spans].count).to eq(1)

span = transaction[:spans][0]
expect(span[:op]).to eq("sql.active_record")
expect(span[:op]).to eq("db.sql.active_record")
expect(span[:description]).to eq('SELECT "users".* FROM "public"."users"')
expect(span[:trace_id]).to eq(transaction.dig(:contexts, :trace, :trace_id))
end
Expand Down

0 comments on commit 5b1e0d1

Please sign in to comment.