Class: GraphQL::Tracing::DataDogTracing

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

Instance Method Summary collapse

Methods inherited from PlatformTracing

inherited, #initialize, #trace, use

Constructor Details

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

Instance Method Details

#analytics_enabled? ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
76
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 73

def analytics_enabled?
  # [Deprecated] options[:analytics_enabled] will be removed in the future
  options.fetch(:analytics_enabled, false)
end

#analytics_sample_rate ⇒ Object



78
79
80
81
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 78

def analytics_sample_rate
  # [Deprecated] options[:analytics_sample_rate] will be removed in the future
  options.fetch(:analytics_sample_rate, 1.0)
end

#platform_authorized_key(type) ⇒ Object



87
88
89
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 87

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

#platform_field_key(type, field) ⇒ Object



83
84
85
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 83

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

#platform_resolve_type_key(type) ⇒ Object



91
92
93
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 91

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

#platform_trace(platform_key, key, data) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 21

def platform_trace(platform_key, key, data)
  tracer.trace(platform_key, service: options[:service], type: 'custom') do |span|
    span.set_tag('component', 'graphql')
    span.set_tag('operation', key)

    if key == 'execute_multiplex'
      operations = data[:multiplex].queries.map(&:selected_operation_name).join(', ')

      resource = if operations.empty?
        first_query = data[:multiplex].queries.first
        fallback_transaction_name(first_query && first_query.context)
      else
        operations
      end
      span.resource = resource if resource

      # [Deprecated] will be removed in the future
      span.set_metric('_dd1.sr.eausr', analytics_sample_rate) if analytics_enabled?
    end

    if key == 'execute_query'
      span.set_tag(:selected_operation_name, data[:query].selected_operation_name)
      span.set_tag(:selected_operation_type, data[:query].selected_operation.operation_type)
      span.set_tag(:query_string, data[:query].query_string)
    end

    prepare_span(key, data, span)

    yield
  end
end

#prepare_span(key, data, span) ⇒ Object

Implement this method in a subclass to apply custom tags to datadog spans

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

:call-seq:

prepare_span(String key, Hash data, Datadog::Tracing::SpanOperation span)


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

def prepare_span(key, data, span)
end

#tracer ⇒ Object



66
67
68
69
70
71
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 66

def tracer
  default_tracer = defined?(Datadog::Tracing) ? Datadog::Tracing : Datadog.tracer

  # [Deprecated] options[:tracer] will be removed in the future
  options.fetch(:tracer, default_tracer)
end