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’m refactoring it so it’s not/less reliant on monkeypatching Hanami, using Rack middleware and request metadata instead.

I’m most of the way there, but the only metadata I’m 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’s 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’t 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’ll collect in the middleware. I couldn’t find any other events that include information about the action.

Here’s 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’d love for us to help you out by getting the action name into the rack environment.

I’ve just created this issue here to remind us: Add action name to Rack environment · Issue #445 · hanami/controller · GitHub

Right now we’re 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’d 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’d welcome PRs to take care of this!)

Thanks again for bringing this to our attention, Tom, and if there’s 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’ll let you know if I have any other questions or suggestions.