Skip to content

Commit

Permalink
Merge pull request #543 from vtex/fix/tracing-error-log
Browse files Browse the repository at this point in the history
Fix error details not being logged in the tracing's span event
  • Loading branch information
filipewl authored Sep 20, 2023
2 parents a5066fa + 5fdcf44 commit 524bbac
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Error tracing spans not logging the details.

## [6.45.21] - 2023-09-19
### Changed
- Fix tracingMiddleware shouldTrace decision
Expand Down
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.error.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: 5 additions & 0 deletions src/tracing/LogFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export const enum ErrorReportLogFields {
*/
ERROR_KIND = 'error.kind',
ERROR_ID = 'error.id',
ERROR_MESSAGE = 'error.message',
ERROR_CODE = 'error.code',
ERROR_STACK = 'error.stack',
ERROR_METADATA_REPORT_COUNT = 'error.metadata.reportCount',
ERROR_METADATA_METRICS_INSTANTIATION_TIME = 'error.metadata.metrics.InstantiationTime',

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

const serializableError = this.toObject()
span?.log({ event: 'error', ...indexedLogs, error: serializableError })
span?.log({
event: 'error',
...indexedLogs,
[ErrorReportLogFields.ERROR_MESSAGE]: serializableError.message,
[ErrorReportLogFields.ERROR_METADATA_METRICS_INSTANTIATION_TIME]: serializableError.metadata?.reportCount,
[ErrorReportLogFields.ERROR_METADATA_REPORT_COUNT]: serializableError.metadata?.metrics?.instantiationTime,
[ErrorReportLogFields.ERROR_STACK]: serializableError.stack,
[ErrorReportLogFields.ERROR_CODE]: serializableError.code,
})

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

0 comments on commit 524bbac

Please sign in to comment.