Class: GraphQL::Tracing::AppOpticsTracing

Inherits:
PlatformTracing show all
Defined in:
lib/graphql/tracing/appoptics_tracing.rb

Overview

This class uses the AppopticsAPM SDK from the appoptics_apm gem to create traces for GraphQL.

There are 4 configurations available. They can be set in the appoptics_apm config file or in code. Please see: https://docs.appoptics.com/kb/apm_tracing/ruby/configure

AppOpticsAPM::Config[:graphql][:enabled] = true|false
AppOpticsAPM::Config[:graphql][:transaction_name]  = true|false
AppOpticsAPM::Config[:graphql][:sanitize_query] = true|false
AppOpticsAPM::Config[:graphql][:remove_comments] = true|false

Constant Summary collapse

PREP_KEYS =

These GraphQL events will show up as 'graphql.prep' spans

['lex', 'parse', 'validate', 'analyze_query', 'analyze_multiplex'].freeze
EXEC_KEYS =

These GraphQL events will show up as 'graphql.execute' spans

['execute_multiplex', 'execute_query', 'execute_query_lazy'].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PlatformTracing

#initialize, #trace, use

Constructor Details

This class inherits a constructor from GraphQL::Tracing::PlatformTracing

Class Method Details

.versionObject

During auto-instrumentation this version of AppOpticsTracing is compared with the version provided in the appoptics_apm gem, so that the newer version of the class can be used



29
30
31
# File 'lib/graphql/tracing/appoptics_tracing.rb', line 29

def self.version
  Gem::Version.new('1.0.0')
end

Instance Method Details

#platform_authorized_key(type) ⇒ Object



63
64
65
# File 'lib/graphql/tracing/appoptics_tracing.rb', line 63

def platform_authorized_key(type)
  "graphql.authorized.#{type.graphql_name}"
end

#platform_field_key(type, field) ⇒ Object



59
60
61
# File 'lib/graphql/tracing/appoptics_tracing.rb', line 59

def platform_field_key(type, field)
  "graphql.#{type.graphql_name}.#{field.graphql_name}"
end

#platform_resolve_type_key(type) ⇒ Object



67
68
69
# File 'lib/graphql/tracing/appoptics_tracing.rb', line 67

def platform_resolve_type_key(type)
  "graphql.resolve_type.#{type.graphql_name}"
end

#platform_trace(platform_key, _key, data) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/graphql/tracing/appoptics_tracing.rb', line 44

def platform_trace(platform_key, _key, data)
  return yield if !defined?(AppOpticsAPM) || gql_config[:enabled] == false

  layer = span_name(platform_key)
  kvs = (data, layer)
  kvs[:Key] = platform_key if (PREP_KEYS + EXEC_KEYS).include?(platform_key)

  transaction_name(kvs[:InboundQuery]) if kvs[:InboundQuery] && layer == 'graphql.execute'

  ::AppOpticsAPM::SDK.trace(layer, kvs) do
    kvs.clear # we don't have to send them twice
    yield
  end
end