Skip to content

Sinatra Spy does not set endpoint name if Error inside endpoint #1561

@bjorn-ali-goransson

Description

@bjorn-ali-goransson

Describe the bug

Transaction name is "Rack" (because of Rack Middleware) if an error happens inside the endpoint.

Steps to reproduce

Create Sinatra application, throw an error inside the endpoint like:

      def hello
        raise MyError
      end

Expected behavior

Sinatra Spy should update transaction name even if Error occurs

Current code:

    class SinatraSpy
      # @api private
      module Ext
        def dispatch!(*args, &block)
          super(*args, &block).tap do # <------- Error occurs inside here! (sometimes)
            next unless (transaction = ElasticAPM.current_transaction)
            next unless (route = env['sinatra.route'])

            transaction.name = route # <----------- this should get called regardless!
          end
        end

My suggestion:

    class SinatraSpy
      # @api private
      module Ext
        def dispatch!(*args, &block)
            begin
              super(*args, &block)
            ensure
              if (transaction = ElasticAPM.current_transaction) && (route = env['sinatra.route'])
                transaction.name = route
              end
            end
        end

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions