From 16e06889489b3cddf8c9736052a0ce0bd9632793 Mon Sep 17 00:00:00 2001 From: DmitryTsepelev Date: Mon, 10 Apr 2023 10:46:11 +0300 Subject: [PATCH] Add query to cache_hit trace event --- CHANGELOG.md | 3 +++ .../persisted_queries/store_adapters/base_store_adapter.rb | 7 +++++-- spec/graphql/persisted_queries/schema_patch_spec.rb | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a41804..93f7cab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## master +- [PR#64](https://github.com/DmitryTsepelev/graphql-ruby-persisted_queries/pull/64) +Add query to cache_hit trace event ([@DmitryTsepelev][]) + ## 1.7.0 (2023-02-02) - [PR#62](https://github.com/DmitryTsepelev/graphql-ruby-persisted_queries/pull/62) diff --git a/lib/graphql/persisted_queries/store_adapters/base_store_adapter.rb b/lib/graphql/persisted_queries/store_adapters/base_store_adapter.rb index 9fce5ba..b5b31d0 100644 --- a/lib/graphql/persisted_queries/store_adapters/base_store_adapter.rb +++ b/lib/graphql/persisted_queries/store_adapters/base_store_adapter.rb @@ -17,8 +17,11 @@ def fetch_query(hash, options = {}) key = build_key(hash, compiled_query) fetch(key).tap do |result| - event = result ? "cache_hit" : "cache_miss" - trace("fetch_query.#{event}", adapter: @name) + if result + trace("fetch_query.cache_hit", adapter: @name, query: result) + else + trace("fetch_query.cache_miss", adapter: @name) + end end end diff --git a/spec/graphql/persisted_queries/schema_patch_spec.rb b/spec/graphql/persisted_queries/schema_patch_spec.rb index 2f57e3d..f7b44ca 100644 --- a/spec/graphql/persisted_queries/schema_patch_spec.rb +++ b/spec/graphql/persisted_queries/schema_patch_spec.rb @@ -79,7 +79,7 @@ def perform_request(with_tracer: false, with_query: true) perform_request(with_tracer: true) perform_request(with_tracer: true, with_query: false) events = tracer.events["persisted_queries.fetch_query.cache_hit"] - expect(events).to eq([{ metadata: { adapter: :memory }, result: nil }]) + expect(events).to eq([{ metadata: { adapter: :memory, query: query }, result: nil }]) end end