From 545e1a5f4427423d946bbe1659f13e86e515e1b6 Mon Sep 17 00:00:00 2001 From: Neel Shah Date: Mon, 19 Sep 2022 16:31:57 +0100 Subject: [PATCH] Annotate rails transaction_source --- sentry-rails/lib/sentry/rails/action_cable.rb | 8 ++++---- sentry-rails/lib/sentry/rails/active_job.rb | 4 ++-- sentry-rails/lib/sentry/rails/capture_exceptions.rb | 9 +-------- sentry-rails/lib/sentry/rails/controller_transaction.rb | 2 +- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/sentry-rails/lib/sentry/rails/action_cable.rb b/sentry-rails/lib/sentry/rails/action_cable.rb index da15e17ae..fa06e870e 100644 --- a/sentry-rails/lib/sentry/rails/action_cable.rb +++ b/sentry-rails/lib/sentry/rails/action_cable.rb @@ -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 @@ -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 diff --git a/sentry-rails/lib/sentry/rails/active_job.rb b/sentry-rails/lib/sentry/rails/active_job.rb index 171f997e1..9e732183f 100644 --- a/sentry-rails/lib/sentry/rails/active_job.rb +++ b/sentry-rails/lib/sentry/rails/active_job.rb @@ -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 diff --git a/sentry-rails/lib/sentry/rails/capture_exceptions.rb b/sentry-rails/lib/sentry/rails/capture_exceptions.rb index 47c6ce4d1..6228c6385 100644 --- a/sentry-rails/lib/sentry/rails/capture_exceptions.rb +++ b/sentry-rails/lib/sentry/rails/capture_exceptions.rb @@ -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 @@ -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) diff --git a/sentry-rails/lib/sentry/rails/controller_transaction.rb b/sentry-rails/lib/sentry/rails/controller_transaction.rb index 5b78aa759..c62cc4591 100644 --- a/sentry-rails/lib/sentry/rails/controller_transaction.rb +++ b/sentry-rails/lib/sentry/rails/controller_transaction.rb @@ -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