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

Conversation

filipewl
Copy link
Contributor

@filipewl filipewl commented Sep 14, 2023

What is the purpose of this pull request?

Fix how the field "error" of an "error" span event is not displaying the error's details.

Before After
CleanShot 2023-09-14 at 14 01 28@2x CleanShot 2023-09-19 at 12 24 19

What problem is this solving?

It appears this "error" field is categorized as a boolean type, so the expected error details isn't being used. By renaming this field to "error.details", we expect to have it displayed on Honeycomb.

How should this be manually tested?

  1. Visit https://filipelimaxtracing--storecomponents.myvtex.com/ where I have yarn-linked this branch to a vtex-linked pages-graphql and render-server apps.
  2. To avoid being sampled, use a browser extension to include the header jaeger-debug-id=ANY_ID_YOU_WANT_USE_TO_QUERY_HONEYCOMB.
  3. Navigate through the store to send some traces to Honeycomb.
  4. In Honeycomb's Query page, add a WHERE filter to jaeger-debug-id = ANY_ID_YOU_WANT_USE_TO_QUERY_HONEYCOMB to find your traces.

Example of a trace with error span. Check the "Span events" tab on the side bar and expand the "error" event.

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Requires change to documentation, which has been updated accordingly.

@filipewl filipewl added the bug label Sep 14, 2023
@filipewl filipewl self-assigned this Sep 14, 2023
@@ -61,7 +61,7 @@ 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.

@@ -61,7 +61,7 @@ export class ErrorReport extends ErrorReportBase {
}

const serializableError = this.toObject()
span.log({ event: 'error', ...indexedLogs, error: serializableError })
span.log({ event: 'error', ...indexedLogs, 'error.details': serializableError })
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of the JS object mentioned above, we're always getting a boolean for the field error. I think by using a different key, that doesn't conflict with a general "error" name, should fix it.

The span event "error" logs a field called "error" that is expected to contain the error's details, but is instead displaying as a boolean on Honeycomb. This is causing us to miss some important information when debuging an error span.

This issue seems to be that a field called "error" is already definded as boolean. A solution would be to rename this field, in this specific span event, to something like "error.details" (we already have "error.id" and "error.kind").
@filipewl filipewl marked this pull request as ready for review September 14, 2023 17:33
Copy link
Contributor

@mairatma mairatma left a comment

Choose a reason for hiding this comment

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

@filipewl it might be worth talking to someone from the Observability team to see how to test this. Isn't there a way to force a trace to be created for a request to linked code?

event: 'error',
...indexedLogs,
[ErrorReportLogFields.ERROR_MESSAGE]: serializableError.message,
[ErrorReportLogFields.ERROR_METADATA]: serializableError.metadata,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to manually serialize this as well? It returns an object from its type definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! I'll flatten this object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done here.

@filipewl
Copy link
Contributor Author

filipewl commented Sep 19, 2023

@filipewl it might be worth talking to someone from the Observability team to see how to test this. Isn't there a way to force a trace to be created for a request to linked code?

@mairatma, I figured out this with @arturpimentel. There's a header jaeger-debug-id that you can include in the requests so they won't be sampled and that can be later used on Honeycomb to find your traces. I've updated the PR's description to explain how to test and added a link to a tracing example.

Copy link
Contributor

@mairatma mairatma left a comment

Choose a reason for hiding this comment

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

Awesome, thanks! Lgtm

Addresses this comment:
#543 (comment)
@@ -65,7 +65,8 @@ export class ErrorReport extends ErrorReportBase {
event: 'error',
...indexedLogs,
[ErrorReportLogFields.ERROR_MESSAGE]: serializableError.message,
[ErrorReportLogFields.ERROR_METADATA]: serializableError.metadata,
[ErrorReportLogFields.ERROR_METADATA_METRICS_INSTANTIATION_TIME]: serializableError.metadata.reportCount,
Copy link
Contributor

Choose a reason for hiding this comment

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

@filipewl is there any chance that metadata may be null or undefined? Just making sure we won't throw here by mistake.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Type-wise, it doesn't look like it can, but I'm afraid of runtime data... I added some optional chaining here to be safe.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also afraid, thanks!

Type-wise it cannot be null but I'm not sure we can trust with runtime data.

Addresses this comment:
#543 (comment)
Conflicts:
	CHANGELOG.md
	src/tracing/errorReporting/ErrorReport.ts
@filipewl filipewl merged commit 524bbac into master Sep 20, 2023
2 checks passed
@filipewl filipewl deleted the fix/tracing-error-log branch September 20, 2023 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants