Use drivers to instrument Redis client behavior
We currently instrument the Redis gem in gitlab-rails by monkey-patching Redis::Client#call. https://gitlab.com/gitlab-org/gitlab/-/blob/162c664135257c0075d5a9e9b725d564d6cd8843/lib/gitlab/instrumentation/redis.rb
One possible issue with this is not the only entry point into the client, there are also methods like call_loop, call_pipeline, call_pipelined.
Another issue is that monkey-patching this way is global: it applies to all Redis::Client instances. But we connect to multiple Redis servers, and we may want to instrument the corresponding clients separately.
One possible way around this would be to create a custom Redis driver. You can specify the driver when you instantiate the client. All we would have to instrument on the driver would be the read and write methods (and maybe connect). The implementation of the driver could just call out to the regular Redis Ruby driver.
So the benefits here might be:
- Instrument a smaller, low-level part of the gem
- Have varying instrumentation labels per Redis::Client instance