From 5cadd880f8765c3e72de690c2bcde459d72c808b Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Fri, 26 Jan 2024 17:51:45 +0100 Subject: [PATCH] WIP --- 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