From a1bf6888c596444787db10ce3c3c63b15ee2f5f3 Mon Sep 17 00:00:00 2001 From: Uma Annamalai Date: Wed, 15 Sep 2021 16:40:14 -0700 Subject: [PATCH] Add GraphQL Framework Info to Metrics (#367) * Add graphene and ariadne product info. * Add strawberry product info. * Add framework info to resolver metrics. * Correct Ariadne tests. * Update Starlette tests with Graphene details. * Add protobuf version dependency to agent_streaming tests. * Specify python version for protobuf dependency. * Remove graphql node product property. --- newrelic/api/graphql_trace.py | 24 ++++++++++++ newrelic/core/graphql_node.py | 8 +--- newrelic/hooks/framework_ariadne.py | 2 + newrelic/hooks/framework_graphql.py | 24 ++++++++++-- newrelic/hooks/framework_strawberry.py | 2 + tests/framework_ariadne/test_application.py | 34 ++++++++--------- .../test_application_async.py | 12 +++--- tests/framework_ariadne/test_asgi.py | 12 +++--- tests/framework_ariadne/test_wsgi.py | 12 +++--- tests/framework_graphene/test_application.py | 37 ++++++++++--------- tests/framework_starlette/test_graphql.py | 10 +++-- .../framework_strawberry/test_application.py | 26 ++++++------- .../test_application_async.py | 19 ++++++---- tests/framework_strawberry/test_asgi.py | 12 +++--- 14 files changed, 141 insertions(+), 93 deletions(-) diff --git a/newrelic/api/graphql_trace.py b/newrelic/api/graphql_trace.py index 0712120ca3..9355a65dbc 100644 --- a/newrelic/api/graphql_trace.py +++ b/newrelic/api/graphql_trace.py @@ -36,6 +36,7 @@ def __init__(self, **kwargs): self.graphql = None self.graphql_format = None self.statement = None + self.product = "GraphQL" def __repr__(self): return "<%s object at 0x%x %s>" % ( @@ -89,6 +90,7 @@ def create_node(self): operation_type=self.operation_type, deepest_path=self.deepest_path, graphql=self.graphql, + product=self.product, ) def set_transaction_name(self, priority=None): @@ -135,10 +137,31 @@ class GraphQLResolverTrace(TimeTrace): def __init__(self, field_name=None, **kwargs): super(GraphQLResolverTrace, self).__init__(**kwargs) self.field_name = field_name + self._product = None def __repr__(self): return "<%s object at 0x%x %s>" % (self.__class__.__name__, id(self), dict(field_name=self.field_name)) + def __enter__(self): + super(GraphQLResolverTrace, self).__enter__() + _ = self.product # Cache product value + return self + + @property + def product(self): + if not self._product: + # Find GraphQLOperationTrace to obtain stored product info + parent = self # init to self for loop start + while parent is not None and not isinstance(parent, GraphQLOperationTrace): + parent = getattr(parent, "parent", None) + + if parent is not None: + self._product = getattr(parent, "product", "GraphQL") + else: + self._product = "GraphQL" + + return self._product + def finalize_data(self, *args, **kwargs): self._add_agent_attribute("graphql.field.name", self.field_name) @@ -155,6 +178,7 @@ def create_node(self): guid=self.guid, agent_attributes=self.agent_attributes, user_attributes=self.user_attributes, + product=self.product, ) diff --git a/newrelic/core/graphql_node.py b/newrelic/core/graphql_node.py index f60f51f6e4..a32e185ee9 100644 --- a/newrelic/core/graphql_node.py +++ b/newrelic/core/graphql_node.py @@ -23,17 +23,13 @@ _GraphQLOperationNode = namedtuple('_GraphQLNode', ['operation_type', 'operation_name', 'deepest_path', 'graphql', 'children', 'start_time', 'end_time', 'duration', 'exclusive', 'guid', - 'agent_attributes', 'user_attributes']) + 'agent_attributes', 'user_attributes', 'product']) _GraphQLResolverNode = namedtuple('_GraphQLNode', ['field_name', 'children', 'start_time', 'end_time', 'duration', - 'exclusive', 'guid', 'agent_attributes', 'user_attributes']) + 'exclusive', 'guid', 'agent_attributes', 'user_attributes', 'product']) class GraphQLNodeMixin(GenericNodeMixin): - @property - def product(self): - return "GraphQL" - def trace_node(self, stats, root, connections): name = root.string_table.cache(self.name) diff --git a/newrelic/hooks/framework_ariadne.py b/newrelic/hooks/framework_ariadne.py index 1ff7a12bed..44315161e6 100644 --- a/newrelic/hooks/framework_ariadne.py +++ b/newrelic/hooks/framework_ariadne.py @@ -60,6 +60,7 @@ def wrap_graphql_sync(wrapped, instance, args, kwargs): transaction.set_transaction_name(callable_name(wrapped), "GraphQL", priority=10) with GraphQLOperationTrace() as trace: + trace.product = "Ariadne" trace.statement = graphql_statement(query) with ErrorTrace(ignore=ignore_graphql_duplicate_exception): return wrapped(*args, **kwargs) @@ -93,6 +94,7 @@ async def wrap_graphql(wrapped, instance, args, kwargs): transaction.set_transaction_name(callable_name(wrapped), "GraphQL", priority=10) with GraphQLOperationTrace() as trace: + trace.product = "Ariadne" trace.statement = graphql_statement(query) with ErrorTrace(ignore=ignore_graphql_duplicate_exception): result = wrapped(*args, **kwargs) diff --git a/newrelic/hooks/framework_graphql.py b/newrelic/hooks/framework_graphql.py index 95971c1a7f..688b309c1b 100644 --- a/newrelic/hooks/framework_graphql.py +++ b/newrelic/hooks/framework_graphql.py @@ -369,6 +369,12 @@ def bind_resolve_field_v2(exe_context, parent_type, source, field_asts, parent_i return parent_type, field_asts, field_path +def graphene_framework_details(): + import graphene + + return ("Graphene", getattr(graphene, "__version__", None)) + + def wrap_resolve_field(wrapped, instance, args, kwargs): transaction = current_transaction() if transaction is None: @@ -402,7 +408,7 @@ def wrap_resolve_field(wrapped, instance, args, kwargs): def bind_graphql_impl_query(schema, source, *args, **kwargs): - return source + return schema, source def bind_execute_graphql_query( @@ -416,8 +422,7 @@ def bind_execute_graphql_query( backend=None, **execute_options ): - - return request_string + return schema, request_string def wrap_graphql_impl(wrapped, instance, args, kwargs): @@ -433,7 +438,7 @@ def wrap_graphql_impl(wrapped, instance, args, kwargs): bind_query = bind_graphql_impl_query try: - query = bind_query(*args, **kwargs) + schema, query = bind_query(*args, **kwargs) except TypeError: return wrapped(*args, **kwargs) @@ -444,6 +449,17 @@ def wrap_graphql_impl(wrapped, instance, args, kwargs): with GraphQLOperationTrace() as trace: trace.statement = graphql_statement(query) + + # Handle Graphene Schemas + try: + from graphene.types.schema import Schema as GrapheneSchema + if isinstance(schema, GrapheneSchema): + trace.product = "Graphene" + framework = graphene_framework_details() + transaction.add_framework_info(name=framework[0], version=framework[1]) + except ImportError: + pass + with ErrorTrace(ignore=ignore_graphql_duplicate_exception): result = wrapped(*args, **kwargs) return result diff --git a/newrelic/hooks/framework_strawberry.py b/newrelic/hooks/framework_strawberry.py index 8baf75d5cc..0510a1711b 100644 --- a/newrelic/hooks/framework_strawberry.py +++ b/newrelic/hooks/framework_strawberry.py @@ -57,6 +57,7 @@ def wrap_execute_sync(wrapped, instance, args, kwargs): transaction.set_transaction_name(callable_name(wrapped), "GraphQL", priority=10) with GraphQLOperationTrace() as trace: + trace.product = "Strawberry" trace.statement = graphql_statement(query) with ErrorTrace(ignore=ignore_graphql_duplicate_exception): return wrapped(*args, **kwargs) @@ -83,6 +84,7 @@ async def wrap_execute(wrapped, instance, args, kwargs): transaction.set_transaction_name(callable_name(wrapped), "GraphQL", priority=10) with GraphQLOperationTrace() as trace: + trace.product = "Strawberry" trace.statement = graphql_statement(query) with ErrorTrace(ignore=ignore_graphql_duplicate_exception): return await wrapped(*args, **kwargs) diff --git a/tests/framework_ariadne/test_application.py b/tests/framework_ariadne/test_application.py index a7eec3303e..4c536042d9 100644 --- a/tests/framework_ariadne/test_application.py +++ b/tests/framework_ariadne/test_application.py @@ -82,8 +82,8 @@ def error_middleware(next, root, info, **args): # pylint: disable=W0622 ("OtherTransaction/all", 1), ("GraphQL/all", 1), ("GraphQL/allOther", 1), - ("GraphQL/GraphQL/all", 1), - ("GraphQL/GraphQL/allOther", 1), + ("GraphQL/Ariadne/all", 1), + ("GraphQL/Ariadne/allOther", 1), ] @@ -118,17 +118,17 @@ def test_query_and_mutation(app, graphql_run): ("Python/Framework/GraphQL/%s" % version, 1), ] _test_mutation_scoped_metrics = [ - ("GraphQL/resolve/GraphQL/storage", 1), - ("GraphQL/resolve/GraphQL/storage_add", 1), - ("GraphQL/operation/GraphQL/query//storage", 1), - ("GraphQL/operation/GraphQL/mutation//storage_add.string", 1), + ("GraphQL/resolve/Ariadne/storage", 1), + ("GraphQL/resolve/Ariadne/storage_add", 1), + ("GraphQL/operation/Ariadne/query//storage", 1), + ("GraphQL/operation/Ariadne/mutation//storage_add.string", 1), ] _test_mutation_unscoped_metrics = [ ("OtherTransaction/all", 1), ("GraphQL/all", 2), - ("GraphQL/GraphQL/all", 2), + ("GraphQL/Ariadne/all", 2), ("GraphQL/allOther", 2), - ("GraphQL/GraphQL/allOther", 2), + ("GraphQL/Ariadne/allOther", 2), ] + _test_mutation_scoped_metrics _expected_mutation_operation_attributes = { @@ -180,8 +180,8 @@ def _test(): @dt_enabled def test_middleware(app, graphql_run, is_graphql_2): _test_middleware_metrics = [ - ("GraphQL/operation/GraphQL/query//hello", 1), - ("GraphQL/resolve/GraphQL/hello", 1), + ("GraphQL/operation/Ariadne/query//hello", 1), + ("GraphQL/resolve/Ariadne/hello", 1), ("Function/test_application:example_middleware", 1), ] @@ -212,8 +212,8 @@ def test_exception_in_middleware(app, graphql_run): # Metrics _test_exception_scoped_metrics = [ - ("GraphQL/operation/GraphQL/query/MyQuery/%s" % field, 1), - ("GraphQL/resolve/GraphQL/%s" % field, 1), + ("GraphQL/operation/Ariadne/query/MyQuery/%s" % field, 1), + ("GraphQL/resolve/Ariadne/%s" % field, 1), ] _test_exception_rollup_metrics = [ ("Errors/all", 1), @@ -262,8 +262,8 @@ def test_exception_in_resolver(app, graphql_run, field): # Metrics _test_exception_scoped_metrics = [ - ("GraphQL/operation/GraphQL/query/MyQuery/%s" % field, 1), - ("GraphQL/resolve/GraphQL/%s" % field, 1), + ("GraphQL/operation/Ariadne/query/MyQuery/%s" % field, 1), + ("GraphQL/resolve/Ariadne/%s" % field, 1), ] _test_exception_rollup_metrics = [ ("Errors/all", 1), @@ -326,7 +326,7 @@ def test_exception_in_validation(app, graphql_run, is_graphql_2, query, exc_clas exc_class = callable_name(GraphQLError) _test_exception_scoped_metrics = [ - # ('GraphQL/operation/GraphQL///', 1), + ('GraphQL/operation/Ariadne///', 1), ] _test_exception_rollup_metrics = [ ("Errors/all", 1), @@ -360,7 +360,7 @@ def _test(): @dt_enabled def test_operation_metrics_and_attrs(app, graphql_run): - operation_metrics = [("GraphQL/operation/GraphQL/query/MyQuery/library", 1)] + operation_metrics = [("GraphQL/operation/Ariadne/query/MyQuery/library", 1)] operation_attrs = { "graphql.operation.type": "query", "graphql.operation.name": "MyQuery", @@ -388,7 +388,7 @@ def _test(): @dt_enabled def test_field_resolver_metrics_and_attrs(app, graphql_run): - field_resolver_metrics = [("GraphQL/resolve/GraphQL/hello", 1)] + field_resolver_metrics = [("GraphQL/resolve/Ariadne/hello", 1)] graphql_attrs = { "graphql.field.name": "hello", "graphql.field.parentType": "Query", diff --git a/tests/framework_ariadne/test_application_async.py b/tests/framework_ariadne/test_application_async.py index 95ac67027a..7b9cf18c4b 100644 --- a/tests/framework_ariadne/test_application_async.py +++ b/tests/framework_ariadne/test_application_async.py @@ -28,17 +28,17 @@ def test_query_and_mutation_async(app, graphql_run_async): ("Python/Framework/GraphQL/%s" % version, 1), ] _test_mutation_scoped_metrics = [ - ("GraphQL/resolve/GraphQL/storage", 1), - ("GraphQL/resolve/GraphQL/storage_add", 1), - ("GraphQL/operation/GraphQL/query//storage", 1), - ("GraphQL/operation/GraphQL/mutation//storage_add.string", 1), + ("GraphQL/resolve/Ariadne/storage", 1), + ("GraphQL/resolve/Ariadne/storage_add", 1), + ("GraphQL/operation/Ariadne/query//storage", 1), + ("GraphQL/operation/Ariadne/mutation//storage_add.string", 1), ] _test_mutation_unscoped_metrics = [ ("OtherTransaction/all", 1), ("GraphQL/all", 2), - ("GraphQL/GraphQL/all", 2), + ("GraphQL/Ariadne/all", 2), ("GraphQL/allOther", 2), - ("GraphQL/GraphQL/allOther", 2), + ("GraphQL/Ariadne/allOther", 2), ] + _test_mutation_scoped_metrics _expected_mutation_operation_attributes = { diff --git a/tests/framework_ariadne/test_asgi.py b/tests/framework_ariadne/test_asgi.py index 5ca307d90d..8bcd81216a 100644 --- a/tests/framework_ariadne/test_asgi.py +++ b/tests/framework_ariadne/test_asgi.py @@ -30,19 +30,19 @@ def test_query_and_mutation_asgi(graphql_asgi_run): ("Python/Framework/GraphQL/%s" % version, 1), ] _test_mutation_scoped_metrics = [ - ("GraphQL/resolve/GraphQL/storage_add", 1), - ("GraphQL/operation/GraphQL/mutation//storage_add.string", 1), + ("GraphQL/resolve/Ariadne/storage_add", 1), + ("GraphQL/operation/Ariadne/mutation//storage_add.string", 1), ] _test_query_scoped_metrics = [ - ("GraphQL/resolve/GraphQL/storage", 1), - ("GraphQL/operation/GraphQL/query//storage", 1), + ("GraphQL/resolve/Ariadne/storage", 1), + ("GraphQL/operation/Ariadne/query//storage", 1), ] _test_unscoped_metrics = [ ("WebTransaction", 1), ("GraphQL/all", 1), - ("GraphQL/GraphQL/all", 1), + ("GraphQL/Ariadne/all", 1), ("GraphQL/allWeb", 1), - ("GraphQL/GraphQL/allWeb", 1), + ("GraphQL/Ariadne/allWeb", 1), ] _test_mutation_unscoped_metrics = _test_unscoped_metrics + _test_mutation_scoped_metrics _test_query_unscoped_metrics = _test_unscoped_metrics + _test_query_scoped_metrics diff --git a/tests/framework_ariadne/test_wsgi.py b/tests/framework_ariadne/test_wsgi.py index bb8a3ae5aa..29e7d9259c 100644 --- a/tests/framework_ariadne/test_wsgi.py +++ b/tests/framework_ariadne/test_wsgi.py @@ -26,20 +26,20 @@ def test_query_and_mutation_wsgi(graphql_wsgi_run): ("Python/Framework/GraphQL/%s" % version, 1), ] _test_mutation_scoped_metrics = [ - ("GraphQL/resolve/GraphQL/storage_add", 1), - ("GraphQL/operation/GraphQL/mutation//storage_add.string", 1), + ("GraphQL/resolve/Ariadne/storage_add", 1), + ("GraphQL/operation/Ariadne/mutation//storage_add.string", 1), ] _test_query_scoped_metrics = [ - ("GraphQL/resolve/GraphQL/storage", 1), - ("GraphQL/operation/GraphQL/query//storage", 1), + ("GraphQL/resolve/Ariadne/storage", 1), + ("GraphQL/operation/Ariadne/query//storage", 1), ] _test_unscoped_metrics = [ ("WebTransaction", 1), ("Python/WSGI/Response", 1), ("GraphQL/all", 1), - ("GraphQL/GraphQL/all", 1), + ("GraphQL/Ariadne/all", 1), ("GraphQL/allWeb", 1), - ("GraphQL/GraphQL/allWeb", 1), + ("GraphQL/Ariadne/allWeb", 1), ] _test_mutation_unscoped_metrics = _test_unscoped_metrics + _test_mutation_scoped_metrics _test_query_unscoped_metrics = _test_unscoped_metrics + _test_query_scoped_metrics diff --git a/tests/framework_graphene/test_application.py b/tests/framework_graphene/test_application.py index eaa53aecfa..0592463f7f 100644 --- a/tests/framework_graphene/test_application.py +++ b/tests/framework_graphene/test_application.py @@ -81,16 +81,19 @@ def error_middleware(next, root, info, **args): #pylint: disable=W0622 ("OtherTransaction/all", 1), ("GraphQL/all", 1), ("GraphQL/allOther", 1), - ("GraphQL/GraphQL/all", 1), - ("GraphQL/GraphQL/allOther", 1), + ("GraphQL/Graphene/all", 1), + ("GraphQL/Graphene/allOther", 1), ] def test_basic(app, graphql_run): from graphql import __version__ as version + from newrelic.hooks.framework_graphql import graphene_framework_details FRAMEWORK_METRICS = [ + ("Python/Framework/Graphene/%s" % graphene_framework_details()[1], 1), ("Python/Framework/GraphQL/%s" % version, 1), + ] @validate_transaction_metrics( @@ -115,17 +118,17 @@ def test_query_and_mutation(app, graphql_run): ("Python/Framework/GraphQL/%s" % version, 1), ] _test_mutation_scoped_metrics = [ - ("GraphQL/resolve/GraphQL/storage", 1), - ("GraphQL/resolve/GraphQL/storage_add", 1), - ("GraphQL/operation/GraphQL/query//storage", 1), - ("GraphQL/operation/GraphQL/mutation//storage_add.string", 1), + ("GraphQL/resolve/Graphene/storage", 1), + ("GraphQL/resolve/Graphene/storage_add", 1), + ("GraphQL/operation/Graphene/query//storage", 1), + ("GraphQL/operation/Graphene/mutation//storage_add.string", 1), ] _test_mutation_unscoped_metrics = [ ("OtherTransaction/all", 1), ("GraphQL/all", 2), - ("GraphQL/GraphQL/all", 2), + ("GraphQL/Graphene/all", 2), ("GraphQL/allOther", 2), - ("GraphQL/GraphQL/allOther", 2), + ("GraphQL/Graphene/allOther", 2), ] + _test_mutation_scoped_metrics _expected_mutation_operation_attributes = { @@ -177,8 +180,8 @@ def _test(): @dt_enabled def test_middleware(app, graphql_run, is_graphql_2): _test_middleware_metrics = [ - ("GraphQL/operation/GraphQL/query//hello", 1), - ("GraphQL/resolve/GraphQL/hello", 1), + ("GraphQL/operation/Graphene/query//hello", 1), + ("GraphQL/resolve/Graphene/hello", 1), ("Function/test_application:example_middleware", 1), ] @@ -207,8 +210,8 @@ def test_exception_in_middleware(app, graphql_run): # Metrics _test_exception_scoped_metrics = [ - ("GraphQL/operation/GraphQL/query/MyQuery/%s" % field, 1), - ("GraphQL/resolve/GraphQL/%s" % field, 1), + ("GraphQL/operation/Graphene/query/MyQuery/%s" % field, 1), + ("GraphQL/resolve/Graphene/%s" % field, 1), ] _test_exception_rollup_metrics = [ ("Errors/all", 1), @@ -259,8 +262,8 @@ def test_exception_in_resolver(app, graphql_run, field): # Metrics _test_exception_scoped_metrics = [ - ("GraphQL/operation/GraphQL/query/MyQuery/%s" % field, 1), - ("GraphQL/resolve/GraphQL/%s" % field, 1), + ("GraphQL/operation/Graphene/query/MyQuery/%s" % field, 1), + ("GraphQL/resolve/Graphene/%s" % field, 1), ] _test_exception_rollup_metrics = [ ("Errors/all", 1), @@ -323,7 +326,7 @@ def test_exception_in_validation(app, graphql_run, is_graphql_2, query, exc_clas exc_class = callable_name(GraphQLError) _test_exception_scoped_metrics = [ - # ('GraphQL/operation/GraphQL///', 1), + ('GraphQL/operation/Graphene///', 1), ] _test_exception_rollup_metrics = [ ("Errors/all", 1), @@ -357,7 +360,7 @@ def _test(): @dt_enabled def test_operation_metrics_and_attrs(app, graphql_run): - operation_metrics = [("GraphQL/operation/GraphQL/query/MyQuery/library", 1)] + operation_metrics = [("GraphQL/operation/Graphene/query/MyQuery/library", 1)] operation_attrs = { "graphql.operation.type": "query", "graphql.operation.name": "MyQuery", @@ -385,7 +388,7 @@ def _test(): @dt_enabled def test_field_resolver_metrics_and_attrs(app, graphql_run): - field_resolver_metrics = [("GraphQL/resolve/GraphQL/hello", 1)] + field_resolver_metrics = [("GraphQL/resolve/Graphene/hello", 1)] graphql_attrs = { "graphql.field.name": "hello", "graphql.field.parentType": "Query", diff --git a/tests/framework_starlette/test_graphql.py b/tests/framework_starlette/test_graphql.py index fd7d2ffcb3..c6cb2de1cd 100644 --- a/tests/framework_starlette/test_graphql.py +++ b/tests/framework_starlette/test_graphql.py @@ -27,19 +27,21 @@ def target_application(): @pytest.mark.parametrize("endpoint", ("/async", "/sync")) def test_graphql_metrics_and_attrs(target_application, endpoint): from graphql import __version__ as version + from newrelic.hooks.framework_graphql import graphene_framework_details FRAMEWORK_METRICS = [ + ("Python/Framework/Graphene/%s" % graphene_framework_details()[1], 1), ("Python/Framework/GraphQL/%s" % version, 1), ] _test_scoped_metrics = [ - ("GraphQL/resolve/GraphQL/hello", 1), - ("GraphQL/operation/GraphQL/query//hello", 1), + ("GraphQL/resolve/Graphene/hello", 1), + ("GraphQL/operation/Graphene/query//hello", 1), ] _test_unscoped_metrics = [ ("GraphQL/all", 1), - ("GraphQL/GraphQL/all", 1), + ("GraphQL/Graphene/all", 1), ("GraphQL/allWeb", 1), - ("GraphQL/GraphQL/allWeb", 1), + ("GraphQL/Graphene/allWeb", 1), ] + _test_scoped_metrics _expected_query_operation_attributes = { diff --git a/tests/framework_strawberry/test_application.py b/tests/framework_strawberry/test_application.py index 5d8ac243b6..b68b825fff 100644 --- a/tests/framework_strawberry/test_application.py +++ b/tests/framework_strawberry/test_application.py @@ -80,8 +80,8 @@ def error_middleware(next, root, info, **args): #pylint: disable=W0622 ("OtherTransaction/all", 1), ("GraphQL/all", 1), ("GraphQL/allOther", 1), - ("GraphQL/GraphQL/all", 1), - ("GraphQL/GraphQL/allOther", 1), + ("GraphQL/Strawberry/all", 1), + ("GraphQL/Strawberry/allOther", 1), ] @@ -120,17 +120,17 @@ def test_query_and_mutation(app, graphql_run): ("Python/Framework/GraphQL/%s" % version, 1), ] _test_mutation_scoped_metrics = [ - ("GraphQL/resolve/GraphQL/storage", 1), - ("GraphQL/resolve/GraphQL/storage_add", 1), - ("GraphQL/operation/GraphQL/query//storage", 1), - ("GraphQL/operation/GraphQL/mutation//storage_add", 1), + ("GraphQL/resolve/Strawberry/storage", 1), + ("GraphQL/resolve/Strawberry/storage_add", 1), + ("GraphQL/operation/Strawberry/query//storage", 1), + ("GraphQL/operation/Strawberry/mutation//storage_add", 1), ] _test_mutation_unscoped_metrics = [ ("OtherTransaction/all", 1), ("GraphQL/all", 2), - ("GraphQL/GraphQL/all", 2), + ("GraphQL/Strawberry/all", 2), ("GraphQL/allOther", 2), - ("GraphQL/GraphQL/allOther", 2), + ("GraphQL/Strawberry/allOther", 2), ] + _test_mutation_scoped_metrics _expected_mutation_operation_attributes = { @@ -188,8 +188,8 @@ def test_exception_in_resolver(app, graphql_run, field): # Metrics _test_exception_scoped_metrics = [ - ("GraphQL/operation/GraphQL/query/MyQuery/%s" % field, 1), - ("GraphQL/resolve/GraphQL/%s" % field, 1), + ("GraphQL/operation/Strawberry/query/MyQuery/%s" % field, 1), + ("GraphQL/resolve/Strawberry/%s" % field, 1), ] _test_exception_rollup_metrics = [ ("Errors/all", 1), @@ -252,7 +252,7 @@ def test_exception_in_validation(app, graphql_run, is_graphql_2, query, exc_clas exc_class = callable_name(GraphQLError) _test_exception_scoped_metrics = [ - # ('GraphQL/operation/GraphQL///', 1), + ('GraphQL/operation/Strawberry///', 1), ] _test_exception_rollup_metrics = [ ("Errors/all", 1), @@ -286,7 +286,7 @@ def _test(): @dt_enabled def test_operation_metrics_and_attrs(app, graphql_run): - operation_metrics = [("GraphQL/operation/GraphQL/query/MyQuery/library", 1)] + operation_metrics = [("GraphQL/operation/Strawberry/query/MyQuery/library", 1)] operation_attrs = { "graphql.operation.type": "query", "graphql.operation.name": "MyQuery", @@ -314,7 +314,7 @@ def _test(): @dt_enabled def test_field_resolver_metrics_and_attrs(app, graphql_run): - field_resolver_metrics = [("GraphQL/resolve/GraphQL/hello", 1)] + field_resolver_metrics = [("GraphQL/resolve/Strawberry/hello", 1)] graphql_attrs = { "graphql.field.name": "hello", "graphql.field.parentType": "Query", diff --git a/tests/framework_strawberry/test_application_async.py b/tests/framework_strawberry/test_application_async.py index f5bfa74f14..3af55b6d46 100644 --- a/tests/framework_strawberry/test_application_async.py +++ b/tests/framework_strawberry/test_application_async.py @@ -21,15 +21,18 @@ def execute(schema, *args, **kwargs): ("OtherTransaction/all", 1), ("GraphQL/all", 1), ("GraphQL/allOther", 1), - ("GraphQL/GraphQL/all", 1), - ("GraphQL/GraphQL/allOther", 1), + ("GraphQL/Strawberry/all", 1), + ("GraphQL/Strawberry/allOther", 1), ] def test_basic(app, graphql_run_async): from graphql import __version__ as version + from newrelic.hooks.framework_strawberry import framework_details + FRAMEWORK_METRICS = [ + ("Python/Framework/Strawberry/%s" % framework_details()[1], 1), ("Python/Framework/GraphQL/%s" % version, 1), ] @@ -62,17 +65,17 @@ def test_query_and_mutation_async(app, graphql_run_async): ("Python/Framework/GraphQL/%s" % version, 1), ] _test_mutation_scoped_metrics = [ - ("GraphQL/resolve/GraphQL/storage", 1), - ("GraphQL/resolve/GraphQL/storage_add", 1), - ("GraphQL/operation/GraphQL/query//storage", 1), - ("GraphQL/operation/GraphQL/mutation//storage_add", 1), + ("GraphQL/resolve/Strawberry/storage", 1), + ("GraphQL/resolve/Strawberry/storage_add", 1), + ("GraphQL/operation/Strawberry/query//storage", 1), + ("GraphQL/operation/Strawberry/mutation//storage_add", 1), ] _test_mutation_unscoped_metrics = [ ("OtherTransaction/all", 1), ("GraphQL/all", 2), - ("GraphQL/GraphQL/all", 2), + ("GraphQL/Strawberry/all", 2), ("GraphQL/allOther", 2), - ("GraphQL/GraphQL/allOther", 2), + ("GraphQL/Strawberry/allOther", 2), ] + _test_mutation_scoped_metrics _expected_mutation_operation_attributes = { diff --git a/tests/framework_strawberry/test_asgi.py b/tests/framework_strawberry/test_asgi.py index 2255e38344..c64fdcd563 100644 --- a/tests/framework_strawberry/test_asgi.py +++ b/tests/framework_strawberry/test_asgi.py @@ -35,19 +35,19 @@ def test_query_and_mutation_asgi(graphql_asgi_run): ("Python/Framework/GraphQL/%s" % version, 1), ] _test_mutation_scoped_metrics = [ - ("GraphQL/resolve/GraphQL/storage_add", 1), - ("GraphQL/operation/GraphQL/mutation//storage_add", 1), + ("GraphQL/resolve/Strawberry/storage_add", 1), + ("GraphQL/operation/Strawberry/mutation//storage_add", 1), ] _test_query_scoped_metrics = [ - ("GraphQL/resolve/GraphQL/storage", 1), - ("GraphQL/operation/GraphQL/query//storage", 1), + ("GraphQL/resolve/Strawberry/storage", 1), + ("GraphQL/operation/Strawberry/query//storage", 1), ] _test_unscoped_metrics = [ ("WebTransaction", 1), ("GraphQL/all", 1), - ("GraphQL/GraphQL/all", 1), + ("GraphQL/Strawberry/all", 1), ("GraphQL/allWeb", 1), - ("GraphQL/GraphQL/allWeb", 1), + ("GraphQL/Strawberry/allWeb", 1), ] _test_mutation_unscoped_metrics = _test_unscoped_metrics + _test_mutation_scoped_metrics _test_query_unscoped_metrics = _test_unscoped_metrics + _test_query_scoped_metrics