Sha256: d5fea8dbc3721559ad491b61ff6a431d3a72a3b55c952c5552c72eeadb8191bb

Contents?: true

Size: 927 Bytes

Versions: 4

Compression:

Stored size: 927 Bytes

Contents

module Sentry
  module Rack
    class Tracing
      def initialize(app)
        @app = app
      end

      def call(env)
        Sentry.clone_hub_to_current_thread unless Sentry.get_current_hub

        if Sentry.configuration.traces_sample_rate.to_f == 0.0
          return @app.call(env)
        end

        Sentry.with_scope do |scope|
          scope.clear_breadcrumbs
          scope.set_transaction_name(env["PATH_INFO"]) if env["PATH_INFO"]
          span = Sentry.start_transaction(name: scope.transaction_name, op: "rack.request")
          scope.set_span(span)

          begin
            response = @app.call(env)
          rescue
            finish_span(span, 500)
            raise
          end

          finish_span(span, response[0])
          response
        end
      end

      def finish_span(span, status_code)
        span.set_http_status(status_code)
        span.finish
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sentry-ruby-4.0.1 lib/sentry/rack/tracing.rb
sentry-ruby-4.0.0 lib/sentry/rack/tracing.rb
sentry-ruby-0.3.0 lib/sentry/rack/tracing.rb
sentry-ruby-0.2.0 lib/sentry/rack/tracing.rb