opentelemetry-instrumentation-graphql 0.26.8 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c36e26e0ccdc84604de671dc5bd2d6dcd7fd06bbaa9c0159e7d30513813bfdd
4
- data.tar.gz: 051b5110592eddb5495868aab95469a88813476c413cc345bd9cb1ae75e22c3d
3
+ metadata.gz: cf9a17d56d662feb78eacc36f2f23dc43d4a01244993b638b87f2c1ce1edc5da
4
+ data.tar.gz: 899d075eb41a2d13c0da8d9e6b3ccc08c0b568b476a0be89262e04baa85c31bf
5
5
  SHA512:
6
- metadata.gz: 5df687d48d5b7062b6c3b3377aa367b14d12550ae82192e06c93cc9cfe1c0c052fe5172d00939ca57a0e17a578e11c84d41ee2d5c54ef2e118e31a1421b7bbc9
7
- data.tar.gz: e2f39bfb71a33bdb69c588bacae73c57680e014e4a0e0a435f2031518674bfb2802bfdb8cefba8fb7c22349ca113916349696f518b05dfbc802888e41fc2fc4d
6
+ metadata.gz: 0217566ff1adebe65c331b91ca473989c47ffa43fc027d029fd125eb51388d739e2b283b43eadc80771cb81665c868418a7b06adb8f2be8ee80243259f733d88
7
+ data.tar.gz: ea52c6fd2b8b9bc378038046a25b92e1dbc11386764e88482439ba974a7fd1f5b6f2e42850b11b270c4ce69410e4a49419dc042328dc9b9c8bc7981c35e91db5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Release History: opentelemetry-instrumentation-graphql
2
2
 
3
+ ### v0.28.0 / 2024-02-16
4
+
5
+ * BREAKING CHANGE: GraphQL Legacy Tracer perf improvements [#867](https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/867).
6
+
7
+ * ADDED: GraphQL Legacy Tracer perf improvements [#867](https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/867).
8
+
9
+ ### v0.27.0 / 2023-11-28
10
+
11
+ * CHANGED: Performance optimization cache attribute hashes [#723](https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/723)
12
+
3
13
  ### v0.26.8 / 2023-11-23
4
14
 
5
15
  * CHANGED: Applied Rubocop Performance Recommendations [#727](https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/727)
@@ -16,8 +16,46 @@ module OpenTelemetry
16
16
  def initialize(trace_scalars: false, **_options)
17
17
  @trace_scalars = trace_scalars
18
18
  @_otel_field_key_cache = Hash.new { |h, k| h[k] = _otel_field_key(k) }
19
+ @_otel_field_key_cache.compare_by_identity
19
20
  @_otel_authorized_key_cache = Hash.new { |h, k| h[k] = _otel_authorized_key(k) }
21
+ @_otel_authorized_key_cache.compare_by_identity
20
22
  @_otel_resolve_type_key_cache = Hash.new { |h, k| h[k] = _otel_resolve_type_key(k) }
23
+ @_otel_resolve_type_key_cache.compare_by_identity
24
+
25
+ @_otel_type_attrs_cache = Hash.new do |h, type|
26
+ h[type] = {
27
+ 'graphql.type.name' => type.graphql_name,
28
+ 'graphql.lazy' => false
29
+ }.freeze
30
+ end
31
+ @_otel_type_attrs_cache.compare_by_identity
32
+
33
+ @_otel_lazy_type_attrs_cache = Hash.new do |h, type|
34
+ h[type] = {
35
+ 'graphql.type.name' => type.graphql_name,
36
+ 'graphql.lazy' => true
37
+ }.freeze
38
+ end
39
+ @_otel_lazy_type_attrs_cache.compare_by_identity
40
+
41
+ @_otel_field_attrs_cache = Hash.new do |h, field|
42
+ h[field] = {
43
+ 'graphql.field.parent' => field.owner&.graphql_name,
44
+ 'graphql.field.name' => field.graphql_name,
45
+ 'graphql.lazy' => false
46
+ }.freeze
47
+ end
48
+ @_otel_field_attrs_cache.compare_by_identity
49
+
50
+ @_otel_lazy_field_attrs_cache = Hash.new do |h, field|
51
+ h[field] = {
52
+ 'graphql.field.parent' => field.owner&.graphql_name,
53
+ 'graphql.field.name' => field.graphql_name,
54
+ 'graphql.lazy' => true
55
+ }.freeze
56
+ end
57
+ @_otel_lazy_field_attrs_cache.compare_by_identity
58
+
21
59
  super
22
60
  end
23
61
 
@@ -73,26 +111,18 @@ module OpenTelemetry
73
111
 
74
112
  def execute_field(field:, query:, ast_node:, arguments:, object:, &block)
75
113
  platform_key = _otel_execute_field_key(field: field)
76
- return super unless platform_key
114
+ return super(field: field, query: query, ast_node: ast_node, object: object, arguments: arguments, &block) unless platform_key
77
115
 
78
- attributes = {
79
- 'graphql.field.parent' => field.owner&.graphql_name,
80
- 'graphql.field.name' => field.graphql_name,
81
- 'graphql.lazy' => false
82
- }
116
+ attributes = @_otel_field_attrs_cache[field]
83
117
 
84
118
  tracer.in_span(platform_key, attributes: attributes, &block)
85
119
  end
86
120
 
87
121
  def execute_field_lazy(field:, query:, ast_node:, arguments:, object:, &block)
88
122
  platform_key = _otel_execute_field_key(field: field)
89
- return super unless platform_key
123
+ return super(field: field, query: query, ast_node: ast_node, object: object, arguments: arguments, &block) unless platform_key
90
124
 
91
- attributes = {
92
- 'graphql.field.parent' => field.owner&.graphql_name,
93
- 'graphql.field.name' => field.graphql_name,
94
- 'graphql.lazy' => true
95
- }
125
+ attributes = @_otel_lazy_field_attrs_cache[field]
96
126
 
97
127
  tracer.in_span(platform_key, attributes: attributes, &block)
98
128
  end
@@ -101,10 +131,7 @@ module OpenTelemetry
101
131
  platform_key = @_otel_authorized_key_cache[type]
102
132
  return super unless platform_key
103
133
 
104
- attributes = {
105
- 'graphql.type.name' => type.graphql_name,
106
- 'graphql.lazy' => false
107
- }
134
+ attributes = @_otel_type_attrs_cache[type]
108
135
 
109
136
  tracer.in_span(platform_key, attributes: attributes, &block)
110
137
  end
@@ -113,33 +140,19 @@ module OpenTelemetry
113
140
  platform_key = @_otel_authorized_key_cache[type]
114
141
  return super unless platform_key
115
142
 
116
- attributes = {
117
- 'graphql.type.name' => type.graphql_name,
118
- 'graphql.lazy' => true
119
- }
120
-
143
+ attributes = @_otel_lazy_type_attrs_cache[type]
121
144
  tracer.in_span(platform_key, attributes: attributes, &block)
122
145
  end
123
146
 
124
147
  def resolve_type(query:, type:, object:, &block)
125
148
  platform_key = @_otel_resolve_type_key_cache[type]
126
-
127
- attributes = {
128
- 'graphql.type.name' => type.graphql_name,
129
- 'graphql.lazy' => false
130
- }
131
-
149
+ attributes = @_otel_type_attrs_cache[type]
132
150
  tracer.in_span(platform_key, attributes: attributes, &block)
133
151
  end
134
152
 
135
153
  def resolve_type_lazy(query:, type:, object:, &block)
136
154
  platform_key = @_otel_resolve_type_key_cache[type]
137
-
138
- attributes = {
139
- 'graphql.type.name' => type.graphql_name,
140
- 'graphql.lazy' => true
141
- }
142
-
155
+ attributes = @_otel_lazy_type_attrs_cache[type]
143
156
  tracer.in_span(platform_key, attributes: attributes, &block)
144
157
  end
145
158
 
@@ -13,6 +13,8 @@ module OpenTelemetry
13
13
  # GraphQLTracer contains the OpenTelemetry tracer implementation compatible with
14
14
  # the GraphQL tracer API
15
15
  class GraphQLTracer < ::GraphQL::Tracing::PlatformTracing
16
+ DEFAULT_HASH = {}.freeze
17
+
16
18
  self.platform_keys = {
17
19
  'lex' => 'graphql.lex',
18
20
  'parse' => 'graphql.parse',
@@ -86,24 +88,60 @@ module OpenTelemetry
86
88
  end
87
89
 
88
90
  def attributes_for(key, data)
89
- attributes = {}
90
91
  case key
91
- when 'execute_field', 'execute_field_lazy'
92
- attributes['graphql.field.parent'] = data[:owner]&.graphql_name # owner is the concrete type, not interface
93
- attributes['graphql.field.name'] = data[:field]&.graphql_name
94
- attributes['graphql.lazy'] = key == 'execute_field_lazy'
95
- when 'authorized', 'authorized_lazy'
96
- attributes['graphql.type.name'] = data[:type]&.graphql_name
97
- attributes['graphql.lazy'] = key == 'authorized_lazy'
98
- when 'resolve_type', 'resolve_type_lazy'
99
- attributes['graphql.type.name'] = data[:type]&.graphql_name
100
- attributes['graphql.lazy'] = key == 'resolve_type_lazy'
92
+ when 'execute_field'
93
+ field_attr_cache = data[:query].context.namespace(:otel_attrs)[:execute_field_attrs] ||= attr_cache do |field|
94
+ attrs = {}
95
+ attrs['graphql.field.parent'] = field.owner.graphql_name if field.owner.graphql_name
96
+ attrs['graphql.field.name'] = field.graphql_name if field.graphql_name
97
+ attrs['graphql.lazy'] = false
98
+ attrs.freeze
99
+ end
100
+ field_attr_cache[data[:field]]
101
+ when 'execute_field_lazy'
102
+ lazy_field_attr_cache = data[:query].context.namespace(:otel_attrs)[:execute_field_lazy_attrs] ||= attr_cache do |field|
103
+ attrs = {}
104
+ attrs['graphql.field.parent'] = field.owner.graphql_name if field.owner.graphql_name
105
+ attrs['graphql.field.name'] = field.graphql_name if field.graphql_name
106
+ attrs['graphql.lazy'] = true
107
+ attrs.freeze
108
+ end
109
+ lazy_field_attr_cache[data[:field]]
110
+ when 'authorized', 'resolve_type'
111
+ type_attrs_cache = data[:context].namespace(:otel_attrs)[:type_attrs] ||= attr_cache do |type|
112
+ attrs = {}
113
+ attrs['graphql.type.name'] = type.graphql_name if type.graphql_name
114
+ attrs['graphql.lazy'] = false
115
+ attrs.freeze
116
+ end
117
+ type_attrs_cache[data[:type]]
118
+ when 'authorized_lazy', 'resolve_type_lazy'
119
+ type_lazy_attrs_cache = data[:context].namespace(:otel_attrs)[:type_lazy_attrs] ||= attr_cache do |type|
120
+ attrs = {}
121
+ attrs['graphql.type.name'] = type.graphql_name if type.graphql_name
122
+ attrs['graphql.lazy'] = true
123
+ attrs.freeze
124
+ end
125
+ type_lazy_attrs_cache[data[:type]]
101
126
  when 'execute_query'
102
- attributes['graphql.operation.name'] = data[:query].selected_operation_name if data[:query].selected_operation_name
103
- attributes['graphql.operation.type'] = data[:query].selected_operation.operation_type
104
- attributes['graphql.document'] = data[:query].query_string
127
+ attrs = {}
128
+ attrs['graphql.document'] = data[:query].query_string if data[:query].query_string
129
+ # rubocop:disable Style/SafeNavigation - using safe navigation creates more objects, we want to avoid this
130
+ attrs['graphql.operation.type'] = data[:query].selected_operation.operation_type if data[:query].selected_operation && data[:query].selected_operation.operation_type
131
+ # rubocop:enable Style/SafeNavigation
132
+ attrs['graphql.operation.name'] = data[:query].selected_operation_name || 'anonymous'
133
+ attrs.freeze
134
+ else
135
+ DEFAULT_HASH
136
+ end
137
+ end
138
+
139
+ def attr_cache
140
+ cache_h = Hash.new do |h, k|
141
+ h[k] = yield(k)
105
142
  end
106
- attributes
143
+ cache_h.compare_by_identity
144
+ cache_h
107
145
  end
108
146
  end
109
147
  end
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module GraphQL
10
- VERSION = '0.26.8'
10
+ VERSION = '0.28.0'
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.26.8
4
+ version: 0.28.0
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-11-23 00:00:00.000000000 Z
11
+ date: 2024-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -148,28 +148,28 @@ dependencies:
148
148
  requirements:
149
149
  - - "~>"
150
150
  - !ruby/object:Gem::Version
151
- version: 1.56.1
151
+ version: 1.60.1
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.56.1
158
+ version: 1.60.1
159
159
  - !ruby/object:Gem::Dependency
160
160
  name: rubocop-performance
161
161
  requirement: !ruby/object:Gem::Requirement
162
162
  requirements:
163
163
  - - "~>"
164
164
  - !ruby/object:Gem::Version
165
- version: 1.19.1
165
+ version: '1.20'
166
166
  type: :development
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
169
169
  requirements:
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
- version: 1.19.1
172
+ version: '1.20'
173
173
  - !ruby/object:Gem::Dependency
174
174
  name: simplecov
175
175
  requirement: !ruby/object:Gem::Requirement
@@ -234,10 +234,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
234
234
  licenses:
235
235
  - Apache-2.0
236
236
  metadata:
237
- changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-graphql/0.26.8/file/CHANGELOG.md
237
+ changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-graphql/0.28.0/file/CHANGELOG.md
238
238
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/graphql
239
239
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
240
- documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-graphql/0.26.8
240
+ documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-graphql/0.28.0
241
241
  post_install_message:
242
242
  rdoc_options: []
243
243
  require_paths: