-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #315 from newrelic/support/graphql-NR-299885
[NR-299885] Instrumentation support for GraphQL
- Loading branch information
Showing
7 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
dependencies { | ||
implementation(project(":newrelic-security-api")) | ||
implementation("com.newrelic.agent.java:newrelic-api:${nrAPIVersion}") | ||
implementation("com.newrelic.agent.java:newrelic-weaver-api:${nrAPIVersion}") | ||
implementation("com.graphql-java:graphql-java:16.2") | ||
} | ||
|
||
jar { | ||
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.security.graphql-java-16.2' } | ||
} | ||
|
||
verifyInstrumentation { | ||
passesOnly('com.graphql-java:graphql-java:[16.0,)') | ||
excludeRegex('com.graphql-java:graphql-java:(0.0.0|201|202).*') | ||
excludeRegex('com.graphql-java:graphql-java:.*(vTEST|-beta|-alpha1|-nf-execution|-rc|-TEST).*') | ||
exclude('com.graphql-java:graphql-java:15.0') | ||
} | ||
|
||
site { | ||
title 'GraphQL Java' | ||
type 'Framework' | ||
} |
32 changes: 32 additions & 0 deletions
32
...rumentation-security/graphql-java-16.2/src/main/java/graphql/GraphQL_Instrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package graphql; | ||
|
||
import com.newrelic.api.agent.security.NewRelicSecurity; | ||
import com.newrelic.api.agent.security.schema.HttpRequest; | ||
import com.newrelic.api.agent.security.schema.HttpRequestCustomDataTypeEnum; | ||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
import graphql.execution.instrumentation.InstrumentationState; | ||
import graphql.language.Document; | ||
import graphql.schema.GraphQLSchema; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
@Weave(originalName = "graphql.GraphQL", type = MatchType.ExactClass) | ||
public class GraphQL_Instrumentation { | ||
|
||
private CompletableFuture<ExecutionResult> execute(ExecutionInput executionInput, Document document, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) { | ||
try { | ||
if (NewRelicSecurity.isHookProcessingActive()) { | ||
HttpRequest request = NewRelicSecurity.getAgent().getSecurityMetaData().getRequest(); | ||
if (executionInput.getQuery() != null && !executionInput.getQuery().isEmpty()) { | ||
request.getCustomDataType().put("*.query", HttpRequestCustomDataTypeEnum.GRAPHQL_QUERY.name()); | ||
} | ||
if (executionInput.getVariables() != null && !executionInput.getVariables().isEmpty()) { | ||
request.getCustomDataType().put("*.variables", HttpRequestCustomDataTypeEnum.GRAPHQL_VARIABLE.name()); | ||
} | ||
} | ||
} catch (Exception ignored) {} | ||
return Weaver.callOriginal(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...on-security/graphql-java-16.2/src/main/java/graphql/ParseAndValidate_Instrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package graphql; | ||
|
||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
|
||
@Weave(originalName = "graphql.ParseAndValidate", type = MatchType.ExactClass) | ||
public class ParseAndValidate_Instrumentation { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...i/src/main/java/com/newrelic/api/agent/security/schema/HttpRequestCustomDataTypeEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.newrelic.api.agent.security.schema; | ||
|
||
public enum HttpRequestCustomDataTypeEnum { | ||
GRAPHQL_QUERY, | ||
GRAPHQL_VARIABLE, | ||
|
||
NONE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters