Skip to content

Commit

Permalink
Add compatibility for .trace_with in graphql-ruby 2.3+
Browse files Browse the repository at this point in the history
  • Loading branch information
janko committed Apr 2, 2024
1 parent 5ead781 commit 799f681
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/graphql.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
----
8 changes: 8 additions & 0 deletions lib/elastic_apm/graphql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/graphql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def post(slug:)

class GraphQLTestAppSchema < GraphQL::Schema
query QueryType
tracer ElasticAPM::GraphQL
trace_with ElasticAPM::GraphQL
end
end

Expand Down

0 comments on commit 799f681

Please sign in to comment.