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

Use GraphQL::Tracing::DataDogTrace when it's available #3432

Closed
Closed
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
30 changes: 5 additions & 25 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -902,18 +902,8 @@ 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,
trace_with(
GraphQL::Tracing::DatadogTrace,
service: 'graphql'
)
end
Expand All @@ -923,22 +913,12 @@ Or you can modify an already defined schema:

```ruby
# Class-based schema
YourSchema.use(
GraphQL::Tracing::DataDogTracing,
service: 'graphql'
YourSchema.trace_with(
GraphQL::Tracing::DatadogTrace,
service: 'graphql'
)
```

```ruby
# .define-style schema
YourSchema.define do
use(
GraphQL::Tracing::DataDogTracing,
service: 'graphql'
)
end
```

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
Expand Down
12 changes: 11 additions & 1 deletion lib/datadog/tracing/contrib/graphql/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ def patch_schema!(schema)
analytics_enabled = Contrib::Analytics.enabled?(get_option(:analytics_enabled))
analytics_sample_rate = get_option(:analytics_sample_rate)

if schema.respond_to?(:use)
if schema.respond_to?(:trace_with)
schema.trace_with(
::GraphQL::Tracing::DataDogTrace,
# By default, Tracing::DataDogTrace holds a reference to a tracer.
# If we provide a tracer argument here it will be eagerly cached,
# and Tracing::DataDogTracing will send traces to a stale tracer instance.
service: service_name,
analytics_enabled: analytics_enabled,
analytics_sample_rate: analytics_sample_rate
)
elsif schema.respond_to?(:use)
schema.use(
::GraphQL::Tracing::DataDogTracing,
# By default, Tracing::DataDogTracing holds a reference to a tracer.
Expand Down
16 changes: 15 additions & 1 deletion spec/datadog/tracing/contrib/graphql/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
describe '.loaded?' do
subject(:loaded?) { described_class.loaded? }

context 'when neither GraphQL or GraphQL::Tracing::DataDogTracing are defined' do
context 'when neither GraphQL, GraphQL::Tracing::DataDogTracing, nor GraphQL::Tracing::DataDogTrace are defined' do
before do
hide_const('GraphQL')
hide_const('GraphQL::Tracing::DataDogTracing')
hide_const('GraphQL::Tracing::DataDogTrace')
end

it { is_expected.to be false }
Expand All @@ -35,6 +36,7 @@
before do
stub_const('GraphQL', Class.new)
hide_const('GraphQL::Tracing::DataDogTracing')
hide_const('GraphQL::Tracing::DataDogTrace')
end

it { is_expected.to be false }
Expand All @@ -45,6 +47,18 @@

it { is_expected.to be true }
end

context 'when GraphQL::Tracing::DataDogTrace is defined' do
context 'when only GraphQL is defined' do
before do
stub_const('GraphQL', Class.new)
hide_const('GraphQL::Tracing::DataDogTracing')
stub_const('GraphQL::Tracing::DataDogTrace', Class.new)
end

it { is_expected.to be true }
end
end
end

describe '.compatible?' do
Expand Down
Loading