Skip to content

Cache hit instrumentation #124

@danielhartnell

Description

@danielhartnell

Thanks for creating this gem. We've found it quite useful.

ActiveSupport::Notifications has been okay for tracking cache hits (subscribing to /cache_read/). I would find it useful to have access to attributes like operation_name or the field name for our observability.

Do you have any suggestions for achieving this?

My first thought was to try to include plaintext strings in the cache key which I could extract from the cache key in the ActiveSupport::Notifications payload. If I recall correctly, object_cache_key worked but I wasn't sure if I was going to break something by using it for this purpose. It would also be nice not to have to explicitly define it on each field we want to cache.

Do you think the GraphQL gem's tracing might be suitable here?

I see how I can implement one of the Trace methods like execute_query within my own app:

https://graphql-ruby.org/api-doc/2.4.8/GraphQL/Tracing/Trace

And I see how I could add something which would identify if there was a cache hit or miss here:

https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/blob/master/lib/graphql/fragment_cache/fragment.rb

I'm not sure how I would connect those two though. Is there some sort of query metadata that I could access? It would be nice to find a generic solution and I'd be happy to open a PR with any changes here if we find something you like.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions