Class: Instana::Exporter::Otlp::GraphqlConverter

Inherits:
BaseConverter show all
Defined in:
lib/instana/exporter/otlp/graphql_converter.rb

Overview

Converter for GraphQL spans to OTLP format

Instance Method Summary collapse

Methods inherited from BaseConverter

#convert, #initialize

Constructor Details

This class inherits a constructor from Instana::Exporter::Otlp::BaseConverter

Instance Method Details

#convert_attributesObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/instana/exporter/otlp/graphql_converter.rb', line 34

def convert_attributes
  attributes = {}

  graphql_data = span[:data]&.[](:graphql)
  return attributes unless graphql_data

  add_attribute(attributes, OpenTelemetry::SemConv::Incubating::GRAPHQL::GRAPHQL_OPERATION_NAME, graphql_data[:operationName])
  add_attribute(attributes, OpenTelemetry::SemConv::Incubating::GRAPHQL::GRAPHQL_OPERATION_TYPE, graphql_data[:operationType])
  add_attribute(attributes, OpenTelemetry::SemConv::Incubating::GRAPHQL::GRAPHQL_DOCUMENT, format_fields(graphql_data[:fields]))

  # Add arguments as custom attribute
  add_attribute(attributes, 'graphql.arguments', format_arguments(graphql_data[:arguments])) if graphql_data[:arguments]

  attributes
end

#span_nameString

Build OTel-compliant span name for GraphQL spans

Formula per SPAN_NAME_PATTERNS.txt Section 7 (observability):

"{operationType} {operationName}"  e.g. "query MyQuery"
Falls back to just "{operationType}" when no name, or "graphql" when both absent.

Returns:

  • (String)

    The span name



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/instana/exporter/otlp/graphql_converter.rb', line 20

def span_name
  gql = span[:data]&.[](:graphql) || {}
  type = gql[:operationType].to_s.strip
  name = gql[:operationName].to_s.strip

  if type.empty?
    'graphql'
  elsif name.empty?
    type
  else
    "#{type} #{name}"
  end
end