Module: OpenTelemetry::Instrumentation::GraphQL::Tracers::GraphQLTrace
- Defined in:
- lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb
Overview
GraphQLTrace contains the OpenTelemetry tracer implementation compatible with the new GraphQL tracing API (>= 2.0.18)
Instance Method Summary collapse
- #analyze_multiplex(multiplex:, &block) ⇒ Object
- #analyze_query(query:, &block) ⇒ Object
- #authorized(query:, type:, object:, &block) ⇒ Object
- #authorized_lazy(query:, type:, object:, &block) ⇒ Object
- #execute_field(field:, query:, ast_node:, arguments:, object:, &block) ⇒ Object
- #execute_field_lazy(field:, query:, ast_node:, arguments:, object:, &block) ⇒ Object
- #execute_multiplex(multiplex:, &block) ⇒ Object
- #execute_query(query:, &block) ⇒ Object
- #execute_query_lazy(query:, multiplex:, &block) ⇒ Object
-
#initialize(trace_scalars: false, **_options) ⇒ Object
rubocop:disable Metrics/ModuleLength.
- #lex(query_string:, &block) ⇒ Object
- #parse(query_string:, &block) ⇒ Object
- #resolve_type(query:, type:, object:, &block) ⇒ Object
- #resolve_type_lazy(query:, type:, object:, &block) ⇒ Object
- #validate(query:, validate:, &block) ⇒ Object
Instance Method Details
#analyze_multiplex(multiplex:, &block) ⇒ Object
91 92 93 |
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb', line 91 def analyze_multiplex(multiplex:, &block) tracer.in_span('graphql.analyze_query', &block) end |
#analyze_query(query:, &block) ⇒ Object
95 96 97 |
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb', line 95 def analyze_query(query:, &block) tracer.in_span('graphql.analyze_multiplex', &block) end |
#authorized(query:, type:, object:, &block) ⇒ Object
130 131 132 133 134 135 136 137 |
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb', line 130 def (query:, type:, object:, &block) platform_key = @_otel_authorized_key_cache[type] return super unless platform_key attributes = @_otel_type_attrs_cache[type] tracer.in_span(platform_key, attributes: attributes, &block) end |
#authorized_lazy(query:, type:, object:, &block) ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb', line 139 def (query:, type:, object:, &block) platform_key = @_otel_authorized_key_cache[type] return super unless platform_key attributes = @_otel_lazy_type_attrs_cache[type] tracer.in_span(platform_key, attributes: attributes, &block) end |
#execute_field(field:, query:, ast_node:, arguments:, object:, &block) ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb', line 112 def execute_field(field:, query:, ast_node:, arguments:, object:, &block) platform_key = _otel_execute_field_key(field: field) return super(field: field, query: query, ast_node: ast_node, object: object, arguments: arguments, &block) unless platform_key attributes = @_otel_field_attrs_cache[field] tracer.in_span(platform_key, attributes: attributes, &block) end |
#execute_field_lazy(field:, query:, ast_node:, arguments:, object:, &block) ⇒ Object
121 122 123 124 125 126 127 128 |
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb', line 121 def execute_field_lazy(field:, query:, ast_node:, arguments:, object:, &block) platform_key = _otel_execute_field_key(field: field) return super(field: field, query: query, ast_node: ast_node, object: object, arguments: arguments, &block) unless platform_key attributes = @_otel_lazy_field_attrs_cache[field] tracer.in_span(platform_key, attributes: attributes, &block) end |
#execute_multiplex(multiplex:, &block) ⇒ Object
62 63 64 |
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb', line 62 def execute_multiplex(multiplex:, &block) tracer.in_span('graphql.execute_multiplex', &block) end |
#execute_query(query:, &block) ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb', line 99 def execute_query(query:, &block) attributes = {} attributes['graphql.operation.name'] = query.selected_operation_name if query.selected_operation_name attributes['graphql.operation.type'] = query.selected_operation.operation_type attributes['graphql.document'] = query.query_string tracer.in_span('graphql.execute_query', attributes: attributes, &block) end |
#execute_query_lazy(query:, multiplex:, &block) ⇒ Object
108 109 110 |
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb', line 108 def execute_query_lazy(query:, multiplex:, &block) tracer.in_span('graphql.execute_query_lazy', &block) end |
#initialize(trace_scalars: false, **_options) ⇒ Object
rubocop:disable Metrics/ModuleLength
16 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb', line 16 def initialize(trace_scalars: false, **) @trace_scalars = trace_scalars @_otel_field_key_cache = Hash.new { |h, k| h[k] = _otel_field_key(k) } @_otel_field_key_cache.compare_by_identity @_otel_authorized_key_cache = Hash.new { |h, k| h[k] = (k) } @_otel_authorized_key_cache.compare_by_identity @_otel_resolve_type_key_cache = Hash.new { |h, k| h[k] = _otel_resolve_type_key(k) } @_otel_resolve_type_key_cache.compare_by_identity @_otel_type_attrs_cache = Hash.new do |h, type| h[type] = { 'graphql.type.name' => type.graphql_name, 'graphql.lazy' => false }.freeze end @_otel_type_attrs_cache.compare_by_identity @_otel_lazy_type_attrs_cache = Hash.new do |h, type| h[type] = { 'graphql.type.name' => type.graphql_name, 'graphql.lazy' => true }.freeze end @_otel_lazy_type_attrs_cache.compare_by_identity @_otel_field_attrs_cache = Hash.new do |h, field| h[field] = { 'graphql.field.parent' => field.owner&.graphql_name, 'graphql.field.name' => field.graphql_name, 'graphql.lazy' => false }.freeze end @_otel_field_attrs_cache.compare_by_identity @_otel_lazy_field_attrs_cache = Hash.new do |h, field| h[field] = { 'graphql.field.parent' => field.owner&.graphql_name, 'graphql.field.name' => field.graphql_name, 'graphql.lazy' => true }.freeze end @_otel_lazy_field_attrs_cache.compare_by_identity super end |
#lex(query_string:, &block) ⇒ Object
66 67 68 |
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb', line 66 def lex(query_string:, &block) tracer.in_span('graphql.lex', &block) end |
#parse(query_string:, &block) ⇒ Object
70 71 72 |
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb', line 70 def parse(query_string:, &block) tracer.in_span('graphql.parse', &block) end |
#resolve_type(query:, type:, object:, &block) ⇒ Object
147 148 149 150 151 |
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb', line 147 def resolve_type(query:, type:, object:, &block) platform_key = @_otel_resolve_type_key_cache[type] attributes = @_otel_type_attrs_cache[type] tracer.in_span(platform_key, attributes: attributes, &block) end |
#resolve_type_lazy(query:, type:, object:, &block) ⇒ Object
153 154 155 156 157 |
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb', line 153 def resolve_type_lazy(query:, type:, object:, &block) platform_key = @_otel_resolve_type_key_cache[type] attributes = @_otel_lazy_type_attrs_cache[type] tracer.in_span(platform_key, attributes: attributes, &block) end |
#validate(query:, validate:, &block) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb', line 74 def validate(query:, validate:, &block) tracer.in_span('graphql.validate') do |span| super.tap do |response| errors = response[:errors]&.compact&.map(&:to_h) || [] unless errors.empty? span.add_event( 'graphql.validation.error', attributes: { 'exception.message' => errors.to_json } ) end end end end |