From 7af15b87bb4d2b3a6fb469e4075097373fb7d994 Mon Sep 17 00:00:00 2001 From: Toney Mathews Date: Tue, 19 Jul 2022 08:46:13 -0400 Subject: [PATCH] Add example and testing for graphql 1.13 --- instrumentation/graphql/Appraisals | 4 ++++ instrumentation/graphql/README.md | 10 ++++++++++ instrumentation/graphql/example/graphql.rb | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/instrumentation/graphql/Appraisals b/instrumentation/graphql/Appraisals index 24efd5c12..b74a9806c 100644 --- a/instrumentation/graphql/Appraisals +++ b/instrumentation/graphql/Appraisals @@ -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 diff --git a/instrumentation/graphql/README.md b/instrumentation/graphql/README.md index c10448ae3..257c6c890 100644 --- a/instrumentation/graphql/README.md +++ b/instrumentation/graphql/README.md @@ -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). diff --git a/instrumentation/graphql/example/graphql.rb b/instrumentation/graphql/example/graphql.rb index 54ab33a94..537ac3a8a 100644 --- a/instrumentation/graphql/example/graphql.rb +++ b/instrumentation/graphql/example/graphql.rb @@ -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 \ No newline at end of file