Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility for .trace_with in graphql-ruby 2.3+ #1446

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading