Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Jan 26, 2024
1 parent 72f7307 commit 5cadd88
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 40 deletions.
2 changes: 1 addition & 1 deletion docs/Compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
32 changes: 3 additions & 29 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand All @@ -857,41 +857,15 @@ 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
```

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.
Expand Down
15 changes: 12 additions & 3 deletions lib/datadog/tracing/contrib/graphql/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
34 changes: 28 additions & 6 deletions spec/datadog/tracing/contrib/graphql/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion spec/support/loaded_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5cadd88

Please sign in to comment.