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

Fix error details not being logged in the tracing's span event #543

Merged
merged 5 commits into from
Sep 20, 2023
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
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()
Copy link
Contributor Author

@filipewl filipewl Sep 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toObject returns some JS object with error details.

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
Loading