Skip to content

Commit

Permalink
Use new transaction API in sentry-rails
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Nov 20, 2020
1 parent c686a62 commit 8fba220
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
34 changes: 20 additions & 14 deletions sentry-rails/lib/sentry/rails/tracing/abstract_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,31 @@ module Rails
module Tracing
class AbstractSubscriber

def self.subscribe!
raise NotImplementedError
end
class << self
def subscribe!
raise NotImplementedError
end

def self.subscribe_to_event(event_name)
if ::Rails.version.to_i == 5
ActiveSupport::Notifications.subscribe(event_name) do |_, start, finish, _, payload|
next unless Sentry.get_transaction
def subscribe_to_event(event_name)
if ::Rails.version.to_i == 5
ActiveSupport::Notifications.subscribe(event_name) do |_, start, finish, _, payload|
next unless get_current_transaction

duration = finish.to_f - start.to_f
yield(event_name, duration, payload)
end
else
ActiveSupport::Notifications.subscribe(event_name) do |event|
next unless Sentry.get_transaction
duration = finish.to_f - start.to_f
yield(event_name, duration, payload)
end
else
ActiveSupport::Notifications.subscribe(event_name) do |event|
next unless get_current_transaction

yield(event_name, event.duration, event.payload)
yield(event_name, event.duration, event.payload)
end
end
end

def get_current_transaction
Sentry.get_current_scope.get_transaction
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def self.subscribe!
timestamp = Time.now.utc.to_f
start_timestamp = timestamp - duration.to_f

new_span = Sentry.get_transaction.start_child(op: event_name, description: payload[:sql], start_timestamp: start_timestamp, timestamp: timestamp)
new_span = get_current_transaction.start_child(op: event_name, description: payload[:sql], start_timestamp: start_timestamp, timestamp: timestamp)
new_span.set_data(:name, payload[:name])
new_span.set_data(:connection_id, payload[:connection_id])
end
Expand Down

0 comments on commit 8fba220

Please sign in to comment.