diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 32bc5cade..6fb17f139 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -34,6 +34,10 @@ endif::[] [[release-notes-4.x]] === Ruby Agent version 4.x +[float] +===== Fixed +- Compatibility with `.trace_with` introduced in graphql-ruby 2.3+ {pull}1446[#1446] + [[release-notes-4.7.2] ==== 4.7.2 diff --git a/docs/graphql.asciidoc b/docs/graphql.asciidoc index 4aa096e8a..8eaed9a4a 100644 --- a/docs/graphql.asciidoc +++ b/docs/graphql.asciidoc @@ -18,6 +18,6 @@ To enable GraphQL support, add the included Tracer to your schema: class MySchema < GraphQL::Schema # ... - tracer ElasticAPM::GraphQL # <-- include this + trace_with ElasticAPM::GraphQL # <-- include this end ---- diff --git a/lib/elastic_apm/graphql.rb b/lib/elastic_apm/graphql.rb index 30127d2a3..e57bb29e7 100644 --- a/lib/elastic_apm/graphql.rb +++ b/lib/elastic_apm/graphql.rb @@ -48,6 +48,14 @@ module GraphQL # "authorized" => "graphql.authorized", }.freeze + KEYS_TO_NAME.each_key do |trace_method| + module_eval <<-RUBY, __FILE__, __LINE__ + def #{trace_method}(**data) + ::ElasticAPM::GraphQL.trace("#{trace_method}", data) { super } + end + RUBY + end + # rubocop:disable Style/ExplicitBlockArgument def self.trace(key, data) return yield unless KEYS_TO_NAME.key?(key) diff --git a/spec/integration/graphql_spec.rb b/spec/integration/graphql_spec.rb index a521c93f7..ed225c763 100644 --- a/spec/integration/graphql_spec.rb +++ b/spec/integration/graphql_spec.rb @@ -95,7 +95,7 @@ def post(slug:) class GraphQLTestAppSchema < GraphQL::Schema query QueryType - tracer ElasticAPM::GraphQL + trace_with ElasticAPM::GraphQL end end