elastic / elastic/apm-agent-ruby
Sinatra Spy does not set endpoint name if Error inside endpoint
- Dominant language
- Ruby
- Stars
- 173
- Forks
- 151
- Avg merge
- 4d 8h
- Merged PRs (30d)
- 2
Description
## 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
```
Contributor guide
Assessment
This issue has not been assessed yet.