Count number of external requests in Absinthe

Hi everyone.

We are using Absinthe to provide a GraphQL API. The absinthe service is using HTTP calls to resolve fields. There is a Rails application that is a source of the data.

To get a better visibility into the external calls, we would like to count in the absinthe service the number of external calls made and return it as a header. Also to log this number it at the end of the request.

What would be the best way how to approach this?

So far the idea is to start an Agent somewhere in Plug middleware for every incoming request. Then before a request to Rails during resolutions, we would increment the value.

Hello.
Why do you need this number in header? Only for debugging purposes?

Yes, debugging mostly.

This sounds like an ideal use case for :telemetry. Have a wrapping module around your external calls, and have each call emit a telemetry event.

1 Like

I thought about telemetry as well. But how would I collect telemetry events made during only this request to sum them up?

Sorry, I didn’t read the whole post clearly and missed the whole bit where this is part of the response to an individual request. I think your agent solution works, as would probably using the process dictionary, although with the latter you’d need to be thoughtful about any intermediary processes you spawn.

1 Like