Skip to content

Commit

Permalink
Add example and testing for graphql 1.13
Browse files Browse the repository at this point in the history
  • Loading branch information
toneymathews committed Jul 19, 2022
1 parent ae0e78c commit 7af15b8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions instrumentation/graphql/Appraisals
Expand Up @@ -4,6 +4,10 @@
#
# SPDX-License-Identifier: Apache-2.0

appraise 'graphql-1.13' do
gem 'graphql', '~> 1.13.0'
end

appraise 'graphql-1.11' do
gem 'graphql', '~> 1.11.0'
end
Expand Down
10 changes: 10 additions & 0 deletions instrumentation/graphql/README.md
Expand Up @@ -53,6 +53,16 @@ OpenTelemetry::SDK.configure do |c|
end
```

Tracing can be enabled per request by setting the following keys to `true` within the GraphQL query execution context. This will add spans that provide more detail.

```ruby
query = GraphQL::Query.new(MyAppSchema, 'query { foo }')

query.context.namespace(:opentelemetry)[:enable_platform_field] = true
query.context.namespace(:opentelemetry)[:enable_platform_authorized] = true
query.context.namespace(:opentelemetry)[:enable_platform_resolve_type] = true
```

## Examples

An example of usage can be seen in [`example/graphql.rb`](https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/instrumentation/graphql/example/graphql.rb).
Expand Down
19 changes: 19 additions & 0 deletions instrumentation/graphql/example/graphql.rb
Expand Up @@ -51,3 +51,22 @@ def initialize(id = 1, name = 'bar')
puts "episodes are #{result.inspect}"

result

# Example of enabling tracing for specific API requests based on query execution context

OpenTelemetry::SDK.configure do |c|
c.use('OpenTelemetry::Instrumentation::GraphQL' => {
schemas: [Schema],
enable_platform_field: true,
enable_platform_authorized: true,
enable_platform_resolve_type: true,
})
end

query = GraphQL::Query.new(Schema, '{ episode(episode_id: 5) { name } }')

query.context.namespace(:opentelemetry)[:enable_platform_field] = true
query.context.namespace(:opentelemetry)[:enable_platform_authorized] = true
query.context.namespace(:opentelemetry)[:enable_platform_resolve_type] = true

query.result

0 comments on commit 7af15b8

Please sign in to comment.