Skip to content

Commit

Permalink
Add query to cache_hit trace event
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryTsepelev committed Apr 10, 2023
1 parent 876a39b commit 16e0688
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/graphql/persisted_queries/schema_patch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 16e0688

Please sign in to comment.