Skip to content

Commit 15c0967

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

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

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)