Module: Datadog::Tracing::Contrib::GraphQL::UnifiedTrace

Includes:
GraphQL::Tracing::PlatformTrace
Defined in:
lib/datadog/tracing/contrib/graphql/unified_trace.rb

Overview

These methods will be called by the GraphQL runtime to trace the execution of queries. This tracer differs from the upstream one as it follows the unified naming convention specification, which is required to use features such as API Catalog. DEV-3.0: This tracer should be the default one in the next major version.

Instance Method Summary collapse

Instance Method Details

#analyze_multiplex(*args, multiplex:, **kwargs) ⇒ Object



35
36
37
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 35

def analyze_multiplex(*args, multiplex:, **kwargs)
  trace(proc { super }, 'analyze_multiplex', multiplex_resource(multiplex), multiplex: multiplex)
end

#analyze_query(*args, query:, **kwargs) ⇒ Object



39
40
41
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 39

def analyze_query(*args, query:, **kwargs)
  trace(proc { super }, 'analyze', query.query_string, query: query)
end

#authorized(*args, **kwargs) ⇒ Object



97
98
99
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 97

def authorized(*args, **kwargs)
  authorized_span(proc { super }, 'authorized', **kwargs)
end

#authorized_lazy(*args, **kwargs) ⇒ Object



101
102
103
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 101

def authorized_lazy(*args, **kwargs)
  authorized_span(proc { super }, 'authorized_lazy', **kwargs)
end

#authorized_span(callable, span_key, **kwargs) ⇒ Object



92
93
94
95
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 92

def authorized_span(callable, span_key, **kwargs)
  platform_key = @platform_key_cache[UnifiedTrace].platform_authorized_key_cache[kwargs[:type]]
  trace(callable, span_key, platform_key, **kwargs)
end

#execute_field(*args, **kwargs) ⇒ Object



84
85
86
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 84

def execute_field(*args, **kwargs)
  execute_field_span(proc { super }, 'resolve', **kwargs)
end

#execute_field_lazy(*args, **kwargs) ⇒ Object



88
89
90
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 88

def execute_field_lazy(*args, **kwargs)
  execute_field_span(proc { super }, 'resolve_lazy', **kwargs)
end

#execute_field_span(callable, span_key, **kwargs) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 69

def execute_field_span(callable, span_key, **kwargs)
  # @platform_key_cache is initialized upstream, in ::GraphQL::Tracing::PlatformTrace
  platform_key = @platform_key_cache[UnifiedTrace].platform_field_key_cache[kwargs[:field]]

  if platform_key
    trace(callable, span_key, platform_key, **kwargs) do |span|
      kwargs[:arguments].each do |key, value|
        span.set_tag("graphql.variables.#{key}", value)
      end
    end
  else
    callable.call
  end
end

#execute_multiplex(*args, multiplex:, **kwargs) ⇒ Object



43
44
45
46
47
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 43

def execute_multiplex(*args, multiplex:, **kwargs)
  trace(proc { super }, 'execute_multiplex', multiplex_resource(multiplex), multiplex: multiplex) do |span|
    span.set_tag('graphql.source', "Multiplex[#{multiplex.queries.map(&:query_string).join(', ')}]")
  end
end

#execute_query(*args, query:, **kwargs) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 49

def execute_query(*args, query:, **kwargs)
  trace(proc { super }, 'execute', query.selected_operation_name, query: query) do |span|
    span.set_tag('graphql.source', query.query_string)
    span.set_tag('graphql.operation.type', query.selected_operation.operation_type)
    span.set_tag('graphql.operation.name', query.selected_operation_name) if query.selected_operation_name
    query.variables.instance_variable_get(:@storage).each do |key, value|
      span.set_tag("graphql.variables.#{key}", value)
    end
  end
end

#execute_query_lazy(*args, query:, multiplex:, **kwargs) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 60

def execute_query_lazy(*args, query:, multiplex:, **kwargs)
  resource = if query
               query.selected_operation_name || fallback_transaction_name(query.context)
             else
               multiplex_resource(multiplex)
             end
  trace(proc { super }, 'execute_lazy', resource, query: query, multiplex: multiplex)
end

#initialize(*args, **kwargs) ⇒ Object



14
15
16
17
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 14

def initialize(*args, **kwargs)
  @has_prepare_span = respond_to?(:prepare_span)
  super
end

#lex(*args, query_string:, **kwargs) ⇒ Object



19
20
21
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 19

def lex(*args, query_string:, **kwargs)
  trace(proc { super }, 'lex', query_string, query_string: query_string)
end

#parse(*args, query_string:, **kwargs) ⇒ Object



23
24
25
26
27
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 23

def parse(*args, query_string:, **kwargs)
  trace(proc { super }, 'parse', query_string, query_string: query_string) do |span|
    span.set_tag('graphql.source', query_string)
  end
end

#platform_authorized_key(type, *args, **kwargs) ⇒ Object



124
125
126
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 124

def platform_authorized_key(type, *args, **kwargs)
  "#{type.graphql_name}.authorized"
end

#platform_field_key(field, *args, **kwargs) ⇒ Object



120
121
122
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 120

def platform_field_key(field, *args, **kwargs)
  field.path
end

#platform_resolve_type_key(type, *args, **kwargs) ⇒ Object



128
129
130
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 128

def platform_resolve_type_key(type, *args, **kwargs)
  "#{type.graphql_name}.resolve_type"
end

#resolve_type(*args, **kwargs) ⇒ Object



110
111
112
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 110

def resolve_type(*args, **kwargs)
  resolve_type_span(proc { super }, 'resolve_type', **kwargs)
end

#resolve_type_lazy(*args, **kwargs) ⇒ Object



114
115
116
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 114

def resolve_type_lazy(*args, **kwargs)
  resolve_type_span(proc { super }, 'resolve_type_lazy', **kwargs)
end

#resolve_type_span(callable, span_key, **kwargs) ⇒ Object



105
106
107
108
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 105

def resolve_type_span(callable, span_key, **kwargs)
  platform_key = @platform_key_cache[UnifiedTrace].platform_resolve_type_key_cache[kwargs[:type]]
  trace(callable, span_key, platform_key, **kwargs)
end

#validate(*args, query:, validate:, **kwargs) ⇒ Object



29
30
31
32
33
# File 'lib/datadog/tracing/contrib/graphql/unified_trace.rb', line 29

def validate(*args, query:, validate:, **kwargs)
  trace(proc { super }, 'validate', query.selected_operation_name, query: query, validate: validate) do |span|
    span.set_tag('graphql.source', query.query_string)
  end
end