Questions for improving the AppSignal APM integration with Hanami 2

Hello there :wave: Tom here from AppSignal.com.

We have an Hanami integration for our APM, and I鈥檓 refactoring it so it鈥檚 not/less reliant on monkeypatching Hanami, using Rack middleware and request metadata instead.

I鈥檓 most of the way there, but the only metadata I鈥檓 missing is the name of the Action class to group requests we monitor per Action class.
Is there a way to get the action class instance from the Hanami request object or router somehow?

For example: in Rails there鈥檚 an action_controller.instance key on the request environment we can fetch this information from. A dry monitor event with this information in the payload would also work.

I tried using the router like app.router.recognize("/"), but this doesn鈥檛 return any route metadata like the action class or route name.
I listened to the dry-monitor events for Rack, but this only included timings and response status, which we鈥檒l collect in the middleware. I couldn鈥檛 find any other events that include information about the action.

Here鈥檚 my PR with the work so far on our Ruby gem: Update Hanami to use Rack middleware by tombruijn 路 Pull Request #1113 路 appsignal/appsignal-ruby 路 GitHub
It only has one monkeypatch left in the lib/appsignal/integrations/hanami.rb file to set the action name.

Any help is appreciated!

Yeah, when I was working on NewRelic support for my system I ended up having to do method tracing for actions.

Another way would be nice.

Hi @tombruijn, thank you for checking in here, and thank you for supporting Hanami! :heart:

Your work in improving the APM integration looks great! I鈥檇 love for us to help you out by getting the action name into the rack environment.

I鈥檝e just created this issue here to remind us: Add action name to Rack environment 路 Issue #445 路 hanami/controller 路 GitHub

Right now we鈥檙e focused on preparing Hanami 2.2 for release, which mostly has us modifying other parts of the framework. If we find a chance to sneak this in before 2.2, that鈥檇 be a nice bonus, but otherwise I make sure we take care of this in whatever release comes next.

(And to any hopeful contributors reading this, I鈥檇 welcome PRs to take care of this!)

Thanks again for bringing this to our attention, Tom, and if there鈥檚 anything we can ever do to help AppSignal with Hanami, you know where to find us! :smile:

Hi @timriley,

Thanks for creating the issue to set the action name on the request env. It helps us a lot with creating a better instrumentation! :smile:

Good luck with the 2.2 release!
I鈥檒l let you know if I have any other questions or suggestions.