Module: GraphQL::Tracing::DataDogTrace

Includes:
PlatformTrace
Defined in:
lib/graphql/tracing/data_dog_trace.rb

Instance Method Summary collapse

Methods included from PlatformTrace

#platform_authorized_lazy, #platform_execute_field_lazy, #platform_resolve_type_lazy

Instance Method Details

#authorized(query:, type:, object:) ⇒ Object



111
112
113
114
115
# File 'lib/graphql/tracing/data_dog_trace.rb', line 111

def authorized(query:, type:, object:)
  authorized_span("authorized", object, type, query) do
    super(query: query, type: type, object: object)
  end
end

#authorized_lazy(object:, type:, query:) ⇒ Object



130
131
132
133
134
# File 'lib/graphql/tracing/data_dog_trace.rb', line 130

def authorized_lazy(object:, type:, query:)
  authorized_span("authorized_lazy", object, type, query) do
    super(query: query, type: type, object: object)
  end
end

#authorized_span(span_key, object, type, query) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/graphql/tracing/data_dog_trace.rb', line 117

def authorized_span(span_key, object, type, query)
  platform_key = @platform_key_cache[DataDogTrace].platform_authorized_key_cache[type]
  @tracer.trace(platform_key, service: @service_name, type: 'custom') do |span|
    span.set_tag('component', 'graphql')
    span.set_tag('operation', span_key)

    if @has_prepare_span
      prepare_span(span_key, {object: object, type: type, query: query}, span)
    end
    yield
  end
end

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



99
100
101
102
103
# File 'lib/graphql/tracing/data_dog_trace.rb', line 99

def execute_field(query:, field:, ast_node:, arguments:, object:)
  execute_field_span("execute_field", query, field, ast_node, arguments, object) do
    super(query: query, field: field, ast_node: ast_node, arguments: arguments, object: object)
  end
end

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



105
106
107
108
109
# File 'lib/graphql/tracing/data_dog_trace.rb', line 105

def execute_field_lazy(query:, field:, ast_node:, arguments:, object:)
  execute_field_span("execute_field_lazy", query, field, ast_node, arguments, object) do
    super(query: query, field: field, ast_node: ast_node, arguments: arguments, object: object)
  end
end

#execute_field_span(span_key, query, field, ast_node, arguments, object) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/graphql/tracing/data_dog_trace.rb', line 72

def execute_field_span(span_key, 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[DataDogTrace].platform_field_key_cache[field]
  else
    nil
  end
  if platform_key && trace_field
    @tracer.trace(platform_key, service: @service_name, type: 'custom') do |span|
      span.set_tag('component', 'graphql')
      span.set_tag('operation', span_key)

      if @has_prepare_span
        prepare_span_data = { query: query, field: field, ast_node: ast_node, arguments: arguments, object: object }
        prepare_span(span_key, prepare_span_data, span)
      end
      yield
    end
  else
    yield
  end
end

#initialize(tracer: nil, analytics_enabled: false, analytics_sample_rate: 1.0, service: nil, **rest) ⇒ Object

Parameters:

  • tracer (#trace) (defaults to: nil)

    Deprecated

  • analytics_enabled (Boolean) (defaults to: false)

    Deprecated

  • analytics_sample_rate (Float) (defaults to: 1.0)

    Deprecated



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/graphql/tracing/data_dog_trace.rb', line 9

def initialize(tracer: nil, analytics_enabled: false, analytics_sample_rate: 1.0, service: nil, **rest)
  if tracer.nil?
    tracer = defined?(Datadog::Tracing) ? Datadog::Tracing : Datadog.tracer
  end
  @tracer = tracer

  @analytics_enabled = analytics_enabled
  @analytics_sample_rate = analytics_sample_rate

  @service_name = service
  @has_prepare_span = respond_to?(:prepare_span)
  super
end

#platform_authorized_key(type) ⇒ Object



174
175
176
# File 'lib/graphql/tracing/data_dog_trace.rb', line 174

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

#platform_field_key(field) ⇒ Object

Implement this method in a subclass to apply custom tags to datadog spans def prepare_span(key, data, span) end

Parameters:

  • key (String)

    The event being traced

  • data (Hash)

    The runtime data for this event (@see GraphQL::Tracing for keys for each event)

  • span (Datadog::Tracing::SpanOperation)

    The datadog span for this event



170
171
172
# File 'lib/graphql/tracing/data_dog_trace.rb', line 170

def platform_field_key(field)
  field.path
end

#platform_resolve_type_key(type) ⇒ Object



178
179
180
# File 'lib/graphql/tracing/data_dog_trace.rb', line 178

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

#resolve_type(object:, type:, query:) ⇒ Object



136
137
138
139
140
# File 'lib/graphql/tracing/data_dog_trace.rb', line 136

def resolve_type(object:, type:, query:)
  resolve_type_span("resolve_type", object, type, query) do
    super(object: object, query: query, type: type)
  end
end

#resolve_type_lazy(object:, type:, query:) ⇒ Object



142
143
144
145
146
# File 'lib/graphql/tracing/data_dog_trace.rb', line 142

def resolve_type_lazy(object:, type:, query:)
  resolve_type_span("resolve_type_lazy", object, type, query) do
    super(object: object, query: query, type: type)
  end
end

#resolve_type_span(span_key, object, type, query) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/graphql/tracing/data_dog_trace.rb', line 148

def resolve_type_span(span_key, object, type, query)
  platform_key = @platform_key_cache[DataDogTrace].platform_resolve_type_key_cache[type]
  @tracer.trace(platform_key, service: @service_name, type: 'custom') do |span|
    span.set_tag('component', 'graphql')
    span.set_tag('operation', span_key)

    if @has_prepare_span
      prepare_span(span_key, {object: object, type: type, query: query}, span)
    end
    yield
  end
end