Module: GraphQL::Tracing::AppOpticsTrace

Includes:
PlatformTrace
Defined in:
lib/graphql/tracing/appoptics_trace.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 included from PlatformTrace

#initialize, #platform_authorized_lazy, #platform_execute_field_lazy, #platform_resolve_type_lazy

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



27
28
29
# File 'lib/graphql/tracing/appoptics_trace.rb', line 27

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

Instance Method Details

#authorized(**data) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/graphql/tracing/appoptics_trace.rb', line 69

def authorized(**data)
  return super if !defined?(AppOpticsAPM) || gql_config[:enabled] == false
  layer = @platform_authorized_key_cache[data[:type]]
  kvs = (data, layer)

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

#authorized_lazy(**data) ⇒ Object



80
81
82
83
84
85
86
87
88
89
# File 'lib/graphql/tracing/appoptics_trace.rb', line 80

def authorized_lazy(**data)
  return super if !defined?(AppOpticsAPM) || gql_config[:enabled] == false
  layer = @platform_authorized_key_cache[data[:type]]
  kvs = (data, layer)

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

#platform_authorized_key(type) ⇒ Object



119
120
121
# File 'lib/graphql/tracing/appoptics_trace.rb', line 119

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

#platform_execute_field(platform_key, data) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/graphql/tracing/appoptics_trace.rb', line 58

def platform_execute_field(platform_key, data)
  return super if !defined?(AppOpticsAPM) || gql_config[:enabled] == false
  layer = platform_key
  kvs = (data, layer)

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

#platform_field_key(field) ⇒ Object



115
116
117
# File 'lib/graphql/tracing/appoptics_trace.rb', line 115

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

#platform_resolve_type_key(type) ⇒ Object



123
124
125
# File 'lib/graphql/tracing/appoptics_trace.rb', line 123

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

#resolve_type(**data) ⇒ Object



91
92
93
94
95
96
97
98
99
100
# File 'lib/graphql/tracing/appoptics_trace.rb', line 91

def resolve_type(**data)
  return super if !defined?(AppOpticsAPM) || gql_config[:enabled] == false
  layer = @platform_resolve_type_key_cache[data[:type]]
  kvs = (data, layer)

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

#resolve_type_lazy(**data) ⇒ Object



102
103
104
105
106
107
108
109
110
111
# File 'lib/graphql/tracing/appoptics_trace.rb', line 102

def resolve_type_lazy(**data)
  return super if !defined?(AppOpticsAPM) || gql_config[:enabled] == false
  layer = @platform_resolve_type_key_cache[data[:type]]
  kvs = (data, layer)

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