Class: GraphQL::Tracing::OpenTelemetryTracing

Inherits:
PlatformTracing show all
Defined in:
lib/graphql/tracing/opentelemetry_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

#platform_authorized_key(type) ⇒ Object



39
40
41
# File 'lib/graphql/tracing/opentelemetry_tracing.rb', line 39

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

#platform_field_key(type, field) ⇒ Object



35
36
37
# File 'lib/graphql/tracing/opentelemetry_tracing.rb', line 35

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

#platform_resolve_type_key(type) ⇒ Object



43
44
45
# File 'lib/graphql/tracing/opentelemetry_tracing.rb', line 43

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
# File 'lib/graphql/tracing/opentelemetry_tracing.rb', line 17

def platform_trace(platform_key, key, data)
  return yield if platform_key.nil?

  tracer.in_span(platform_key, attributes: attributes_for(key, data)) do |span, _context|
    yield.tap do |response|
      errors = response[:errors]&.compact&.map { |e| e.to_h }&.to_json if key == 'validate'
      unless errors.nil?
        span.add_event(
          'graphql.validation.error',
          attributes: {
            'message' => errors
          }
        )
      end
    end
  end
end