-
Notifications
You must be signed in to change notification settings - Fork 144
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
GraphQL Instrumentation #396
Conversation
Manual testing of NetFlix DGS example jav app - looks good. https://staging.onenr.io/0mMRNAKLAwn |
So not really 50+ files of code. We have our GraphQL test files in separate *.gql files under |
We are totally fine squashing or whatever team wants to do. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor nits but overall looks good!
@@ -25,4 +27,6 @@ | |||
String getHttpComponent(); | |||
|
|||
String getTransactionId(); | |||
|
|||
Map<String, Object> getAgentAttributes(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this? Looks like testing only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, so that we can get the attributes from span event through introspector. (channeling Xi Xia)
newrelic-agent/src/main/java/com/newrelic/agent/service/analytics/TracerToSpanEvent.java
Outdated
Show resolved
Hide resolved
...tion/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLErrorHandler.java
Outdated
Show resolved
Hide resolved
...entation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLSpanUtil.java
Show resolved
Hide resolved
List<Selection> selection = selections.stream() | ||
.filter(namedNode -> notFederatedFieldName(getNameFrom(namedNode))) | ||
.collect(Collectors.toList()); | ||
// there can be only one, or we stop digging into query |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...on/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/GraphQLObfuscatorTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly nit picking.
public static void reportResolverThrowableToNR(Throwable e) { | ||
NewRelic.noticeError(e); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you foresee this method doing something else?
In the place that this is called, it gives the impression that it would do something else besides calling noticeError.
Same question for reportGraphQLException.
Though I do see the value in reportGraphQLError.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
private static <T> T getValueOrDefault(T value, T defaultValue) { | ||
return value == null ? defaultValue : value; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great method that we could use in other places.
Do we have a Util class where it could live?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I don't know. I'm not sure where something like this goes.
private static boolean isNullOrEmpty(final Collection<?> c) { | ||
return c == null || c.isEmpty(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This too should be in a Util class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My rule is, if you use it twice, copy paste is fine. But if you go to use it in a third place, pull it out. But I can pull it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically I use a Collection Utils class that exists in latter versions of Java
return null; | ||
} | ||
List<Selection> selections = selectionSet.getSelections(); | ||
if (selections == null || selections.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Util method I mentioned below could be reused here.
} | ||
|
||
protected void handleFetchingException(ExecutionContext executionContext, DataFetchingEnvironment environment, Throwable e) { | ||
reportResolverThrowableToNR(e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following up on my comment on GraphQLErrorHandler.
I think that calling NewRelic.notifyError(e);
here is less surprising for the reader without loss of the context given by the method name.
|
||
@ParameterizedTest | ||
@CsvFileSource(resources = "/obfuscateQueryTestData/obfuscate-query-test-data.csv", delimiter = '|', numLinesToSkip = 2) | ||
public void testObfuscateQuery(String queryToObfuscateFile, String expectedObfuscatedQueryFile) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just nit picking, but the File
in the var name is odd.
dependencies { | ||
implementation(project(":agent-bridge")) | ||
|
||
implementation 'com.graphql-java:graphql-java:16.2' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add something to the THIRD_PARTY_NOTICES.md
file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
??? this is the library we are instrumenting. I don't know about this type of file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for dependencies used in instrumentation modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically it's just libraries that we directly use in development of the agent that need to be declared.
495c2ea
to
3ac30c1
Compare
- Add copyright statements - Refactor out a couple utility methods - Remove a couple unnecessary passthru methods - Fix a couple unit test parameter names for clarity
3ac30c1
to
5a035c1
Compare
Overview
GraphQL Instrumentation
Related Github Issue
For every metric created, the agent creates a scoped and unscoped version. An unscoped metric could get filtered out from being sent by the agent if it doesn't meet certain criteria. This prevents the GraphQL metrics from being filtered.
Checks
[X] Are your contributions backwards compatible with relevant frameworks and APIs?
[] Does your code contain any breaking changes? Please describe.
[X] Does your code introduce any new dependencies? Please describe.