From 19980af6b0fc5186432105166ac3b0acd4194620 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Fri, 26 Jan 2024 17:51:45 +0100 Subject: [PATCH 1/5] Update support matrix --- docs/Compatibility.md | 2 +- docs/GettingStarted.md | 32 ++--------------- .../tracing/contrib/graphql/integration.rb | 15 ++++++-- .../contrib/graphql/integration_spec.rb | 34 +++++++++++++++---- spec/support/loaded_gem.rb | 3 +- 5 files changed, 46 insertions(+), 40 deletions(-) diff --git a/docs/Compatibility.md b/docs/Compatibility.md index b89d75b9f4a..02e461dfb33 100644 --- a/docs/Compatibility.md +++ b/docs/Compatibility.md @@ -77,7 +77,7 @@ For a list of available integrations, and their configuration options, refer to | Excon | `excon` | `>= 0.50` | `>= 0.50` | [Link][16] | [Link](https://github.com/excon/excon) | | Faraday | `faraday` | `>= 0.14` | `>= 0.14` | [Link][17] | [Link](https://github.com/lostisland/faraday) | | Grape | `grape` | `>= 1.0` | `>= 1.0` | [Link][18] | [Link](https://github.com/ruby-grape/grape) | -| GraphQL | `graphql` | `>= 1.7.9` | `>= 1.7.9` | [Link][19] | [Link](https://github.com/rmosolgo/graphql-ruby) | +| GraphQL | `graphql` | `>= 2.2.6` | `>= 2.2.6` | [Link][19] | [Link](https://github.com/rmosolgo/graphql-ruby) | | gRPC | `grpc` | `>= 1.7` | *gem not available* | [Link][20] | [Link](https://github.com/grpc/grpc/tree/master/src/rubyc) | | hanami | `hanami` | `>= 1`, `< 2` | `>= 1`, `< 2` | [Link][21] | [Link](https://github.com/hanami/hanami) | | http.rb | `httprb` | `>= 2.0` | `>= 2.0` | [Link][22] | [Link](https://github.com/httprb/http) | diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index a87c047ac92..2e5ec3afe98 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -847,7 +847,7 @@ The `instrument :graphql` method accepts the following parameters. Additional op | Key | Description | Default | | --- | ----------- | ------- | -| `schemas` | Required. Array of `GraphQL::Schema` objects which to trace. Tracing will be added to all the schemas listed, using the options provided to this configuration. If you do not provide any, then tracing will not be activated. | `[]` | +| `schemas` | Array of `GraphQL::Schema` objects (Only supporting class-based schema) which to trace. If you do not provide any, then tracing will applied to all the schemas. | `[]` | | `service_name` | Service name used for graphql instrumentation | `'ruby-graphql'` | **Manually configuring GraphQL schemas** @@ -857,20 +857,7 @@ If you prefer to individually configure the tracer settings for a schema (e.g. y ```ruby # Class-based schema class YourSchema < GraphQL::Schema - use( - GraphQL::Tracing::DataDogTracing, - service: 'graphql' - ) -end -``` - -```ruby -# .define-style schema -YourSchema = GraphQL::Schema.define do - use( - GraphQL::Tracing::DataDogTracing, - service: 'graphql' - ) + use(GraphQL::Tracing::DataDogTracing) end ``` @@ -878,20 +865,7 @@ Or you can modify an already defined schema: ```ruby # Class-based schema -YourSchema.use( - GraphQL::Tracing::DataDogTracing, - service: 'graphql' -) -``` - -```ruby -# .define-style schema -YourSchema.define do - use( - GraphQL::Tracing::DataDogTracing, - service: 'graphql' - ) -end +YourSchema.use(GraphQL::Tracing::DataDogTracing) ``` Do *NOT* `instrument :graphql` in `Datadog.configure` if you choose to configure manually, as to avoid double tracing. These two means of configuring GraphQL tracing are considered mutually exclusive. diff --git a/lib/datadog/tracing/contrib/graphql/integration.rb b/lib/datadog/tracing/contrib/graphql/integration.rb index 473df4e5c9a..2896bc2cd79 100644 --- a/lib/datadog/tracing/contrib/graphql/integration.rb +++ b/lib/datadog/tracing/contrib/graphql/integration.rb @@ -10,8 +10,6 @@ module GraphQL class Integration include Contrib::Integration - MINIMUM_VERSION = Gem::Version.new('1.7.9') - # @public_api Changing the integration name or integration options can cause breaking changes register_as :graphql, auto_patch: true @@ -24,8 +22,19 @@ def self.loaded? && !defined?(::GraphQL::Tracing::DataDogTracing).nil? end + # Breaking changes are introduce in `2.2.6` and have been backported to + # + # * 1.13.21 + # * 2.0.28 + # * 2.1.11 + # def self.compatible? - super && version >= MINIMUM_VERSION + super && ( + (version >= Gem::Version.new('1.13.21') && version < Gem::Version.new('2.0')) || + (version >= Gem::Version.new('2.0.28') && version < Gem::Version.new('2.1')) || + (version >= Gem::Version.new('2.1.11') && version < Gem::Version.new('2.2')) || + (version >= Gem::Version.new('2.2.6')) + ) end def new_configuration diff --git a/spec/datadog/tracing/contrib/graphql/integration_spec.rb b/spec/datadog/tracing/contrib/graphql/integration_spec.rb index ce1faff27da..c480d815328 100644 --- a/spec/datadog/tracing/contrib/graphql/integration_spec.rb +++ b/spec/datadog/tracing/contrib/graphql/integration_spec.rb @@ -9,7 +9,7 @@ subject(:version) { described_class.version } context 'when the "graphql" gem is loaded' do - include_context 'loaded gems', graphql: described_class::MINIMUM_VERSION + include_context 'loaded gems', graphql: '2.2.6' it { is_expected.to be_a_kind_of(Gem::Version) } end @@ -49,15 +49,37 @@ describe '.compatible?' do subject(:compatible?) { described_class.compatible? } - context 'when "graphql" gem is loaded with a version' do - context 'that is less than the minimum' do - include_context 'loaded gems', graphql: decrement_gem_version(described_class::MINIMUM_VERSION) + backport_support = { + '1.13.21' => '2.0', + '2.0.28' => '2.1', + '2.1.11' => '2.2', + } + + backport_support.each do |backported_version, broken_version| + context "when #{backported_version}" do + include_context 'loaded gems', graphql: backported_version + it { is_expected.to be true } + end + + context "when #{decrement_gem_version(backported_version)}" do + include_context 'loaded gems', graphql: decrement_gem_version(backported_version) + it { is_expected.to be false } + end + + context "when #{broken_version}" do + include_context 'loaded gems', graphql: broken_version + it { is_expected.to be false } + end + end + + context "when #{decrement_gem_version('2.2.6')}" do + include_context 'loaded gems', graphql: decrement_gem_version('2.2.6') it { is_expected.to be false } end - context 'that meets the minimum version' do - include_context 'loaded gems', graphql: described_class::MINIMUM_VERSION + context 'when 2.2.6' do + include_context 'loaded gems', graphql: '2.2.6' it { is_expected.to be true } end end diff --git a/spec/support/loaded_gem.rb b/spec/support/loaded_gem.rb index 535f831e3c8..5f8edde03d2 100644 --- a/spec/support/loaded_gem.rb +++ b/spec/support/loaded_gem.rb @@ -25,13 +25,14 @@ module LoadedGem module Helpers def decrement_gem_version(version) - segments = version.segments.dup + segments = Gem::Version.new(version).segments.dup segments.reverse.each_with_index do |value, i| if value.to_i > 0 segments[segments.length - 1 - i] -= 1 break end end + Gem::Version.new(segments.join('.')) end From 1e5de552d82ae7176f0f182cdc9c1d8979809822 Mon Sep 17 00:00:00 2001 From: TonyCTHsu Date: Fri, 26 Jan 2024 22:13:34 +0100 Subject: [PATCH 2/5] Update docs/GettingStarted.md Co-authored-by: Austin Lai <76412946+alai97@users.noreply.github.com> --- docs/GettingStarted.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 2e5ec3afe98..1e19ea8cc3c 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -847,7 +847,7 @@ The `instrument :graphql` method accepts the following parameters. Additional op | Key | Description | Default | | --- | ----------- | ------- | -| `schemas` | Array of `GraphQL::Schema` objects (Only supporting class-based schema) which to trace. If you do not provide any, then tracing will applied to all the schemas. | `[]` | +| `schemas` | Array of `GraphQL::Schema` objects (that support class-based schema only) to trace. If you do not provide any, then tracing will applied to all the schemas. | `[]` | | `service_name` | Service name used for graphql instrumentation | `'ruby-graphql'` | **Manually configuring GraphQL schemas** From 735c68c37710a96ea6a799ddbaeaaad58d759830 Mon Sep 17 00:00:00 2001 From: TonyCTHsu Date: Fri, 26 Jan 2024 22:13:40 +0100 Subject: [PATCH 3/5] Update lib/datadog/tracing/contrib/graphql/integration.rb Co-authored-by: Brett Blue <84536271+brett0000FF@users.noreply.github.com> --- lib/datadog/tracing/contrib/graphql/integration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/datadog/tracing/contrib/graphql/integration.rb b/lib/datadog/tracing/contrib/graphql/integration.rb index 2896bc2cd79..1ffc5b63fe6 100644 --- a/lib/datadog/tracing/contrib/graphql/integration.rb +++ b/lib/datadog/tracing/contrib/graphql/integration.rb @@ -22,7 +22,7 @@ def self.loaded? && !defined?(::GraphQL::Tracing::DataDogTracing).nil? end - # Breaking changes are introduce in `2.2.6` and have been backported to + # Breaking changes are introduced in `2.2.6` and have been backported to # # * 1.13.21 # * 2.0.28 From 3a8ed422c09dbf9a1ba61495b9cc9e5f362fede1 Mon Sep 17 00:00:00 2001 From: TonyCTHsu Date: Fri, 26 Jan 2024 22:13:55 +0100 Subject: [PATCH 4/5] Update docs/GettingStarted.md Co-authored-by: Brett Blue <84536271+brett0000FF@users.noreply.github.com> --- docs/GettingStarted.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 1e19ea8cc3c..57d9871986b 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -868,6 +868,8 @@ Or you can modify an already defined schema: YourSchema.use(GraphQL::Tracing::DataDogTracing) ``` +**Note**: This integration does not support define-style schemas. Only class-based schemas are supported. + Do *NOT* `instrument :graphql` in `Datadog.configure` if you choose to configure manually, as to avoid double tracing. These two means of configuring GraphQL tracing are considered mutually exclusive. ### gRPC From 640c864a0e23c2028905839acb8d6f64e72f6fb1 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Fri, 26 Jan 2024 22:21:09 +0100 Subject: [PATCH 5/5] Update compatibility --- docs/Compatibility.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Compatibility.md b/docs/Compatibility.md index 02e461dfb33..857d2105209 100644 --- a/docs/Compatibility.md +++ b/docs/Compatibility.md @@ -77,7 +77,7 @@ For a list of available integrations, and their configuration options, refer to | Excon | `excon` | `>= 0.50` | `>= 0.50` | [Link][16] | [Link](https://github.com/excon/excon) | | Faraday | `faraday` | `>= 0.14` | `>= 0.14` | [Link][17] | [Link](https://github.com/lostisland/faraday) | | Grape | `grape` | `>= 1.0` | `>= 1.0` | [Link][18] | [Link](https://github.com/ruby-grape/grape) | -| GraphQL | `graphql` | `>= 2.2.6` | `>= 2.2.6` | [Link][19] | [Link](https://github.com/rmosolgo/graphql-ruby) | +| GraphQL | `graphql` | `>= 2.2.6`, `2.1.11+`,`2.0.28+`, `1.13.21+`| `>= 2.2.6`, `2.1.11+`,`2.0.28+`, `1.13.21+`| [Link][19] | [Link](https://github.com/rmosolgo/graphql-ruby) | | gRPC | `grpc` | `>= 1.7` | *gem not available* | [Link][20] | [Link](https://github.com/grpc/grpc/tree/master/src/rubyc) | | hanami | `hanami` | `>= 1`, `< 2` | `>= 1`, `< 2` | [Link][21] | [Link](https://github.com/hanami/hanami) | | http.rb | `httprb` | `>= 2.0` | `>= 2.0` | [Link][22] | [Link](https://github.com/httprb/http) |