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 data fetching environment hint to breadcrumb (#3413) #3431

Merged
merged 6 commits into from
May 28, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Features

- Publish Gradle module metadata ([#3422](https://github.com/getsentry/sentry-java/pull/3422))
- Add data fetching environment hint to breadcrumb for GraphQL (#3413) ([#3431](https://github.com/getsentry/sentry-java/pull/3431))

### Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
import graphql.schema.GraphQLObjectType;
import graphql.schema.GraphQLOutputType;
import io.sentry.Breadcrumb;
import io.sentry.Hint;
import io.sentry.IScopes;
import io.sentry.ISpan;
import io.sentry.NoOpScopes;
import io.sentry.Sentry;
import io.sentry.SentryIntegrationPackageStorage;
import io.sentry.SpanStatus;
import io.sentry.TypeCheckHint;
import io.sentry.util.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -300,13 +302,16 @@ private boolean isIgnored(final @Nullable String errorType) {
return environment -> {
final @Nullable ExecutionStepInfo executionStepInfo = environment.getExecutionStepInfo();
if (executionStepInfo != null) {
Hint hint = new Hint();
hint.set(TypeCheckHint.GRAPHQL_DATA_FETCHING_ENVIRONMENT, environment);
scopesFromContext(parameters.getExecutionContext().getGraphQLContext())
.addBreadcrumb(
Breadcrumb.graphqlDataFetcher(
StringUtils.toString(executionStepInfo.getPath()),
GraphqlStringUtils.fieldToString(executionStepInfo.getField()),
GraphqlStringUtils.typeToString(executionStepInfo.getType()),
GraphqlStringUtils.objectTypeToString(executionStepInfo.getObjectType())));
GraphqlStringUtils.objectTypeToString(executionStepInfo.getObjectType())),
hint);
}
final TracingState tracingState = parameters.getInstrumentationState();
final ISpan transaction = tracingState.getTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ import graphql.schema.GraphQLObjectType
import graphql.schema.GraphQLScalarType
import graphql.schema.GraphQLSchema
import io.sentry.Breadcrumb
import io.sentry.Hint
import io.sentry.IScopes
import io.sentry.Sentry
import io.sentry.SentryOptions
import io.sentry.SentryTracer
import io.sentry.TransactionContext
import io.sentry.TypeCheckHint
import io.sentry.graphql.ExceptionReporter.ExceptionDetails
import io.sentry.graphql.SentryInstrumentation.SENTRY_EXCEPTIONS_CONTEXT_KEY
import io.sentry.graphql.SentryInstrumentation.TracingState
Expand Down Expand Up @@ -245,6 +247,10 @@ class SentryInstrumentationAnotherTest {
assertEquals("myFieldName", breadcrumb.data["field"])
assertEquals("MyResponseType", breadcrumb.data["type"])
assertEquals("QUERY", breadcrumb.data["object_type"])
},
org.mockito.kotlin.check<Hint> { hint ->
val environment = hint.getAs(TypeCheckHint.GRAPHQL_DATA_FETCHING_ENVIRONMENT, DataFetchingEnvironment::class.java)
assertNotNull(environment)
}
)
}
Expand Down
1 change: 1 addition & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -3343,6 +3343,7 @@ public final class io/sentry/TypeCheckHint {
public static final field ANDROID_VIEW Ljava/lang/String;
public static final field APOLLO_REQUEST Ljava/lang/String;
public static final field APOLLO_RESPONSE Ljava/lang/String;
public static final field GRAPHQL_DATA_FETCHING_ENVIRONMENT Ljava/lang/String;
public static final field GRAPHQL_HANDLER_PARAMETERS Ljava/lang/String;
public static final field JUL_LOG_RECORD Ljava/lang/String;
public static final field LOG4J_LOG_EVENT Ljava/lang/String;
Expand Down
3 changes: 3 additions & 0 deletions sentry/src/main/java/io/sentry/TypeCheckHint.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public final class TypeCheckHint {
/** Used for GraphQl handler exceptions. */
public static final String GRAPHQL_HANDLER_PARAMETERS = "graphql:handlerParameters";

/** Used for GraphQl data fetcher breadcrumbs. */
public static final String GRAPHQL_DATA_FETCHING_ENVIRONMENT = "graphql:dataFetchingEnvironment";

/** Used for JUL breadcrumbs. */
public static final String JUL_LOG_RECORD = "jul:logRecord";

Expand Down
Loading