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

#initialize, #trace, use

Constructor Details

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

Instance Method Details

#analytics_available?Boolean

Returns:

  • (Boolean)


56
57
58
59
60
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 56

def analytics_available?
  defined?(Datadog::Contrib::Analytics) \
    && Datadog::Contrib::Analytics.respond_to?(:enabled?) \
    && Datadog::Contrib::Analytics.respond_to?(:set_sample_rate)
end

#analytics_enabled?Boolean

Returns:

  • (Boolean)


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

def analytics_enabled?
  analytics_available? && Datadog::Contrib::Analytics.enabled?(options.fetch(:analytics_enabled, false))
end

#analytics_sample_rateObject



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

def analytics_sample_rate
  options.fetch(:analytics_sample_rate, 1.0)
end

#platform_authorized_key(type) ⇒ Object



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

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

#platform_field_key(type, field) ⇒ Object



70
71
72
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 70

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

#platform_resolve_type_key(type) ⇒ Object



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

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

#platform_trace(platform_key, key, data) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 17

def platform_trace(platform_key, key, data)
  tracer.trace(platform_key, service: service_name) do |span|
    span.span_type = 'custom'

    if key == 'execute_multiplex'
      operations = data[:multiplex].queries.map(&:selected_operation_name).join(', ')
      span.resource = if operations.empty?
        first_query = data[:multiplex].queries.first
        fallback_transaction_name(first_query && first_query.context)
      else
        operations
      end

      # For top span of query, set the analytics sample rate tag, if available.
      if analytics_enabled?
        Datadog::Contrib::Analytics.set_sample_rate(span, analytics_sample_rate)
      end
    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

    yield
  end
end

#service_nameObject



46
47
48
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 46

def service_name
  options.fetch(:service, 'ruby-graphql')
end

#tracerObject



50
51
52
53
54
# File 'lib/graphql/tracing/data_dog_tracing.rb', line 50

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

  options.fetch(:tracer, default_tracer)
end