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

Guard GraphQL Settings Lookup #787

Merged
merged 5 commits into from
Mar 30, 2023
Merged
Changes from 3 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
10 changes: 8 additions & 2 deletions newrelic/hooks/framework_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def bind_operation_v2(exe_context, operation, root_value):
def wrap_execute_operation(wrapped, instance, args, kwargs):
transaction = current_transaction()
trace = current_trace()
TimPansino marked this conversation as resolved.
Show resolved Hide resolved
settings = transaction.settings

if not transaction:
return wrapped(*args, **kwargs)
Expand Down Expand Up @@ -136,7 +135,14 @@ def wrap_execute_operation(wrapped, instance, args, kwargs):
if operation.selection_set is not None:
fields = operation.selection_set.selections
# Ignore transactions for introspection queries
if not settings.instrumentation.graphql.capture_introspection_queries:
capture_introspection_queries = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this just be left as it was before since the transaction we know must exist now if it got this far? Looking at other places in the code we don't seem to guard against the settings path not existing like this so wondering if this is really needed.

if not transaction.settings.instrumentation.graphql.capture_introspection_queries:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do sometimes and sometimes not, it's a mixed bag of style across the agent. I'm not sure it's any safer as long as the top level settings exists so maybe we can leave it at that.

transaction
and transaction.settings
and transaction.settings.instrumentation
and transaction.settings.instrumentation.graphql
and transaction.settings.instrumentation.graphql.capture_introspection_queries
)
if not capture_introspection_queries:
# If all selected fields are introspection fields
if all(get_node_value(field, "name") in GRAPHQL_INTROSPECTION_FIELDS for field in fields):
ignore_transaction()
Expand Down