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



88
89
90
91
92
93
94
95
96
97
# File 'lib/graphql/tracing/appoptics_trace.rb', line 88

def authorized(**data)
  return super if !defined?(AppOpticsAPM) || gql_config[:enabled] == false
  layer = @platform_key_cache[AppOpticsTrace].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



99
100
101
102
103
104
105
106
107
108
# File 'lib/graphql/tracing/appoptics_trace.rb', line 99

def authorized_lazy(**data)
  return super if !defined?(AppOpticsAPM) || gql_config[:enabled] == false
  layer = @platform_key_cache[AppOpticsTrace].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

#execute_field(query:, field:, ast_node:, arguments:, object:) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/graphql/tracing/appoptics_trace.rb', line 58

def execute_field(query:, field:, ast_node:, arguments:, object:)
  return_type = field.type.unwrap
  trace_field = if return_type.kind.scalar? || return_type.kind.enum?
    (field.trace.nil? && @trace_scalars) || field.trace
  else
    true
  end
  platform_key = if trace_field
    @platform_key_cache[AppOpticsTrace].platform_field_key_cache[field]
  else
    nil
  end
  if platform_key && trace_field
    return super if !defined?(AppOpticsAPM) || gql_config[:enabled] == false
    layer = platform_key
    kvs = ({query: query, field: field, ast_node: ast_node, arguments: arguments, object: object}, layer)

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

#execute_field_lazy(query:, field:, ast_node:, arguments:, object:) ⇒ Object



84
85
86
# File 'lib/graphql/tracing/appoptics_trace.rb', line 84

def execute_field_lazy(query:, field:, ast_node:, arguments:, object:)
  execute_field(query: query, field: field, ast_node: ast_node, arguments: arguments, object: object)
end

#platform_authorized_key(type) ⇒ Object



139
140
141
# File 'lib/graphql/tracing/appoptics_trace.rb', line 139

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

#platform_field_key(field) ⇒ Object



135
136
137
# File 'lib/graphql/tracing/appoptics_trace.rb', line 135

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

#platform_resolve_type_key(type) ⇒ Object



143
144
145
# File 'lib/graphql/tracing/appoptics_trace.rb', line 143

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

#resolve_type(**data) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/graphql/tracing/appoptics_trace.rb', line 110

def resolve_type(**data)
  return super if !defined?(AppOpticsAPM) || gql_config[:enabled] == false
  layer = @platform_key_cache[AppOpticsTrace].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



122
123
124
125
126
127
128
129
130
131
# File 'lib/graphql/tracing/appoptics_trace.rb', line 122

def resolve_type_lazy(**data)
  return super if !defined?(AppOpticsAPM) || gql_config[:enabled] == false
  layer = @platform_key_cache[AppOpticsTrace].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