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

[WIP] Add Path to GraphQLResolverTrace #737

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1bdf3b1
Add GraphQL Server Sanic Instrumentation
lrafeei Mar 24, 2022
9e526d1
Co-authored-by: Timothy Pansino <TimPansino@users.noreply.github.com>
lrafeei Mar 24, 2022
9f8856b
Add co-authors
lrafeei Mar 24, 2022
375bda5
Comment out Copyright notice message
lrafeei Mar 24, 2022
07ec74f
Finalize Sanic testing
TimPansino Mar 28, 2022
f781423
Fix flask framework details with callable
TimPansino Mar 28, 2022
58418ee
Parametrized testing for graphql-server
TimPansino Mar 28, 2022
215538b
GraphQL Async Resolvers
TimPansino Mar 28, 2022
e7705ad
Merge branch 'main' into develop-graphql-async
TimPansino Mar 31, 2022
38e9f72
Merge branch 'main' into develop-graphql-async
TimPansino Apr 20, 2022
8cda4f7
GraphQL Proper Coro and Promise Support (#508)
TimPansino Apr 20, 2022
7c630b8
Merge branch 'main' into develop-graphql-async
TimPansino Apr 27, 2022
56cab4b
Fix graphql impl coros (#522)
TimPansino Apr 27, 2022
fd57192
Strawberry Async Updates (#521)
TimPansino May 3, 2022
ff9b1b4
Ariadne Async Testing (#523)
TimPansino May 9, 2022
a2889a6
Graphene Async Testing (#524)
TimPansino May 10, 2022
addc9e5
Merge branch 'main' into develop-graphql-async
TimPansino May 26, 2022
ec0ec2f
Merge branch 'main' into develop-graphql-async
TimPansino May 27, 2022
545fdfa
Merge branch 'main' into develop-graphql-async
TimPansino Jul 11, 2022
61d32f1
Merge branch 'main' into develop-graphql-async
TimPansino Jul 11, 2022
619026e
Merge branch 'main' into develop-graphql-async
TimPansino Oct 6, 2022
8ce4dcd
Add path to graphql resolver trace node
TimPansino Dec 27, 2022
b79a077
Graphene v3 resolver traces fixed
TimPansino Dec 27, 2022
412032e
Validate span events made more verbose
TimPansino Dec 27, 2022
2042998
Graphql v2 trace fixes
TimPansino Dec 27, 2022
6eafefb
Update tests for resolver traces
TimPansino Dec 27, 2022
73cf83f
Fix graphql schema search field
TimPansino Dec 28, 2022
d239756
Graphql v2 field path algorithm
TimPansino Dec 28, 2022
af505f4
Additional resolver trace path testing
TimPansino Dec 28, 2022
429dea2
Move conditional decorator to testing_support
TimPansino Jan 4, 2023
174567f
Rework parametrized resolver test
TimPansino Jan 4, 2023
15cabcb
Add pytest parametrization from dict
TimPansino Jan 4, 2023
9027f9a
Fully expand resolver path tests
TimPansino Jan 4, 2023
4c00038
WIP Combined implementation for graphql 2/3
TimPansino Jan 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion newrelic/api/graphql_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def wrap_graphql_operation_trace(module, object_path):


class GraphQLResolverTrace(TimeTrace):
def __init__(self, field_name=None, **kwargs):
def __init__(self, field_name=None, field_parent_type=None, field_return_type=None, field_path=None, **kwargs):
parent = kwargs.pop("parent", None)
source = kwargs.pop("source", None)
if kwargs:
Expand All @@ -143,6 +143,9 @@ def __init__(self, field_name=None, **kwargs):
super(GraphQLResolverTrace, self).__init__(parent=parent, source=source)

self.field_name = field_name
self.field_parent_type = field_parent_type
self.field_return_type = field_return_type
self.field_path = field_path
self._product = None

def __repr__(self):
Expand Down Expand Up @@ -170,12 +173,16 @@ def product(self):

def finalize_data(self, *args, **kwargs):
self._add_agent_attribute("graphql.field.name", self.field_name)
self._add_agent_attribute("graphql.field.parentType", self.field_parent_type)
self._add_agent_attribute("graphql.field.returnType", self.field_return_type)
self._add_agent_attribute("graphql.field.path", self.field_path)

return super(GraphQLResolverTrace, self).finalize_data(*args, **kwargs)

def create_node(self):
return GraphQLResolverNode(
field_name=self.field_name,
field_path=self.field_path,
children=self.children,
start_time=self.start_time,
end_time=self.end_time,
Expand Down
13 changes: 5 additions & 8 deletions newrelic/core/graphql_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'agent_attributes', 'user_attributes', 'product'])

_GraphQLResolverNode = namedtuple('_GraphQLNode',
['field_name', 'children', 'start_time', 'end_time', 'duration',
['field_name', 'field_path', 'children', 'start_time', 'end_time', 'duration',
'exclusive', 'guid', 'agent_attributes', 'user_attributes', 'product'])

class GraphQLNodeMixin(GenericNodeMixin):
Expand Down Expand Up @@ -57,10 +57,10 @@ def trace_node(self, stats, root, connections):
class GraphQLResolverNode(_GraphQLResolverNode, GraphQLNodeMixin):
@property
def name(self):
field_name = self.field_name or "<unknown>"
product = self.product
field_path = self.field_path or self.field_name or "<unknown>"
product = self.product or "GraphQL"

name = 'GraphQL/resolve/%s/%s' % (product, field_name)
name = 'GraphQL/resolve/%s/%s' % (product, field_path)

return name

Expand All @@ -69,12 +69,9 @@ def time_metrics(self, stats, root, parent):
database node as well as all the child nodes.
"""

field_name = self.field_name or "<unknown>"
product = self.product

# Determine the scoped metric

field_resolver_metric_name = 'GraphQL/resolve/%s/%s' % (product, field_name)
field_resolver_metric_name = self.name

yield TimeMetric(name=field_resolver_metric_name, scope=root.path, duration=self.duration,
exclusive=self.exclusive)
Expand Down
14 changes: 11 additions & 3 deletions newrelic/hooks/framework_ariadne.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@


def framework_details():
import ariadne

return ("Ariadne", getattr(ariadne, "__version__", None))
try:
import ariadne
version = ariadne.__version__
except Exception:
try:
import pkg_resources
version = pkg_resources.get_distribution("ariadne").version
except Exception:
version = None

return ("Ariadne", version)


def bind_graphql(schema, data, *args, **kwargs):
Expand Down