Closed ryansouza closed 10 months ago
Instrumentation is so application specific that I would like to avoid the library to have any opinion on that.
Allowing the user to pass a block that yield into the new_connection
just make sense in general for flexibility.
I'm wondering if we do:
client = Acme::Client.new do {|conn| conn.something }
As user, I would expect block passed to initialize to be called only once, and right away, but in practice this block would get called multiple time, possibly at a later time, because we need different type of connections.
What about passing the configuration as a lambda?
client = Acme::Client.new(..., connection_block: lambda {|conn| conn.something })
Its the same but from a dev ux it just seem less surprising.
For instrumenting, at Shopify we use the statsd-instrument metaprogramming module.
The gist of it would be something like
module AcmeInstrumentation
def order(*)
MetricThing.count("acme-client.order")
MetricThing.measure("acme-client.order") { super }
end
end
Acme::Client.include(AcmeInstrumentation)
Does that help?
I'm fine wrapping the methods that make requests to instrument them like that 👍 My thought was an integrated approach automatically pick up changes to the gem/acme flow but it's feeling pretty settled with V2. It also misses out on access to the response, but I can categorize them as success/failure using a rescue.
I agree with the connection block lambda, I'll PR that when I get to integrating a logger 👍
In the newer version you have more control over the client. I think this should solve those use cases.
I would like to be able to track metrics around and log the http requests being made. Currently brainstorming something like the following pseudo-code, does it seem reasonable and worth me continuing with a PR?