-
-
Notifications
You must be signed in to change notification settings - Fork 452
Add support for v22 of graphql-java
via sentry-graphql-22
#3740
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ba9af62
attach request body for application/x-www-form-urlencoded
adinauer f38c4bf
extend tests
adinauer 72aa792
changelog
adinauer 02ed018
Add support for v22 of graphql-java, new modules sentry-graphql-22 an…
adinauer 3cc76b4
Add back callback interface and constants as deprecated
adinauer a51e541
Merge branch '8.x.x' into fix/support-graphql-v22
adinauer 2b401c2
changelog
adinauer 766b86a
CR changes
adinauer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 @@ | ||
public final class io/sentry/graphql22/BuildConfig { | ||
public static final field SENTRY_GRAPHQL22_SDK_NAME Ljava/lang/String; | ||
public static final field VERSION_NAME Ljava/lang/String; | ||
} | ||
|
||
public final class io/sentry/graphql22/SentryInstrumentation : graphql/execution/instrumentation/SimpleInstrumentation { | ||
public static final field SENTRY_EXCEPTIONS_CONTEXT_KEY Ljava/lang/String; | ||
public static final field SENTRY_SCOPES_CONTEXT_KEY Ljava/lang/String; | ||
public fun <init> (Lio/sentry/graphql/SentryGraphqlInstrumentation$BeforeSpanCallback;Lio/sentry/graphql/SentrySubscriptionHandler;Lio/sentry/graphql/ExceptionReporter;Ljava/util/List;)V | ||
public fun <init> (Lio/sentry/graphql/SentryGraphqlInstrumentation$BeforeSpanCallback;Lio/sentry/graphql/SentrySubscriptionHandler;Z)V | ||
public fun <init> (Lio/sentry/graphql/SentryGraphqlInstrumentation$BeforeSpanCallback;Lio/sentry/graphql/SentrySubscriptionHandler;ZLjava/util/List;)V | ||
public fun <init> (Lio/sentry/graphql/SentrySubscriptionHandler;Z)V | ||
public fun beginExecuteOperation (Lgraphql/execution/instrumentation/parameters/InstrumentationExecuteOperationParameters;Lgraphql/execution/instrumentation/InstrumentationState;)Lgraphql/execution/instrumentation/InstrumentationContext; | ||
public fun beginExecution (Lgraphql/execution/instrumentation/parameters/InstrumentationExecutionParameters;Lgraphql/execution/instrumentation/InstrumentationState;)Lgraphql/execution/instrumentation/InstrumentationContext; | ||
public fun createState (Lgraphql/execution/instrumentation/parameters/InstrumentationCreateStateParameters;)Lgraphql/execution/instrumentation/InstrumentationState; | ||
public fun instrumentDataFetcher (Lgraphql/schema/DataFetcher;Lgraphql/execution/instrumentation/parameters/InstrumentationFieldFetchParameters;Lgraphql/execution/instrumentation/InstrumentationState;)Lgraphql/schema/DataFetcher; | ||
public fun instrumentExecutionResult (Lgraphql/ExecutionResult;Lgraphql/execution/instrumentation/parameters/InstrumentationExecutionParameters;Lgraphql/execution/instrumentation/InstrumentationState;)Ljava/util/concurrent/CompletableFuture; | ||
} | ||
|
||
public abstract interface class io/sentry/graphql22/SentryInstrumentation$BeforeSpanCallback : io/sentry/graphql/SentryGraphqlInstrumentation$BeforeSpanCallback { | ||
} | ||
|
This file contains hidden or 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,89 @@ | ||
import net.ltgt.gradle.errorprone.errorprone | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
plugins { | ||
`java-library` | ||
kotlin("jvm") | ||
jacoco | ||
id(Config.QualityPlugins.errorProne) | ||
id(Config.QualityPlugins.gradleVersions) | ||
id(Config.BuildPlugins.buildConfig) version Config.BuildPlugins.buildConfigVersion | ||
} | ||
|
||
configure<JavaPluginExtension> { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
tasks.withType<KotlinCompile>().configureEach { | ||
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString() | ||
kotlinOptions.languageVersion = Config.kotlinCompatibleLanguageVersion | ||
} | ||
|
||
dependencies { | ||
api(projects.sentry) | ||
api(projects.sentryGraphqlCore) | ||
compileOnly(Config.Libs.graphQlJava22) | ||
|
||
compileOnly(Config.CompileOnly.nopen) | ||
errorprone(Config.CompileOnly.nopenChecker) | ||
errorprone(Config.CompileOnly.errorprone) | ||
errorprone(Config.CompileOnly.errorProneNullAway) | ||
compileOnly(Config.CompileOnly.jetbrainsAnnotations) | ||
|
||
// tests | ||
testImplementation(projects.sentry) | ||
testImplementation(projects.sentryTestSupport) | ||
testImplementation(kotlin(Config.kotlinStdLib)) | ||
testImplementation(Config.TestLibs.kotlinTestJunit) | ||
testImplementation(Config.TestLibs.mockitoKotlin) | ||
testImplementation(Config.TestLibs.mockitoInline) | ||
testImplementation(Config.TestLibs.mockWebserver) | ||
testImplementation(Config.Libs.okhttp) | ||
testImplementation(Config.Libs.springBootStarterGraphql) | ||
testImplementation("com.netflix.graphql.dgs:graphql-error-types:4.9.2") | ||
testImplementation(Config.Libs.graphQlJava22) | ||
} | ||
|
||
configure<SourceSetContainer> { | ||
test { | ||
java.srcDir("src/test/java") | ||
} | ||
} | ||
|
||
jacoco { | ||
toolVersion = Config.QualityPlugins.Jacoco.version | ||
} | ||
|
||
tasks.jacocoTestReport { | ||
reports { | ||
xml.required.set(true) | ||
html.required.set(false) | ||
} | ||
} | ||
|
||
tasks { | ||
jacocoTestCoverageVerification { | ||
violationRules { | ||
rule { limit { minimum = Config.QualityPlugins.Jacoco.minimumCoverage } } | ||
} | ||
} | ||
check { | ||
dependsOn(jacocoTestCoverageVerification) | ||
dependsOn(jacocoTestReport) | ||
} | ||
} | ||
|
||
tasks.withType<JavaCompile>().configureEach { | ||
options.errorprone { | ||
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR) | ||
option("NullAway:AnnotatedPackages", "io.sentry") | ||
} | ||
} | ||
|
||
buildConfig { | ||
useJavaOutput() | ||
packageName("io.sentry.graphql22") | ||
buildConfigField("String", "SENTRY_GRAPHQL22_SDK_NAME", "\"${Config.Sentry.SENTRY_GRAPHQL22_SDK_NAME}\"") | ||
buildConfigField("String", "VERSION_NAME", "\"${project.version}\"") | ||
} |
163 changes: 163 additions & 0 deletions
163
sentry-graphql-22/src/main/java/io/sentry/graphql22/SentryInstrumentation.java
This file contains hidden or 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,163 @@ | ||
package io.sentry.graphql22; | ||
|
||
import graphql.ExecutionResult; | ||
import graphql.execution.instrumentation.InstrumentationContext; | ||
import graphql.execution.instrumentation.InstrumentationState; | ||
import graphql.execution.instrumentation.parameters.InstrumentationCreateStateParameters; | ||
import graphql.execution.instrumentation.parameters.InstrumentationExecuteOperationParameters; | ||
import graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters; | ||
import graphql.execution.instrumentation.parameters.InstrumentationFieldFetchParameters; | ||
import graphql.schema.DataFetcher; | ||
import io.sentry.SentryIntegrationPackageStorage; | ||
import io.sentry.graphql.ExceptionReporter; | ||
import io.sentry.graphql.SentryGraphqlInstrumentation; | ||
import io.sentry.graphql.SentrySubscriptionHandler; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.jetbrains.annotations.TestOnly; | ||
|
||
@SuppressWarnings("deprecation") | ||
public final class SentryInstrumentation | ||
extends graphql.execution.instrumentation.SimpleInstrumentation { | ||
|
||
/** | ||
* @deprecated please use {@link SentryGraphqlInstrumentation#SENTRY_SCOPES_CONTEXT_KEY} | ||
*/ | ||
@Deprecated | ||
public static final @NotNull String SENTRY_SCOPES_CONTEXT_KEY = | ||
SentryGraphqlInstrumentation.SENTRY_SCOPES_CONTEXT_KEY; | ||
|
||
/** | ||
* @deprecated please use {@link SentryGraphqlInstrumentation#SENTRY_EXCEPTIONS_CONTEXT_KEY} | ||
*/ | ||
@Deprecated | ||
public static final @NotNull String SENTRY_EXCEPTIONS_CONTEXT_KEY = | ||
SentryGraphqlInstrumentation.SENTRY_EXCEPTIONS_CONTEXT_KEY; | ||
|
||
private static final String TRACE_ORIGIN = "auto.graphql.graphql22"; | ||
private final @NotNull SentryGraphqlInstrumentation instrumentation; | ||
|
||
/** | ||
* @param beforeSpan callback when a span is created | ||
* @param subscriptionHandler can report subscription errors | ||
* @param captureRequestBodyForNonSubscriptions false if request bodies should not be captured by | ||
* this integration for query and mutation operations. This can be used to prevent unnecessary | ||
* work by not adding the request body when another integration will add it anyways, as is the | ||
* case with our spring integration for WebMVC. | ||
*/ | ||
public SentryInstrumentation( | ||
final @Nullable SentryGraphqlInstrumentation.BeforeSpanCallback beforeSpan, | ||
final @NotNull SentrySubscriptionHandler subscriptionHandler, | ||
final boolean captureRequestBodyForNonSubscriptions) { | ||
this( | ||
beforeSpan, | ||
subscriptionHandler, | ||
new ExceptionReporter(captureRequestBodyForNonSubscriptions), | ||
new ArrayList<>()); | ||
} | ||
|
||
/** | ||
* @param beforeSpan callback when a span is created | ||
* @param subscriptionHandler can report subscription errors | ||
* @param captureRequestBodyForNonSubscriptions false if request bodies should not be captured by | ||
* this integration for query and mutation operations. This can be used to prevent unnecessary | ||
* work by not adding the request body when another integration will add it anyways, as is the | ||
* case with our spring integration for WebMVC. | ||
* @param ignoredErrorTypes list of error types that should not be captured and sent to Sentry | ||
*/ | ||
public SentryInstrumentation( | ||
final @Nullable SentryGraphqlInstrumentation.BeforeSpanCallback beforeSpan, | ||
final @NotNull SentrySubscriptionHandler subscriptionHandler, | ||
final boolean captureRequestBodyForNonSubscriptions, | ||
final @NotNull List<String> ignoredErrorTypes) { | ||
this( | ||
beforeSpan, | ||
subscriptionHandler, | ||
new ExceptionReporter(captureRequestBodyForNonSubscriptions), | ||
ignoredErrorTypes); | ||
} | ||
|
||
@TestOnly | ||
public SentryInstrumentation( | ||
final @Nullable SentryGraphqlInstrumentation.BeforeSpanCallback beforeSpan, | ||
final @NotNull SentrySubscriptionHandler subscriptionHandler, | ||
final @NotNull ExceptionReporter exceptionReporter, | ||
final @NotNull List<String> ignoredErrorTypes) { | ||
this.instrumentation = | ||
new SentryGraphqlInstrumentation( | ||
beforeSpan, subscriptionHandler, exceptionReporter, ignoredErrorTypes, TRACE_ORIGIN); | ||
SentryIntegrationPackageStorage.getInstance().addIntegration("GraphQL-v22"); | ||
SentryIntegrationPackageStorage.getInstance() | ||
.addPackage("maven:io.sentry:sentry-graphql-22", BuildConfig.VERSION_NAME); | ||
} | ||
|
||
/** | ||
* @param subscriptionHandler can report subscription errors | ||
* @param captureRequestBodyForNonSubscriptions false if request bodies should not be captured by | ||
* this integration for query and mutation operations. This can be used to prevent unnecessary | ||
* work by not adding the request body when another integration will add it anyways, as is the | ||
* case with our spring integration for WebMVC. | ||
*/ | ||
public SentryInstrumentation( | ||
final @NotNull SentrySubscriptionHandler subscriptionHandler, | ||
final boolean captureRequestBodyForNonSubscriptions) { | ||
this(null, subscriptionHandler, captureRequestBodyForNonSubscriptions); | ||
} | ||
|
||
@Override | ||
public @NotNull InstrumentationState createState( | ||
final @NotNull InstrumentationCreateStateParameters parameters) { | ||
return instrumentation.createState(); | ||
} | ||
|
||
@Override | ||
public @Nullable InstrumentationContext<ExecutionResult> beginExecution( | ||
final @NotNull InstrumentationExecutionParameters parameters, | ||
final @NotNull InstrumentationState state) { | ||
final SentryGraphqlInstrumentation.TracingState tracingState = | ||
InstrumentationState.ofState(state); | ||
instrumentation.beginExecution(parameters, tracingState); | ||
return super.beginExecution(parameters, state); | ||
} | ||
|
||
@Override | ||
public @NotNull CompletableFuture<ExecutionResult> instrumentExecutionResult( | ||
final @NotNull ExecutionResult executionResult, | ||
final @NotNull InstrumentationExecutionParameters parameters, | ||
final @NotNull InstrumentationState state) { | ||
return super.instrumentExecutionResult(executionResult, parameters, state) | ||
.whenComplete( | ||
(result, exception) -> { | ||
instrumentation.instrumentExecutionResultComplete(parameters, result, exception); | ||
}); | ||
} | ||
|
||
@Override | ||
public @Nullable InstrumentationContext<ExecutionResult> beginExecuteOperation( | ||
final @NotNull InstrumentationExecuteOperationParameters parameters, | ||
final @NotNull InstrumentationState state) { | ||
instrumentation.beginExecuteOperation(parameters); | ||
return super.beginExecuteOperation(parameters, state); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings({"FutureReturnValueIgnored", "deprecation"}) | ||
public @NotNull DataFetcher<?> instrumentDataFetcher( | ||
final @NotNull DataFetcher<?> dataFetcher, | ||
final @NotNull InstrumentationFieldFetchParameters parameters, | ||
final @NotNull InstrumentationState state) { | ||
final SentryGraphqlInstrumentation.TracingState tracingState = | ||
InstrumentationState.ofState(state); | ||
return instrumentation.instrumentDataFetcher(dataFetcher, parameters, tracingState); | ||
} | ||
|
||
/** | ||
* @deprecated please use {@link SentryGraphqlInstrumentation.BeforeSpanCallback} | ||
*/ | ||
@Deprecated | ||
@FunctionalInterface | ||
public interface BeforeSpanCallback extends SentryGraphqlInstrumentation.BeforeSpanCallback {} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.