Skip to content

Commit

Permalink
Merge b0d2aa9 into 53deb6e
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 authored Oct 2, 2021
2 parents 53deb6e + b0d2aa9 commit 5eb4686
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
### Miscellaneous

- Start Testing Against Rails 7.0 [#1581](https://github.com/getsentry/sentry-ruby/pull/1581)
- Tracing subscribers should be multi-event based [#1587](https://github.com/getsentry/sentry-ruby/pull/1587)

## 4.7.3

Expand Down
3 changes: 2 additions & 1 deletion sentry-rails/lib/sentry/rails/tracing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def self.subscribe_tracing_events

subscribers.each do |subscriber|
subscriber.subscribe!
subscribed_tracing_events << subscriber::EVENT_NAME
@subscribed_tracing_events ||= []
@subscribed_tracing_events += subscriber::EVENT_NAMES
end

@subscribed = true
Expand Down
30 changes: 18 additions & 12 deletions sentry-rails/lib/sentry/rails/tracing/abstract_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,28 @@ def subscribe!
end

def unsubscribe!
ActiveSupport::Notifications.unsubscribe(self::EVENT_NAME)
ActiveSupport::Notifications.unsubscribe(*self::EVENT_NAMES)
end

def subscribe_to_event(event_name)
if ::Rails.version.to_i == 5
ActiveSupport::Notifications.subscribe(event_name) do |*args|
next unless Tracing.get_current_transaction
if ::Rails.version.to_i == 5
def subscribe_to_event(event_names)
event_names.each do |event_name|
ActiveSupport::Notifications.subscribe(event_name) do |*args|
next unless Tracing.get_current_transaction

event = ActiveSupport::Notifications::Event.new(*args)
yield(event_name, event.duration, event.payload)
event = ActiveSupport::Notifications::Event.new(*args)
yield(event_name, event.duration, event.payload)
end
end
else
ActiveSupport::Notifications.subscribe(event_name) do |event|
next unless Tracing.get_current_transaction

yield(event_name, event.duration, event.payload)
end
else
def subscribe_to_event(event_names)
event_names.each do |event_name|
ActiveSupport::Notifications.subscribe(event_name) do |event|
next unless Tracing.get_current_transaction

yield(event_name, event.duration, event.payload)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ module Tracing
class ActionControllerSubscriber < AbstractSubscriber
extend InstrumentPayloadCleanupHelper

EVENT_NAME = "process_action.action_controller".freeze
EVENT_NAMES = ["process_action.action_controller"].freeze

def self.subscribe!
subscribe_to_event(EVENT_NAME) do |event_name, duration, payload|
subscribe_to_event(EVENT_NAMES) do |event_name, duration, payload|
controller = payload[:controller]
action = payload[:action]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ module Sentry
module Rails
module Tracing
class ActionViewSubscriber < AbstractSubscriber
EVENT_NAME = "render_template.action_view".freeze
EVENT_NAMES = ["render_template.action_view"].freeze

def self.subscribe!
subscribe_to_event(EVENT_NAME) do |event_name, duration, payload|
subscribe_to_event(EVENT_NAMES) do |event_name, duration, payload|
record_on_current_span(op: event_name, start_timestamp: payload[START_TIMESTAMP_NAME], description: payload[:identifier], duration: duration)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ module Sentry
module Rails
module Tracing
class ActiveRecordSubscriber < AbstractSubscriber
EVENT_NAME = "sql.active_record".freeze
EVENT_NAMES = ["sql.active_record"].freeze
EXCLUDED_EVENTS = ["SCHEMA", "TRANSACTION"].freeze

def self.subscribe!
subscribe_to_event(EVENT_NAME) do |event_name, duration, payload|
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[START_TIMESTAMP_NAME], description: payload[:sql], duration: duration) do |span|
Expand Down

0 comments on commit 5eb4686

Please sign in to comment.