-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
367 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module Tracing | ||
module Contrib | ||
module GraphQL | ||
# Provides instrumentation for `graphql` through with GraphQL's trace | ||
module TracePatcher | ||
module_function | ||
|
||
def patch!(schemas, options) | ||
if schemas.empty? | ||
::GraphQL::Schema.trace_with(::GraphQL::Tracing::DataDogTrace, **options) | ||
else | ||
schemas.each do |schema| | ||
schema.trace_with(::GraphQL::Tracing::DataDogTrace, **options) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module Tracing | ||
module Contrib | ||
module GraphQL | ||
# Provides instrumentation for `graphql` through the GraphQL's tracing | ||
module TracingPatcher | ||
module_function | ||
|
||
def patch!(schemas, options) | ||
if schemas.empty? | ||
::GraphQL::Schema.tracer(::GraphQL::Tracing::DataDogTracing.new(**options)) | ||
else | ||
schemas.each do |schema| | ||
if schema.respond_to? :use | ||
schema.use(::GraphQL::Tracing::DataDogTracing, **options) | ||
else | ||
Datadog.logger.warn("Unable to patch #{schema}: Please migrate to class-based schema.") | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
require 'datadog/tracing/contrib/support/spec_helper' | ||
require 'datadog/tracing/contrib/graphql/test_schema_examples' | ||
require 'datadog/tracing/contrib/graphql/tracing_patcher' | ||
require 'datadog/tracing/contrib/graphql/trace_patcher' | ||
|
||
require 'ddtrace' | ||
|
||
RSpec.describe Datadog::Tracing::Contrib::GraphQL::Patcher do | ||
around do |example| | ||
remove_patch!(:graphql) | ||
Datadog.configuration.reset! | ||
Datadog.configuration.tracing[:graphql].reset! | ||
|
||
without_warnings do | ||
example.run | ||
end | ||
|
||
remove_patch!(:graphql) | ||
Datadog.configuration.reset! | ||
Datadog.configuration.tracing[:graphql].reset! | ||
end | ||
|
||
describe 'patch' do | ||
context 'when graphql does not support trace' do | ||
context 'with default configuration' do | ||
it 'patches GraphQL' do | ||
allow(Datadog::Tracing::Contrib::GraphQL::Integration).to receive(:trace_supported?).and_return(true) | ||
expect(Datadog::Tracing::Contrib::GraphQL::TracePatcher).to receive(:patch!).with( | ||
[], | ||
hash_including(:analytics_enabled, :analytics_sample_rate, :service) | ||
) | ||
|
||
Datadog.configure do |c| | ||
c.tracing.instrument :graphql | ||
end | ||
end | ||
end | ||
|
||
context 'with with_deprecated_tracer enabled' do | ||
it do | ||
allow(Datadog::Tracing::Contrib::GraphQL::Integration).to receive(:trace_supported?).and_return(true) | ||
expect(Datadog::Tracing::Contrib::GraphQL::TracingPatcher).to receive(:patch!).with( | ||
[], | ||
hash_including(:analytics_enabled, :analytics_sample_rate, :service) | ||
) | ||
|
||
Datadog.configure do |c| | ||
c.tracing.instrument :graphql, with_deprecated_tracer: true | ||
end | ||
end | ||
end | ||
|
||
context 'with with_deprecated_tracer disabled' do | ||
it do | ||
allow(Datadog::Tracing::Contrib::GraphQL::Integration).to receive(:trace_supported?).and_return(true) | ||
expect(Datadog::Tracing::Contrib::GraphQL::TracePatcher).to receive(:patch!).with( | ||
[], | ||
hash_including(:analytics_enabled, :analytics_sample_rate, :service) | ||
) | ||
|
||
Datadog.configure do |c| | ||
c.tracing.instrument :graphql, with_deprecated_tracer: false | ||
end | ||
end | ||
end | ||
|
||
context 'with given schema' do | ||
it do | ||
allow(Datadog::Tracing::Contrib::GraphQL::Integration).to receive(:trace_supported?).and_return(true) | ||
expect(Datadog::Tracing::Contrib::GraphQL::TracePatcher).to receive(:patch!).with( | ||
[TestGraphQLSchema], | ||
hash_including(:analytics_enabled, :analytics_sample_rate, :service) | ||
) | ||
|
||
Datadog.configure do |c| | ||
c.tracing.instrument :graphql, schemas: [TestGraphQLSchema] | ||
end | ||
end | ||
end | ||
end | ||
|
||
context 'when graphql supports trace' do | ||
context 'with default configuration' do | ||
it 'patches GraphQL' do | ||
allow(Datadog::Tracing::Contrib::GraphQL::Integration).to receive(:trace_supported?).and_return(false) | ||
expect(Datadog::Tracing::Contrib::GraphQL::TracingPatcher).to receive(:patch!).with( | ||
[], | ||
hash_including(:analytics_enabled, :analytics_sample_rate, :service) | ||
) | ||
expect_any_instance_of(Datadog::Core::Logger).to receive(:warn) | ||
.with(/Falling back to GraphQL::Tracing::DataDogTracing/) | ||
|
||
Datadog.configure do |c| | ||
c.tracing.instrument :graphql | ||
end | ||
end | ||
end | ||
|
||
context 'with with_deprecated_tracer enabled' do | ||
it do | ||
allow(Datadog::Tracing::Contrib::GraphQL::Integration).to receive(:trace_supported?).and_return(false) | ||
expect(Datadog::Tracing::Contrib::GraphQL::TracingPatcher).to receive(:patch!).with( | ||
[], | ||
hash_including(:analytics_enabled, :analytics_sample_rate, :service) | ||
) | ||
expect_any_instance_of(Datadog::Core::Logger).not_to receive(:warn) | ||
|
||
Datadog.configure do |c| | ||
c.tracing.instrument :graphql, with_deprecated_tracer: true | ||
end | ||
end | ||
end | ||
|
||
context 'with with_deprecated_tracer disabled' do | ||
it do | ||
allow(Datadog::Tracing::Contrib::GraphQL::Integration).to receive(:trace_supported?).and_return(false) | ||
expect(Datadog::Tracing::Contrib::GraphQL::TracingPatcher).to receive(:patch!).with( | ||
[], | ||
hash_including(:analytics_enabled, :analytics_sample_rate, :service) | ||
) | ||
expect_any_instance_of(Datadog::Core::Logger).to receive(:warn) | ||
.with(/Falling back to GraphQL::Tracing::DataDogTracing/) | ||
|
||
Datadog.configure do |c| | ||
c.tracing.instrument :graphql, with_deprecated_tracer: false | ||
end | ||
end | ||
end | ||
|
||
context 'with given schema' do | ||
it do | ||
allow(Datadog::Tracing::Contrib::GraphQL::Integration).to receive(:trace_supported?).and_return(false) | ||
expect(Datadog::Tracing::Contrib::GraphQL::TracingPatcher).to receive(:patch!).with( | ||
[TestGraphQLSchema], | ||
hash_including(:analytics_enabled, :analytics_sample_rate, :service) | ||
) | ||
expect_any_instance_of(Datadog::Core::Logger).to receive(:warn) | ||
.with(/Falling back to GraphQL::Tracing::DataDogTracing/) | ||
|
||
Datadog.configure do |c| | ||
c.tracing.instrument :graphql, schemas: [TestGraphQLSchema] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.