Skip to content

Commit

Permalink
Checkout: Add tags to sentry error log in checkout error boundary (#9…
Browse files Browse the repository at this point in the history
…7472)

* Add tags to sentry error log in checkout error boundary

* Include serialized_message
  • Loading branch information
sirbrillig authored Dec 13, 2024
1 parent 3180f34 commit c72ee5b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions client/my-sites/checkout/src/lib/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@ function serializeCaughtError(
// type. It can be used to keep another Error but it could also be anything
// else so let's not make any assumptions. Also things other than Error
// objects can be thrown so let's not even assume this is an Error.
error: unknown
error: unknown,
options: {
excludeStack?: boolean;
} = {}
): string {
const messages = [];
messages.push( getErrorMessageFromError( error ) );
let hasCause = false;
const errorObject = error as Error;
if ( 'cause' in errorObject && errorObject.cause ) {
hasCause = true;
const cause = serializeCaughtError( errorObject.cause );
const cause = serializeCaughtError( errorObject.cause, options );
messages.push( `(Cause: ${ cause })` );
}
// We only include the stack trace if there is no cause, meaning this is
// the deepest error in the chain. The others are all likely re-thrown
// errors so we should know their stack trace already.
if ( ! hasCause && 'stack' in errorObject && errorObject.stack ) {
if ( ! options?.excludeStack && ! hasCause && 'stack' in errorObject && errorObject.stack ) {
messages.push( `(Stack: ${ errorObject.stack })` );
}
return messages.join( '; ' );
Expand Down Expand Up @@ -59,7 +62,14 @@ export function logStashLoadErrorEvent(
error: Error,
additionalData: Record< string, string | number | undefined > = {}
): Promise< void > {
captureException( error.cause ? error.cause : error );
captureException( error, {
tags: {
serialized_message: serializeCaughtError( error, { excludeStack: true } ),
calypso_checkout: 'true',
error_type: errorType,
...additionalData,
},
} );
return logStashEvent( 'composite checkout load error', {
...additionalData,
type: errorType,
Expand Down

0 comments on commit c72ee5b

Please sign in to comment.