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

ActiveOperationLimiter does not work when I have enabled SentryTrace #4826

Closed
cyruxwong opened this issue Feb 6, 2024 · 6 comments · Fixed by #4830
Closed

ActiveOperationLimiter does not work when I have enabled SentryTrace #4826

cyruxwong opened this issue Feb 6, 2024 · 6 comments · Fixed by #4830

Comments

@cyruxwong
Copy link

cyruxwong commented Feb 6, 2024

Describe the bug

Once I have enabled both rate limiting (ActiveOperationLimiter) and tracing (SentryTrace) at the same time, the ActiveOperationLimiter does not work.

Versions

graphql version: 2.2.7
graphql-pro version: 1.25.2
graphql-enterprise version: 1.3.1 / 1.3.3
rails (or other framework): 7.1.3

GraphQL schema

class ApplicationSchema < GraphQL::Schema
  query QueryType

  use GraphQL::Enterprise::ActiveOperationLimiter, redis:
  trace_with GraphQL::Tracing::SentryTrace
end

GraphQL query

Any query

Steps to reproduce

Just execute any query to the schema.

Expected behavior

The ActiveOperationLimiter should work as expected even though I have enabled SentryTrace.

Actual behavior

There is no exception, but the ActiveOperationLimiter stopped working.
I set the breakpoint in the debugger and confirmed the methods in ActiveOperationLimiter were not triggered.

BTW, there is an unexpected warning message when I started the Rails server:

Schema.instrument is deprecated, use `trace_with` instead: https://graphql-ruby.org/queries/tracing.html"
  (From `PublicSchema.instrument(query, #<GraphQL::Enterprise::ActiveOperationLimiter::Instrumenter:0x000000012ed3b768>)` at /Users/cyrux.wong/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/graphql-enterprise-1.3.1/lib/graphql/enterprise/active_operation_limiter.rb:51:in `initialize')

Additional context

The rate limiting will be enabled if I did any of the following:

  • Disable SentryTrace
  • Swap the lines of configuration in the schema, i.e. trace_with SentryTrace first and then use ActiveOperationLimiter
@rmosolgo
Copy link
Owner

rmosolgo commented Feb 6, 2024

Hi! Thanks for reporting this. These two should definitely work together, regardless of their order. I'll take a look at their implementation and see why they're getting mixed up. Thanks for sharing the work-arounds that worked for you.

For the deprecation, you could try updating to graphql-enterprise v1.3.2 -- it includes a patch to use the new tracing API instead of the deprecated one (https://github.com/rmosolgo/graphql-ruby/blob/master/CHANGELOG-enterprise.md#132-15-jan-2024). Let me know if you still see that warning after updating.

In the meantime, I'll take a look at this compatibility issue soon and follow up here!

@cyruxwong
Copy link
Author

I have updated my local machine and the warning message is gone.

But FYI I still encountered the original problem with graphql-enterprise gem v1.3.3.

Anyway, thanks @rmosolgo 🙏

@FraDim
Copy link

FraDim commented Feb 7, 2024

Hey @rmosolgo,

I am getting the same issue with the Sentry trace and the GraphQL object cache.

This code does not work:

class ApplicationSchema < GraphQL::Schema
  query QueryType

  use(GraphQL::Enterprise::ObjectCache, memory: true)
  trace_with GraphQL::Tracing::SentryTrace
end

The code above calculates the cache hit correctly, but never writes to the cache, because it never calls the GraphQL::Enterprise::ObjectCache#write method.

This code works as expected:

class ApplicationSchema < GraphQL::Schema
  query QueryType

  trace_with GraphQL::Tracing::SentryTrace
  use(GraphQL::Enterprise::ObjectCache, memory: true)
end

indicating that the order of the statements matter.

I am also using the v1.3.3 enterprise version.

@rmosolgo
Copy link
Owner

rmosolgo commented Feb 7, 2024

Hey, thanks again for reporting this. I just released graphql-ruby 2.2.8 which includes #4830. Please give it a try on that new version and let me know if you run into any more trouble!

@cyruxwong
Copy link
Author

It is working fine now. thanks @rmosolgo

@rmosolgo
Copy link
Owner

Glad to hear it -- please let me know if you run into any more trouble!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants