Skip to content
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

Add support for v22 of graphql-java via sentry-graphql-22 #3740

Open
wants to merge 2 commits into
base: feat/spring-request-body-form
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ targets:
maven:io.sentry:sentry-apollo:
maven:io.sentry:sentry-jdbc:
maven:io.sentry:sentry-graphql:
# maven:io.sentry:sentry-graphql-core:
# maven:io.sentry:sentry-graphql-22:
maven:io.sentry:sentry-quartz:
maven:io.sentry:sentry-okhttp:
maven:io.sentry:sentry-android-navigation:
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report_java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ body:
- sentry-logback
- sentry-log4j2
- sentry-graphql
- sentry-graphql-22
- sentry-quartz
- sentry-openfeign
- sentry-apache-http-client-5
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Sentry SDK for Java and Android
| sentry-log4j2 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-log4j2/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-log4j2) |
| sentry-bom | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-bom/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-bom) |
| sentry-graphql | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-graphql/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-graphql) |
| sentry-graphql-core | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-graphql-core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-graphql-core) |
| sentry-graphql-22 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-graphql-22/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-graphql-22) |
| sentry-quartz | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-quartz/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-quartz) |
| sentry-openfeign | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-openfeign/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-openfeign) |
| sentry-opentelemetry-agent | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-opentelemetry-agent/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-opentelemetry-agent) |
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ object Config {
val p6spy = "p6spy:p6spy:3.9.1"

val graphQlJava = "com.graphql-java:graphql-java:17.3"
val graphQlJava22 = "com.graphql-java:graphql-java:22.1"

val quartz = "org.quartz-scheduler:quartz:2.3.0"

Expand Down
22 changes: 22 additions & 0 deletions sentry-graphql-22/api/sentry-graphql-22.api
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 {
}

89 changes: 89 additions & 0 deletions sentry-graphql-22/build.gradle.kts
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}\"")
}
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 {}
}
Loading
Loading