diff --git a/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLErrorHandler.java b/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLErrorHandler.java index 35a71f8372..24cb7c4352 100644 --- a/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLErrorHandler.java +++ b/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLErrorHandler.java @@ -1,3 +1,10 @@ +/* + * + * * Copyright 2020 New Relic Corporation. All rights reserved. + * * SPDX-License-Identifier: Apache-2.0 + * + */ + package com.nr.instrumentation.graphql; import com.newrelic.api.agent.NewRelic; @@ -12,13 +19,9 @@ import java.util.logging.Level; public class GraphQLErrorHandler { - public static void reportResolverThrowableToNR(Throwable e) { - NewRelic.noticeError(e); - } - public static void reportNonNullableExceptionToNR(FieldValueInfo result) { CompletableFuture exceptionResult = result.getFieldValue(); - if (ifResultHasException(exceptionResult)) { + if (resultHasException(exceptionResult)) { reportExceptionFromCompletedExceptionally(exceptionResult); } } @@ -31,7 +34,7 @@ public static void reportGraphQLError(GraphQLError error) { NewRelic.noticeError(throwableFromGraphQLError(error)); } - private static boolean ifResultHasException(CompletableFuture exceptionResult) { + private static boolean resultHasException(CompletableFuture exceptionResult) { return exceptionResult != null && exceptionResult.isCompletedExceptionally(); } diff --git a/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLObfuscator.java b/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLObfuscator.java index 014811c07c..cf87b05286 100644 --- a/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLObfuscator.java +++ b/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLObfuscator.java @@ -1,3 +1,10 @@ +/* + * + * * Copyright 2020 New Relic Corporation. All rights reserved. + * * SPDX-License-Identifier: Apache-2.0 + * + */ + package com.nr.instrumentation.graphql; import graphql.com.google.common.base.Joiner; diff --git a/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLOperationDefinition.java b/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLOperationDefinition.java index 271396596b..7e8aa048bc 100644 --- a/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLOperationDefinition.java +++ b/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLOperationDefinition.java @@ -1,3 +1,10 @@ +/* + * + * * Copyright 2020 New Relic Corporation. All rights reserved. + * * SPDX-License-Identifier: Apache-2.0 + * + */ + package com.nr.instrumentation.graphql; import graphql.language.Document; diff --git a/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLSpanUtil.java b/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLSpanUtil.java index 33cd46a380..2e56c666ee 100644 --- a/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLSpanUtil.java +++ b/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLSpanUtil.java @@ -1,24 +1,21 @@ +/* + * + * * Copyright 2020 New Relic Corporation. All rights reserved. + * * SPDX-License-Identifier: Apache-2.0 + * + */ + package com.nr.instrumentation.graphql; import com.newrelic.agent.bridge.AgentBridge; -import com.newrelic.api.agent.NewRelic; -import graphql.ExecutionResult; -import graphql.GraphQLError; -import graphql.GraphQLException; -import graphql.GraphqlErrorException; import graphql.execution.ExecutionStrategyParameters; -import graphql.execution.FieldValueInfo; import graphql.language.Document; import graphql.language.OperationDefinition; import graphql.schema.GraphQLObjectType; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; -import java.util.logging.Level; - import static com.nr.instrumentation.graphql.GraphQLObfuscator.obfuscate; import static com.nr.instrumentation.graphql.GraphQLOperationDefinition.getOperationTypeFrom; - +import static com.nr.instrumentation.graphql.Utils.getValueOrDefault; public class GraphQLSpanUtil { @@ -57,8 +54,4 @@ private static void setDefaultOperationAttributes(String query) { AgentBridge.privateApi.addTracerParameter("graphql.operation.name", DEFAULT_OPERATION_NAME); AgentBridge.privateApi.addTracerParameter("graphql.operation.query", obfuscate(query)); } - - private static T getValueOrDefault(T value, T defaultValue) { - return value == null ? defaultValue : value; - } } \ No newline at end of file diff --git a/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLTransactionName.java b/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLTransactionName.java index 94c6d94e01..66bbcbccf6 100644 --- a/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLTransactionName.java +++ b/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLTransactionName.java @@ -1,12 +1,20 @@ +/* + * + * * Copyright 2020 New Relic Corporation. All rights reserved. + * * SPDX-License-Identifier: Apache-2.0 + * + */ + package com.nr.instrumentation.graphql; import graphql.language.*; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.stream.Collectors; +import static com.nr.instrumentation.graphql.Utils.isNullOrEmpty; + /** * Generates GraphQL transaction names based on details referenced in Node instrumentation. * @@ -95,7 +103,7 @@ private static Selection onlyNonFederatedSelectionOrNoneFrom(final SelectionSet return null; } List selections = selectionSet.getSelections(); - if (selections == null || selections.isEmpty()) { + if (isNullOrEmpty(selections)) { return null; } List selection = selections.stream() @@ -139,8 +147,4 @@ private static Selection nextNonFederatedSelectionChildFrom(final Selection sele private static boolean notFederatedFieldName(final String fieldName) { return !(TYPENAME.equals(fieldName) || ID.equals(fieldName)); } - - private static boolean isNullOrEmpty(final Collection c) { - return c == null || c.isEmpty(); - } } diff --git a/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/Utils.java b/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/Utils.java new file mode 100644 index 0000000000..9a1747e054 --- /dev/null +++ b/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/Utils.java @@ -0,0 +1,14 @@ +package com.nr.instrumentation.graphql; + +import java.util.Collection; + +// instead of adding dependencies, just add some utility methods +public class Utils { + public static T getValueOrDefault(T value, T defaultValue) { + return value == null ? defaultValue : value; + } + + public static boolean isNullOrEmpty(final Collection c) { + return c == null || c.isEmpty(); + } +} diff --git a/instrumentation/graphql-java-16.2/src/main/java/graphql/ExecutionStrategy_Instrumentation.java b/instrumentation/graphql-java-16.2/src/main/java/graphql/ExecutionStrategy_Instrumentation.java index 86b9887bc2..fc435ab3db 100644 --- a/instrumentation/graphql-java-16.2/src/main/java/graphql/ExecutionStrategy_Instrumentation.java +++ b/instrumentation/graphql-java-16.2/src/main/java/graphql/ExecutionStrategy_Instrumentation.java @@ -1,3 +1,10 @@ +/* + * + * * Copyright 2020 New Relic Corporation. All rights reserved. + * * SPDX-License-Identifier: Apache-2.0 + * + */ + package graphql; import com.newrelic.api.agent.NewRelic; @@ -27,7 +34,7 @@ protected CompletableFuture resolveFieldWithInfo(ExecutionContex } protected void handleFetchingException(ExecutionContext executionContext, DataFetchingEnvironment environment, Throwable e) { - reportResolverThrowableToNR(e); + NewRelic.noticeError(e); Weaver.callOriginal(); } diff --git a/instrumentation/graphql-java-16.2/src/main/java/graphql/GraphQL_Instrumentation.java b/instrumentation/graphql-java-16.2/src/main/java/graphql/GraphQL_Instrumentation.java index 887fe8ea48..374bd487ec 100644 --- a/instrumentation/graphql-java-16.2/src/main/java/graphql/GraphQL_Instrumentation.java +++ b/instrumentation/graphql-java-16.2/src/main/java/graphql/GraphQL_Instrumentation.java @@ -1,3 +1,10 @@ +/* + * + * * Copyright 2020 New Relic Corporation. All rights reserved. + * * SPDX-License-Identifier: Apache-2.0 + * + */ + package graphql; import com.newrelic.api.agent.Trace; diff --git a/instrumentation/graphql-java-16.2/src/main/java/graphql/ParseAndValidate_Instrumentation.java b/instrumentation/graphql-java-16.2/src/main/java/graphql/ParseAndValidate_Instrumentation.java index 5ba04c7aae..c616132493 100644 --- a/instrumentation/graphql-java-16.2/src/main/java/graphql/ParseAndValidate_Instrumentation.java +++ b/instrumentation/graphql-java-16.2/src/main/java/graphql/ParseAndValidate_Instrumentation.java @@ -1,3 +1,10 @@ +/* + * + * * Copyright 2020 New Relic Corporation. All rights reserved. + * * SPDX-License-Identifier: Apache-2.0 + * + */ + package graphql; import com.newrelic.api.agent.NewRelic; diff --git a/instrumentation/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/GraphQLObfuscatorTest.java b/instrumentation/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/GraphQLObfuscatorTest.java index 2856f5b669..003baf1050 100644 --- a/instrumentation/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/GraphQLObfuscatorTest.java +++ b/instrumentation/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/GraphQLObfuscatorTest.java @@ -1,3 +1,10 @@ +/* + * + * * Copyright 2020 New Relic Corporation. All rights reserved. + * * SPDX-License-Identifier: Apache-2.0 + * + */ + package com.nr.instrumentation.graphql; import org.junit.jupiter.params.ParameterizedTest; @@ -12,17 +19,19 @@ public class GraphQLObfuscatorTest { @ParameterizedTest @CsvFileSource(resources = "/obfuscateQueryTestData/obfuscate-query-test-data.csv", delimiter = '|', numLinesToSkip = 2) - public void testObfuscateQuery(String queryToObfuscateFile, String expectedObfuscatedQueryFile) { + public void testObfuscateQuery(String queryToObfuscateFilename, String expectedObfuscatedQueryFilename) { //setup - queryToObfuscateFile = queryToObfuscateFile.trim(); - expectedObfuscatedQueryFile = expectedObfuscatedQueryFile.trim(); - String expectedObfuscatedResult = readText(OBFUSCATE_DATA_DIR, expectedObfuscatedQueryFile);//readText(expectedObfuscatedQueryFile); + queryToObfuscateFilename = queryToObfuscateFilename.trim(); + expectedObfuscatedQueryFilename = expectedObfuscatedQueryFilename.trim(); + String expectedObfuscatedResult = readText(OBFUSCATE_DATA_DIR, expectedObfuscatedQueryFilename); //given - String query = readText(OBFUSCATE_DATA_DIR, queryToObfuscateFile); + String query = readText(OBFUSCATE_DATA_DIR, queryToObfuscateFilename); //when String obfuscatedQuery = GraphQLObfuscator.obfuscate(query); + + //then assertEquals(expectedObfuscatedResult, obfuscatedQuery); } } diff --git a/instrumentation/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/GraphQLSpanUtilTest.java b/instrumentation/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/GraphQLSpanUtilTest.java index d56a794b86..189ce57a43 100644 --- a/instrumentation/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/GraphQLSpanUtilTest.java +++ b/instrumentation/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/GraphQLSpanUtilTest.java @@ -1,3 +1,10 @@ +/* + * + * * Copyright 2020 New Relic Corporation. All rights reserved. + * * SPDX-License-Identifier: Apache-2.0 + * + */ + package com.nr.instrumentation.graphql; import com.newrelic.agent.bridge.AgentBridge; diff --git a/instrumentation/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/GraphQLTransactionNameTest.java b/instrumentation/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/GraphQLTransactionNameTest.java index a51ed698c9..ba130cc1a2 100644 --- a/instrumentation/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/GraphQLTransactionNameTest.java +++ b/instrumentation/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/GraphQLTransactionNameTest.java @@ -1,3 +1,10 @@ +/* + * + * * Copyright 2020 New Relic Corporation. All rights reserved. + * * SPDX-License-Identifier: Apache-2.0 + * + */ + package com.nr.instrumentation.graphql; import graphql.language.Document; diff --git a/instrumentation/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/helper/GraphQLTestHelper.java b/instrumentation/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/helper/GraphQLTestHelper.java index ebb7792c49..9da9fdeed7 100644 --- a/instrumentation/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/helper/GraphQLTestHelper.java +++ b/instrumentation/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/helper/GraphQLTestHelper.java @@ -1,3 +1,10 @@ +/* + * + * * Copyright 2020 New Relic Corporation. All rights reserved. + * * SPDX-License-Identifier: Apache-2.0 + * + */ + package com.nr.instrumentation.graphql.helper; import graphql.language.Document; diff --git a/instrumentation/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/helper/PrivateApiStub.java b/instrumentation/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/helper/PrivateApiStub.java index 1b1394eb8c..971076d338 100644 --- a/instrumentation/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/helper/PrivateApiStub.java +++ b/instrumentation/graphql-java-16.2/src/test/java/com/nr/instrumentation/graphql/helper/PrivateApiStub.java @@ -1,3 +1,10 @@ +/* + * + * * Copyright 2020 New Relic Corporation. All rights reserved. + * * SPDX-License-Identifier: Apache-2.0 + * + */ + package com.nr.instrumentation.graphql.helper; import com.newrelic.agent.bridge.PrivateApi; diff --git a/instrumentation/graphql-java-16.2/src/test/java/graphql/GraphQL_InstrumentationTest.java b/instrumentation/graphql-java-16.2/src/test/java/graphql/GraphQL_InstrumentationTest.java index fe7adf41df..c98884a8b8 100644 --- a/instrumentation/graphql-java-16.2/src/test/java/graphql/GraphQL_InstrumentationTest.java +++ b/instrumentation/graphql-java-16.2/src/test/java/graphql/GraphQL_InstrumentationTest.java @@ -1,3 +1,10 @@ +/* + * + * * Copyright 2020 New Relic Corporation. All rights reserved. + * * SPDX-License-Identifier: Apache-2.0 + * + */ + package graphql; import com.newrelic.agent.introspec.InstrumentationTestConfig; diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/service/analytics/TracerToSpanEvent.java b/newrelic-agent/src/main/java/com/newrelic/agent/service/analytics/TracerToSpanEvent.java index 0da6cb6e9c..eb2a0f0cec 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/service/analytics/TracerToSpanEvent.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/service/analytics/TracerToSpanEvent.java @@ -126,7 +126,7 @@ public SpanEvent createSpanEvent(Tracer tracer, TransactionData transactionData, private SpanEventFactory maybeSetGraphQLAttributes(Tracer tracer, SpanEventFactory builder) { Map agentAttributes = tracer.getAgentAttributes(); boolean containsGraphQLAttributes = agentAttributes.keySet().stream().anyMatch(key -> key.contains("graphql")); - if(containsGraphQLAttributes){ + if (containsGraphQLAttributes){ agentAttributes.entrySet().stream() .filter(e -> e.getKey().contains("graphql")) .forEach(e -> builder.putAgentAttribute(e.getKey(), e.getValue()));