lib/opentelemetry/instrumentation/graphql/instrumentation.rb in opentelemetry-instrumentation-graphql-0.14.0 vs lib/opentelemetry/instrumentation/graphql/instrumentation.rb in opentelemetry-instrumentation-graphql-0.15.0

- old
+ new

@@ -9,10 +9,19 @@ module OpenTelemetry module Instrumentation module GraphQL # The Instrumentation class contains logic to detect and install the GraphQL instrumentation class Instrumentation < OpenTelemetry::Instrumentation::Base + install do |config| + require_dependencies + install_tracer(config) + end + + present do + defined?(::GraphQL) + end + ## Supported configuration keys for the install config hash: # # The enable_platform_field key expects a boolean value, # and enables the tracing of "execute_field" and "execute_field_lazy". # @@ -23,26 +32,22 @@ # and enables the tracing of "resolve_type" and "resolve_type_lazy". # # The schemas key expects an array of Schemas, and is used to specify # which schemas are to be instrumented. If this value is not supplied # the default behaviour is to instrument all schemas. - install do |config| - require_dependencies - install_tracer(config) - end + option :schemas, default: [], validate: :array + option :enable_platform_field, default: false, validate: :boolean + option :enable_platform_authorized, default: false, validate: :boolean + option :enable_platform_resolve_type, default: false, validate: :boolean - present do - defined?(::GraphQL) - end - private def require_dependencies require_relative 'tracers/graphql_tracer' end def install_tracer(config = {}) - if config[:schemas].nil? || config[:schemas].empty? + if config[:schemas].empty? ::GraphQL::Schema.tracer(Tracers::GraphQLTracer.new) else config[:schemas].each do |schema| schema.use(Tracers::GraphQLTracer) rescue StandardError => e