-
-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,460 additions
and
389 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
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
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 @@ | ||
public final class io/sentry/graphql22/BuildConfig { | ||
public static final field SENTRY_GRAPHQL_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 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_GRAPHQL_SDK_NAME", "\"${Config.Sentry.SENTRY_GRAPHQL_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 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 CompletableFuture<ExecutionResult> instrumentExecutionResult( | ||
ExecutionResult executionResult, | ||
InstrumentationExecutionParameters parameters, | ||
final @NotNull InstrumentationState state) { | ||
return super.instrumentExecutionResult(executionResult, parameters, state) | ||
.whenComplete( | ||
(result, exception) -> { | ||
instrumentation.instrumentExecutionResultComplete(parameters, result, exception); | ||
}); | ||
} | ||
|
||
@Override | ||
public @NotNull 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.