Skip to content

Commit 765611e

Browse files
umaannamalaiTimPansino
authored andcommitted
  (#289)
Add GraphQL framework metric.
1 parent 108d2ed commit 765611e

File tree

2 files changed

+11
-23
lines changed

2 files changed

+11
-23
lines changed

newrelic/hooks/framework_graphql.py

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,6 @@ def ignore_graphql_duplicate_exception(exc, val, tb):
5151
return None # Follow original exception matching rules
5252

5353

54-
def ignore_graphql_duplicate_exception(exc, val, tb):
55-
from graphql.error import GraphQLError
56-
57-
if isinstance(val, GraphQLError):
58-
transaction = current_transaction()
59-
60-
# Check that we have not recorded this exception
61-
# previously for this transaction due to multiple
62-
# error traces triggering. This happens if an exception
63-
# is reraised by GraphQL as a new GraphQLError type
64-
# after the original exception has already been recorded.
65-
66-
if transaction and hasattr(val, "original_error"):
67-
_, _, fullnames, message = parse_exc_info((None, val.original_error, None))
68-
fullname = fullnames[0]
69-
for error in transaction._errors:
70-
if error.type == fullname and error.message == message:
71-
return True
72-
73-
return None # Follow original exception matching rules
74-
75-
7654
def wrap_executor_context_init(wrapped, instance, args, kwargs):
7755
result = wrapped(*args, **kwargs)
7856

@@ -288,6 +266,11 @@ def wrap_graphql_impl(wrapped, instance, args, kwargs):
288266
if not transaction:
289267
return wrapped(*args, **kwargs)
290268

269+
version = graphql_version()
270+
framework_version = '.'.join(map(str, version))
271+
272+
transaction.add_framework_info(name='GraphQL', version=framework_version)
273+
291274
if graphql_version() <= (3, 0, 0):
292275
bind_query = bind_execute_graphql_query
293276
else:

tests/framework_graphql/test_application.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ def error_middleware(next, root, info, **args):
7676

7777
@dt_enabled
7878
def test_basic(app, graphql_run):
79+
from graphql import __version__ as version
80+
81+
FRAMEWORK_METRICS = [
82+
('Python/Framework/GraphQL/%s' % version, 1),
83+
]
7984
_test_mutation_scoped_metrics = [
8085
("GraphQL/resolve/GraphQL/storage", 1),
8186
("GraphQL/resolve/GraphQL/storage_add", 1),
@@ -113,7 +118,7 @@ def test_basic(app, graphql_run):
113118
@validate_transaction_metrics(
114119
"_target_application:resolve_storage",
115120
scoped_metrics=_test_mutation_scoped_metrics,
116-
rollup_metrics=_test_mutation_unscoped_metrics,
121+
rollup_metrics=_test_mutation_unscoped_metrics + FRAMEWORK_METRICS,
117122
background_task=True,
118123
)
119124
@validate_span_events(exact_agents=_expected_mutation_operation_attributes)

0 commit comments

Comments
 (0)