Skip to content

Commit

Permalink
Annotate rails transaction_source
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py committed Sep 19, 2022
1 parent fd85d96 commit 545e1a5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
8 changes: 4 additions & 4 deletions sentry-rails/lib/sentry/rails/action_cable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def capture(connection, transaction_name:, extra_context: nil, &block)
Sentry.with_scope do |scope|
scope.set_rack_env(env)
scope.set_context("action_cable", extra_context) if extra_context
scope.set_transaction_name(transaction_name)
transaction = start_transaction(env, scope.transaction_name)
scope.set_transaction_name(transaction_name, source: :view)
transaction = start_transaction(env, scope.transaction_name, scope.transaction_source)
scope.set_span(transaction) if transaction

begin
Expand All @@ -29,11 +29,11 @@ def capture(connection, transaction_name:, extra_context: nil, &block)
end
end

def start_transaction(env, transaction_name)
def start_transaction(env, transaction_name, transaction_source)
sentry_trace = env["HTTP_SENTRY_TRACE"]
baggage = env["HTTP_BAGGAGE"]

options = { name: transaction_name, op: "rails.action_cable".freeze }
options = { name: transaction_name, source: transaction_source, op: "rails.action_cable".freeze }
transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, baggage: baggage, **options) if sentry_trace
Sentry.start_transaction(transaction: transaction, **options)
end
Expand Down
4 changes: 2 additions & 2 deletions sentry-rails/lib/sentry/rails/active_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class << self
def record(job, &block)
Sentry.with_scope do |scope|
begin
scope.set_transaction_name(job.class.name)
scope.set_transaction_name(job.class.name, source: :task)
transaction =
if job.is_a?(::Sentry::SendEventJob)
nil
else
Sentry.start_transaction(name: scope.transaction_name, op: "active_job")
Sentry.start_transaction(name: scope.transaction_name, source: scope.transaction_source, op: "active_job")
end

scope.set_span(transaction) if transaction
Expand Down
9 changes: 1 addition & 8 deletions sentry-rails/lib/sentry/rails/capture_exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ def capture_exception(exception, env)

# the exception will be swallowed by ShowExceptions middleware
return if request.show_exceptions? && !Sentry.configuration.rails.report_rescued_exceptions

current_scope = Sentry.get_current_scope

if original_transaction = env["sentry.original_transaction"]
current_scope.set_transaction_name(original_transaction)
end

Sentry::Rails.capture_exception(exception).tap do |event|
env[ERROR_EVENT_ID_KEY] = event.event_id if event
end
Expand All @@ -41,7 +34,7 @@ def start_transaction(env, scope)
sentry_trace = env["HTTP_SENTRY_TRACE"]
baggage = env["HTTP_BAGGAGE"]

options = { name: scope.transaction_name, op: transaction_op }
options = { name: scope.transaction_name, source: scope.transaction_source, op: transaction_op }

if @assets_regex && scope.transaction_name.match?(@assets_regex)
options.merge!(sampled: false)
Expand Down
2 changes: 1 addition & 1 deletion sentry-rails/lib/sentry/rails/controller_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Rails
module ControllerTransaction
def self.included(base)
base.prepend_before_action do |controller|
Sentry.get_current_scope.set_transaction_name("#{controller.class}##{controller.action_name}")
Sentry.get_current_scope.set_transaction_name("#{controller.class}##{controller.action_name}", source: :view)
end
end
end
Expand Down

0 comments on commit 545e1a5

Please sign in to comment.