-
Notifications
You must be signed in to change notification settings - Fork 25
DEVPROD-356: Add Sentry grouping #2262
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,9 +1,11 @@ | ||||
import { ErrorResponse } from "@apollo/client/link/error"; | ||||
import { | ||||
captureException, | ||||
ErrorBoundary as SentryErrorBoundary, | ||||
getCurrentHub, | ||||
init, | ||||
Replay, | ||||
setTag, | ||||
withScope, | ||||
} from "@sentry/react"; | ||||
import type { Scope, SeverityLevel } from "@sentry/react"; | ||||
|
@@ -38,14 +40,35 @@ const initializeSentry = () => { | |||
|
||||
const isInitialized = () => !!getCurrentHub().getClient(); | ||||
|
||||
type ErrorMetadata = { | ||||
gqlErr?: ErrorResponse["graphQLErrors"][0]; | ||||
operationName?: ErrorResponse["operation"]["operationName"]; | ||||
variables?: ErrorResponse["operation"]["variables"]; | ||||
}; | ||||
|
||||
const sendError = ( | ||||
err: Error, | ||||
severity: SeverityLevel, | ||||
metadata?: { [key: string]: any }, | ||||
metadata?: ErrorMetadata, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This typing is technically broken since spruce/src/utils/errorReporting.ts Line 10 in 45550f1
{ [key:string]: any } so this type is never actually used.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is also not flexible enough to allow for any metadata to be passed in once the typing in reportError is fixed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the typing in |
||||
) => { | ||||
withScope((scope) => { | ||||
setScope(scope, { level: severity, context: metadata }); | ||||
|
||||
const { gqlErr, operationName } = metadata ?? {}; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we improve the type safety on these by adding |
||||
|
||||
// Add additional sorting for GraphQL errors | ||||
if (operationName) { | ||||
// A custom fingerprint allows for more intelligent grouping | ||||
const fingerprint = [operationName]; | ||||
if (gqlErr?.path && Array.isArray(gqlErr.path)) { | ||||
fingerprint.push(...gqlErr.path); | ||||
} | ||||
scope.setFingerprint(fingerprint); | ||||
|
||||
// Apply tag, which is a searchable/filterable property | ||||
setTag("operationName", operationName); | ||||
} | ||||
|
||||
captureException(err); | ||||
}); | ||||
}; | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are all actually typed from
import { GraphQLError } from "graphql";
since they are properties of the GraphQL request and not specific to Apollo.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the correct typing of Apollo's onError handlers if I'm not mistaken: https://github.com/apollographql/apollo-client/blob/17ccc42825d0b0355212f3ac823780edb467ea77/src/link/error/index.ts#L28
GraphQLError
doesn't includeoperationName
orvariables
: https://github.com/graphql/graphql-js/blob/9c90a23dd430ba7b9db3d566b084e9f66aded346/src/error/GraphQLError.ts#L41These are Apollo-specific since they come from Apollo links; the GraphQL request is just a part of the data in the
graphQLErrors
field.