Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update analyzer option #88

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ Compatible with the [`graphql-batch` gem](https://github.com/Shopify/graphql-bat

Be sure to read the [CHANGELOG](CHANGELOG.md) to stay updated on feature additions, breaking changes made to this gem.

**NOTE**: Not tested with graphql-ruby's multiplexing feature. Metrics may not
be accurate if you execute multiple operations at once.

## Installation

Add this line to your application's Gemfile:
Expand Down Expand Up @@ -42,7 +39,7 @@ Get started by defining your own Analyzer, inheriting from `GraphQL::Metrics::An

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
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!
Expand Down Expand Up @@ -176,8 +173,7 @@ schema.

#### Metrics that are captured for arguments for fields and directives

Let's have a query example

Example query:
```graphql
query PostDetails($postId: ID!, $commentsTags: [String!] = null, $val: Int!) @customDirective(val: $val) {
post(id: $postId) {
Expand Down Expand Up @@ -236,14 +232,14 @@ These are some of the arguments that are extracted

### Make use of your analyzer

Add the `GraphQL::Metrics` plugins to your schema. This opts you in to capturing all static and runtime metrics seen above.
Add the `GraphQL::Metrics` plugin to your schema. This opts you in to capturing all static and runtime metrics seen above.

```ruby
class Schema < GraphQL::Schema
query QueryRoot
mutation MutationRoot

use GraphQL::Metrics
use GraphQL::Metrics, analyzer: SimpleAnalyzer
end
```

Expand All @@ -256,7 +252,7 @@ class Schema < GraphQL::Schema
query QueryRoot
mutation MutationRoot

use GraphQL::Metrics, capture_field_timings: false
use GraphQL::Metrics, analyzer: SimpleAnalyzer, capture_field_timings: false
end
```

Expand All @@ -270,7 +266,7 @@ class Schema < GraphQL::Schema
query QueryRoot
mutation MutationRoot

use GraphQL::Metrics, capture_timings: false
use GraphQL::Metrics, analyzer: SimpleAnalyzer, capture_timings: false
end
```

Expand Down
4 changes: 2 additions & 2 deletions lib/graphql/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def self.time

def self.use(
schema_defn,
analyzer_class:,
analyzer:,
tracer: GraphQL::Metrics::Trace,
capture_timings: nil,
capture_field_timings: nil,
Expand All @@ -66,7 +66,7 @@ def self.use(

schema_defn.trace_with(GraphQL::Metrics::Instrumentation, capture_field_timings: capture_field_timings)
schema_defn.trace_with(tracer, mode: trace_mode) if capture_timings
schema_defn.query_analyzer(analyzer_class)
schema_defn.query_analyzer(analyzer)
end
end
end
6 changes: 3 additions & 3 deletions test/unit/graphql/metrics/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class SchemaWithFullMetrics < GraphQL::Schema
directive CustomDirective

use GraphQL::Batch
use GraphQL::Metrics, analyzer_class: SimpleAnalyzer
use GraphQL::Metrics, analyzer: SimpleAnalyzer

trace_with TestTrace

Expand All @@ -107,15 +107,15 @@ class SchemaWithoutFieldTimingMetrics < GraphQL::Schema
mutation MutationRoot

use GraphQL::Batch
use GraphQL::Metrics, analyzer_class: SimpleAnalyzer, capture_field_timings: false
use GraphQL::Metrics, analyzer: SimpleAnalyzer, capture_field_timings: false
end

class SchemaWithoutTimingMetrics < GraphQL::Schema
query QueryRoot
mutation MutationRoot

use GraphQL::Batch
use GraphQL::Metrics, analyzer_class: SimpleAnalyzer, capture_timings: false
use GraphQL::Metrics, analyzer: SimpleAnalyzer, capture_timings: false
end

test "it doesn't short-circuit other traces" do
Expand Down
Loading