File: controller_transaction.rb

package info (click to toggle)
ruby-sentry-rails 5.18.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 232 kB
  • sloc: ruby: 1,035; makefile: 7; sh: 4
file content (39 lines) | stat: -rw-r--r-- 1,153 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module Sentry
  module Rails
    module ControllerTransaction
      SPAN_ORIGIN = 'auto.view.rails'.freeze

      def self.included(base)
        base.prepend_around_action(:sentry_around_action)
      end

      private

      def sentry_around_action
        if Sentry.initialized?
          transaction_name = "#{self.class}##{action_name}"
          Sentry.get_current_scope.set_transaction_name(transaction_name, source: :view)
          Sentry.with_child_span(op: "view.process_action.action_controller", description: transaction_name, origin: SPAN_ORIGIN) do |child_span|
            if child_span
              begin
                result = yield
              ensure
                child_span.set_http_status(response.status)
                child_span.set_data(:format, request.format)
                child_span.set_data(:method, request.method)
                child_span.set_data(:path, request.path)
                child_span.set_data(:params, request.params)
              end

              result
            else
              yield
            end
          end
        else
          yield
        end
      end
    end
  end
end