opentelemetry-instrumentation-graphql 0.25.0 → 0.26.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3371fa2b3365c58fa9a6d601b674883e30f83c8f42904c6995b217eee235205
4
- data.tar.gz: 2d2005d4dbe68396b720afa7cd8395e1fdd2ac6488f6b41b7f36811dd4fedd15
3
+ metadata.gz: 22354dd67b54b11ca1cadf6ddf29294dd5aed6a12ae20dda2d555e93ec8f7b31
4
+ data.tar.gz: 1e14829c1d707245f8cf149dd2470305deef73835f0cf1d3a1c41e289fa188f0
5
5
  SHA512:
6
- metadata.gz: c8a335dc15df7b331af81333e92806ff2b94c5696924bc36201a2d79ab2ea64ed8e09f1a0eb0fe8427514cae82c225cd2fd4811d2544ab2c690e84d39c2ce99b
7
- data.tar.gz: 2eba3563b8d087f3342c83a35b16cfe361d745926949b2584107816f29c133048af5541bee0f1d279fe692856ecf4c4315ba5e483f6f0abcdc6ea914a3ca87b4
6
+ metadata.gz: c0b18403ea47cb8f43683e277ecb5b2f75570c3733f42399d8bc3a3c9255f2ee1990998cd95948087e761df4dee1a29e3c90a1927992ec616ba374231b643844
7
+ data.tar.gz: 07203101de80d2c361b252bd86a9bb7e1883def38706a3ca4cd3c2d48f3c10074b3d117719218992f290c0ebe2532d927a41681c797ee7519d80dbb23a985121
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Release History: opentelemetry-instrumentation-graphql
2
2
 
3
+ ### v0.26.1 / 2023-05-30
4
+
5
+ * FIXED: GraphQL tracing
6
+
7
+ ### v0.26.0 / 2023-05-17
8
+
9
+ * BREAKING CHANGE: GraphQL instrumentation: support new tracing API
10
+
11
+ * ADDED: GraphQL instrumentation: support new tracing API
12
+
3
13
  ### v0.25.0 / 2023-04-17
4
14
 
5
15
  * BREAKING CHANGE: Drop support for EoL Ruby 2.7
@@ -12,19 +12,31 @@ module OpenTelemetry
12
12
  # The Instrumentation class contains logic to detect and install the GraphQL instrumentation
13
13
  class Instrumentation < OpenTelemetry::Instrumentation::Base
14
14
  compatible do
15
- Gem::Requirement.new('<= 2.0.17').satisfied_by?(gem_version) ||
16
- Gem::Requirement.new('~> 2.0.19').satisfied_by?(gem_version)
15
+ if config[:legacy_tracing]
16
+ legacy_tracing_requirement_satisfied?
17
+ else
18
+ Gem::Requirement.new('>= 2.0.18', '< 3.0.0').satisfied_by?(gem_version)
19
+ end
17
20
  end
18
21
 
19
22
  install do |config|
20
- require_dependencies
21
- install_tracer(config)
23
+ if config[:legacy_tracing]
24
+ require_relative 'tracers/graphql_tracer'
25
+ install_tracer(config)
26
+ else
27
+ require_relative 'tracers/graphql_trace'
28
+ install_new_tracer(config)
29
+ end
22
30
  end
23
31
 
24
32
  present do
25
33
  defined?(::GraphQL)
26
34
  end
27
35
 
36
+ def legacy_tracing_requirement_satisfied?
37
+ Gem::Requirement.new('<= 2.0.17').satisfied_by?(gem_version) || Gem::Requirement.new('2.0.19').satisfied_by?(gem_version)
38
+ end
39
+
28
40
  ## Supported configuration keys for the install config hash:
29
41
  #
30
42
  # The enable_platform_field key expects a boolean value,
@@ -49,6 +61,7 @@ module OpenTelemetry
49
61
  option :enable_platform_authorized, default: false, validate: :boolean
50
62
  option :enable_platform_resolve_type, default: false, validate: :boolean
51
63
  option :legacy_platform_span_names, default: false, validate: :boolean
64
+ option :legacy_tracing, default: false, validate: :boolean
52
65
 
53
66
  private
54
67
 
@@ -56,10 +69,6 @@ module OpenTelemetry
56
69
  Gem::Version.new(::GraphQL::VERSION)
57
70
  end
58
71
 
59
- def require_dependencies
60
- require_relative 'tracers/graphql_tracer'
61
- end
62
-
63
72
  def install_tracer(config = {})
64
73
  if config[:schemas].empty?
65
74
  ::GraphQL::Schema.tracer(Tracers::GraphQLTracer.new)
@@ -71,6 +80,18 @@ module OpenTelemetry
71
80
  end
72
81
  end
73
82
  end
83
+
84
+ def install_new_tracer(config = {})
85
+ if config[:schemas].empty?
86
+ ::GraphQL::Schema.trace_with(Tracers::GraphQLTrace)
87
+ else
88
+ config[:schemas].each do |schema|
89
+ schema.trace_with(Tracers::GraphQLTrace)
90
+ rescue StandardError => e
91
+ OpenTelemetry.logger.error("Unable to patch schema #{schema}: #{e.message}")
92
+ end
93
+ end
94
+ end
74
95
  end
75
96
  end
76
97
  end
@@ -0,0 +1,198 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright The OpenTelemetry Authors
4
+ #
5
+ # SPDX-License-Identifier: Apache-2.0
6
+
7
+ require 'opentelemetry'
8
+
9
+ module OpenTelemetry
10
+ module Instrumentation
11
+ module GraphQL
12
+ module Tracers
13
+ # GraphQLTrace contains the OpenTelemetry tracer implementation compatible with
14
+ # the new GraphQL tracing API (>= 2.0.18)
15
+ module GraphQLTrace # rubocop:disable Metrics/ModuleLength
16
+ def initialize(trace_scalars: false, **_options)
17
+ @trace_scalars = trace_scalars
18
+ @platform_field_key_cache = Hash.new { |h, k| h[k] = platform_field_key(k) }
19
+ @platform_authorized_key_cache = Hash.new { |h, k| h[k] = platform_authorized_key(k) }
20
+ @platform_resolve_type_key_cache = Hash.new { |h, k| h[k] = platform_resolve_type_key(k) }
21
+ super
22
+ end
23
+
24
+ def execute_multiplex(multiplex:, &block)
25
+ tracer.in_span('graphql.execute_multiplex', &block)
26
+ end
27
+
28
+ def lex(query_string:, &block)
29
+ tracer.in_span('graphql.lex', &block)
30
+ end
31
+
32
+ def parse(query_string:, &block)
33
+ tracer.in_span('graphql.parse', &block)
34
+ end
35
+
36
+ def validate(query:, validate:, &block)
37
+ tracer.in_span('graphql.validate') do |span|
38
+ super.tap do |response|
39
+ errors = response[:errors]&.compact&.map(&:to_h)&.to_json
40
+ unless errors.nil?
41
+ span.add_event(
42
+ 'graphql.validation.error',
43
+ attributes: {
44
+ 'message' => errors
45
+ }
46
+ )
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ def analyze_multiplex(multiplex:, &block)
53
+ tracer.in_span('graphql.analyze_query', &block)
54
+ end
55
+
56
+ def analyze_query(query:, &block)
57
+ tracer.in_span('graphql.analyze_multiplex', &block)
58
+ end
59
+
60
+ def execute_query(query:, &block)
61
+ attributes = {}
62
+ attributes['graphql.operation.name'] = query.selected_operation_name if query.selected_operation_name
63
+ attributes['graphql.operation.type'] = query.selected_operation.operation_type
64
+ attributes['graphql.document'] = query.query_string
65
+
66
+ tracer.in_span('graphql.execute_query', attributes: attributes, &block)
67
+ end
68
+
69
+ def execute_query_lazy(query:, multiplex:, &block)
70
+ tracer.in_span('graphql.execute_query_lazy', &block)
71
+ end
72
+
73
+ def execute_field(field:, query:, ast_node:, arguments:, object:, &block)
74
+ platform_key = platform_execute_field_key(field: field)
75
+ return super unless platform_key
76
+
77
+ attributes = {}
78
+ attributes['graphql.field.parent'] = field.owner&.graphql_name
79
+ attributes['graphql.field.name'] = field.graphql_name
80
+ attributes['graphql.lazy'] = false
81
+
82
+ tracer.in_span(platform_key, attributes: attributes, &block)
83
+ end
84
+
85
+ def execute_field_lazy(field:, query:, ast_node:, arguments:, object:, &block)
86
+ platform_key = platform_execute_field_key(field: field)
87
+ return super unless platform_key
88
+
89
+ attributes = {}
90
+ attributes['graphql.field.parent'] = field.owner&.graphql_name
91
+ attributes['graphql.field.name'] = field.graphql_name
92
+ attributes['graphql.lazy'] = true
93
+
94
+ tracer.in_span(platform_key, attributes: attributes, &block)
95
+ end
96
+
97
+ def authorized(query:, type:, object:, &block)
98
+ platform_key = @platform_authorized_key_cache[type]
99
+ return super unless platform_key
100
+
101
+ attributes = {}
102
+ attributes['graphql.type.name'] = type.graphql_name
103
+ attributes['graphql.lazy'] = false
104
+
105
+ tracer.in_span(platform_key, attributes: attributes, &block)
106
+ end
107
+
108
+ def authorized_lazy(query:, type:, object:, &block)
109
+ platform_key = @platform_authorized_key_cache[type]
110
+ return super unless platform_key
111
+
112
+ attributes = {}
113
+ attributes['graphql.type.name'] = type.graphql_name
114
+ attributes['graphql.lazy'] = true
115
+
116
+ tracer.in_span(platform_key, attributes: attributes, &block)
117
+ end
118
+
119
+ def resolve_type(query:, type:, object:, &block)
120
+ platform_key = @platform_resolve_type_key_cache[type]
121
+
122
+ attributes = {}
123
+ attributes['graphql.type.name'] = type.graphql_name
124
+ attributes['graphql.lazy'] = false
125
+
126
+ tracer.in_span(platform_key, attributes: attributes, &block)
127
+ end
128
+
129
+ def resolve_type_lazy(query:, type:, object:)
130
+ platform_key = @platform_resolve_type_key_cache[type]
131
+
132
+ attributes = {}
133
+ attributes['graphql.type.name'] = type.graphql_name
134
+ attributes['graphql.lazy'] = true
135
+
136
+ tracer.in_span(platform_key, attributes: attributes, &block)
137
+ end
138
+
139
+ private
140
+
141
+ def platform_execute_field_key(field:, &block)
142
+ trace_field = trace_field?(field)
143
+ platform_key = @platform_field_key_cache[field] if trace_field
144
+ platform_key if platform_key && trace_field
145
+ end
146
+
147
+ def trace_field?(field)
148
+ return_type = field.type.unwrap
149
+
150
+ if return_type.kind.scalar? || return_type.kind.enum?
151
+ (field.trace.nil? && @trace_scalars) || field.trace
152
+ else
153
+ true
154
+ end
155
+ end
156
+
157
+ def platform_field_key(field)
158
+ return unless config[:enable_platform_field]
159
+
160
+ if config[:legacy_platform_span_names]
161
+ field.path
162
+ else
163
+ 'graphql.execute_field'
164
+ end
165
+ end
166
+
167
+ def platform_authorized_key(type)
168
+ return unless config[:enable_platform_authorized]
169
+
170
+ if config[:legacy_platform_span_names]
171
+ "#{type.graphql_name}.authorized"
172
+ else
173
+ 'graphql.authorized'
174
+ end
175
+ end
176
+
177
+ def platform_resolve_type_key(type)
178
+ return unless config[:enable_platform_resolve_type]
179
+
180
+ if config[:legacy_platform_span_names]
181
+ "#{type.graphql_name}.resolve_type"
182
+ else
183
+ 'graphql.resolve_type'
184
+ end
185
+ end
186
+
187
+ def tracer
188
+ GraphQL::Instrumentation.instance.tracer
189
+ end
190
+
191
+ def config
192
+ GraphQL::Instrumentation.instance.config
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end
198
+ end
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module GraphQL
10
- VERSION = '0.25.0'
10
+ VERSION = '0.26.1'
11
11
  end
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-instrumentation-graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.0
4
+ version: 0.26.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenTelemetry Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-17 00:00:00.000000000 Z
11
+ date: 2023-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -148,14 +148,14 @@ dependencies:
148
148
  requirements:
149
149
  - - "~>"
150
150
  - !ruby/object:Gem::Version
151
- version: 1.48.1
151
+ version: 1.50.2
152
152
  type: :development
153
153
  prerelease: false
154
154
  version_requirements: !ruby/object:Gem::Requirement
155
155
  requirements:
156
156
  - - "~>"
157
157
  - !ruby/object:Gem::Version
158
- version: 1.48.1
158
+ version: 1.50.2
159
159
  - !ruby/object:Gem::Dependency
160
160
  name: simplecov
161
161
  requirement: !ruby/object:Gem::Requirement
@@ -227,16 +227,17 @@ files:
227
227
  - lib/opentelemetry/instrumentation.rb
228
228
  - lib/opentelemetry/instrumentation/graphql.rb
229
229
  - lib/opentelemetry/instrumentation/graphql/instrumentation.rb
230
+ - lib/opentelemetry/instrumentation/graphql/tracers/graphql_trace.rb
230
231
  - lib/opentelemetry/instrumentation/graphql/tracers/graphql_tracer.rb
231
232
  - lib/opentelemetry/instrumentation/graphql/version.rb
232
233
  homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
233
234
  licenses:
234
235
  - Apache-2.0
235
236
  metadata:
236
- changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-graphql/0.25.0/file/CHANGELOG.md
237
+ changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-graphql/0.26.1/file/CHANGELOG.md
237
238
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/graphql
238
239
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
239
- documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-graphql/0.25.0
240
+ documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-graphql/0.26.1
240
241
  post_install_message:
241
242
  rdoc_options: []
242
243
  require_paths: