从 Ruby 应用程序和 graphql gem 提供的 GraphQL 查询中提取您想要的尽可能多的细节。
Extract as much detail as you want from GraphQL queries, served up from your Ruby app and the graphql gem.
Compatible with the graphql-batch gem, to extract batch-loaded fields resolution timings.
Be sure to read the CHANGELOG to stay updated on feature additions, breaking changes made to this gem.
Add this line to your application's Gemfile:
gem 'graphql-metrics'You can require it with in your code as needed with:
require 'graphql/metrics'Or globally in the Gemfile with:
gem 'graphql-metrics', require: 'graphql/metrics'And then execute:
$ bundleOr install it yourself as:
$ gem install graphql-metricsGet started by defining your own Analyzer, inheriting from GraphQL::Metrics::Analyzer.
The following analyzer demonstrates a simple way to capture commonly used metrics sourced from key parts of your schema
definition, the query document being served, as well as runtime query and resolver timings. In this toy example, all of
this data is simply stored on the GraphQL::Query context, under a namespace to avoid collisions with other analyzers
etc.
What you do with these captured metrics is up to you!
NOTE: If any non-graphql-ruby gem-related exceptions occur in your application during query document
parsing and validation, runtime metrics for queries (like query_duration, etc.) as well as field
resolver timings (like resolver_timings, lazy_resolver_timings) may not be present in the extracted metrics hash,
even if you opt to collect them.
…Add the GraphQL::Metrics plugin to your schema. This opts you in to capturing all static and runtime metrics seen above.
class Schema < GraphQL::Schema
query QueryRoot
mutation MutationRoot
use GraphQL::Metrics, analyzer: SimpleAnalyzer
endIf you don't care to capture field timings metrics, they can be disabled with the capture_field_timings option:
class Schema < GraphQL::Schema
query QueryRoot
mutation MutationRoot
use GraphQL::Metrics, analyzer: SimpleAnalyzer, capture_field_timings: false
endYour analyzer will still be called with query_extracted, field_extracted, but with timings metrics omitted.
argument_extracted will work exactly the same.
And if you want to disable tracing metrics entirely, use the capture_timings option:
class Schema < GraphQL::Schema
query QueryRoot
mutation MutationRoot
use GraphQL::Metrics, analyzer: SimpleAnalyzer, capture_timings: false
endBecause of the structure of graphql-ruby's plugin architecture, it may be difficult to build an intuition around the
order in which methods defined on GraphQL::Metrics::Instrumentation, GraphQL::Metrics::Trace and subclasses of
GraphQL::Metrics::Analyzer run.
Although you ideally will not need to care about these details if you are simply using this gem to gather metrics in your application as intended, here's a breakdown of the order of execution of the methods involved:
When used as instrumentation, an analyzer and tracing, the order of execution is usually:
After checking out the repo, run bin/setup to install dependencies. Then, run bundle exec rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/Shopify/graphql-metrics. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the GraphQL::Metrics project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
暂无开放 Issues,或尚未同步最近议题。