Skip to content

Commit a22fef6

Browse files
committed
Add compatibility for .trace_with in graphql-ruby 2.3+
1 parent cb57272 commit a22fef6

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

CHANGELOG.asciidoc

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ endif::[]
3434
[[release-notes-4.x]]
3535
=== Ruby Agent version 4.x
3636
37+
[float]
38+
===== Fixed
39+
- Compatibility with `.trace_with` introduced in graphql-ruby 2.3+ {pull}1446[#1446]
40+
3741
[[release-notes-4.7.2]
3842
==== 4.7.2
3943

docs/graphql.asciidoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ To enable GraphQL support, add the included Tracer to your schema:
1818
class MySchema < GraphQL::Schema
1919
# ...
2020
21-
tracer ElasticAPM::GraphQL # <-- include this
21+
trace_with ElasticAPM::GraphQL # <-- include this
2222
end
2323
----

lib/elastic_apm/graphql.rb

+8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ module GraphQL
4848
# "authorized" => "graphql.authorized",
4949
}.freeze
5050

51+
KEYS_TO_NAME.each_key do |trace_method|
52+
module_eval <<-RUBY, __FILE__, __LINE__
53+
def #{trace_method}(**data)
54+
::ElasticAPM::GraphQL.trace("#{trace_method}", data) { super }
55+
end
56+
RUBY
57+
end
58+
5159
# rubocop:disable Style/ExplicitBlockArgument
5260
def self.trace(key, data)
5361
return yield unless KEYS_TO_NAME.key?(key)

spec/integration/graphql_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def post(slug:)
9595

9696
class GraphQLTestAppSchema < GraphQL::Schema
9797
query QueryType
98-
tracer ElasticAPM::GraphQL
98+
trace_with ElasticAPM::GraphQL
9999
end
100100
end
101101

0 commit comments

Comments
 (0)