Skip to content

Commit

Permalink
Flatten the error object details
Browse files Browse the repository at this point in the history
  • Loading branch information
filipewl committed Sep 19, 2023
1 parent 0edfbe4 commit 0dd7bf3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export const registerSharedTestSuite = (testSuiteConfig: TestSuiteConfig) => {
expect((requestSpan as any)._logs[len - 1].fields[ErrorReportLogFields.ERROR_ID]).toBeDefined()
expect((requestSpan as any)._logs[len - 1].fields[ErrorReportLogFields.ERROR_KIND]).toBeDefined()
expect(
((requestSpan as any)._logs[len - 1].fields[ErrorReportLogFields.ERROR_DETAILS].message as string).startsWith(
((requestSpan as any)._logs[len - 1].fields[ErrorReportLogFields.ERROR_MESSAGE] as string).startsWith(
testSuiteConfig.expects.error!.errorMessagePrefix
)
).toBeTruthy()
Expand Down
5 changes: 4 additions & 1 deletion src/tracing/LogFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export const enum ErrorReportLogFields {
*/
ERROR_KIND = 'error.kind',
ERROR_ID = 'error.id',
ERROR_DETAILS = 'error.details',
ERROR_MESSAGE = 'error.message',
ERROR_CODE = 'error.code',
ERROR_STACK = 'error.stack',
ERROR_METADATA = 'error.metadata',

/**
* VTEX's Infra errors adds error details to the response
Expand Down
9 changes: 8 additions & 1 deletion src/tracing/errorReporting/ErrorReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ export class ErrorReport extends ErrorReportBase {
}

const serializableError = this.toObject()
span.log({ event: 'error', ...indexedLogs, [ErrorReportLogFields.ERROR_DETAILS]: serializableError })
span.log({
event: 'error',
...indexedLogs,
[ErrorReportLogFields.ERROR_MESSAGE]: serializableError.message,
[ErrorReportLogFields.ERROR_METADATA]: serializableError.metadata,
[ErrorReportLogFields.ERROR_STACK]: serializableError.stack,
[ErrorReportLogFields.ERROR_CODE]: serializableError.code,
})

if (logger && this.shouldLogToSplunk(span)) {
logger.error(serializableError)
Expand Down

0 comments on commit 0dd7bf3

Please sign in to comment.