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_resolve_type_lazy

Instance Method Details

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



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/graphql/tracing/data_dog_trace.rb', line 92

def authorized(object:, type:, query:, span_key: "authorized")
  platform_key = @platform_authorized_key_cache[type]
  @tracer.trace(platform_key, service: @service_name) do |span|
    span.span_type = 'custom'
    if defined?(Datadog::Tracing::Metadata::Ext) # Introduced in ddtrace 1.0
      span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT, 'graphql')
      span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION, span_key)
    end
    prepare_span(span_key, {object: object, type: type, query: query}, span)
    super(query: query, type: type, object: object)
  end
end

#authorized_lazy(**kwargs, &block) ⇒ Object



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

def authorized_lazy(**kwargs, &block)
  authorized(span_key: "authorized_lazy", **kwargs, &block)
end

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

Parameters:

  • analytics_enabled (Boolean) (defaults to: false)

    Deprecated

  • analytics_sample_rate (Float) (defaults to: 1.0)

    Deprecated



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

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

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

  @analytics_enabled = analytics_available && Datadog::Contrib::Analytics.enabled?(analytics_enabled)
  @analytics_sample_rate = analytics_sample_rate
  @service_name = service
  super
end

#platform_authorized_key(type) ⇒ Object



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

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

#platform_execute_field(platform_key, data, span_key = "execute_field") ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/graphql/tracing/data_dog_trace.rb', line 76

def platform_execute_field(platform_key, data, span_key = "execute_field")
  @tracer.trace(platform_key, service: @service_name) do |span|
    span.span_type = 'custom'
    if defined?(Datadog::Tracing::Metadata::Ext) # Introduced in ddtrace 1.0
      span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT, 'graphql')
      span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION, span_key)
    end
    prepare_span(span_key, data, span)
    yield
  end
end

#platform_execute_field_lazy(platform_key, data, &block) ⇒ Object



88
89
90
# File 'lib/graphql/tracing/data_dog_trace.rb', line 88

def platform_execute_field_lazy(platform_key, data, &block)
  platform_execute_field(platform_key, data, "execute_field_lazy", &block)
end

#platform_field_key(field) ⇒ Object



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

def platform_field_key(field)
  field.path
end

#platform_resolve_type_key(type) ⇒ Object



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

def platform_resolve_type_key(type)
  "#{type.graphql_name}.resolve_type"
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



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

def prepare_span(key, data, span)
end

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



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

def resolve_type(object:, type:, query:, span_key: "resolve_type")
  platform_key = @platform_resolve_type_key_cache[type]
  @tracer.trace(platform_key, service: @service_name) do |span|
    span.span_type = 'custom'
    if defined?(Datadog::Tracing::Metadata::Ext) # Introduced in ddtrace 1.0
      span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT, 'graphql')
      span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION, span_key)
    end
    prepare_span(span_key, {object: object, type: type, query: query}, span)
    super(query: query, type: type, object: object)
  end
end

#resolve_type_lazy(**kwargs, &block) ⇒ Object



122
123
124
# File 'lib/graphql/tracing/data_dog_trace.rb', line 122

def resolve_type_lazy(**kwargs, &block)
  resolve_type(span_key: "resolve_type_lazy", **kwargs, &block)
end