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

feat(tracer): add try/catch logic to decorator and middleware close #1716

Merged
merged 6 commits into from
Sep 28, 2023

Conversation

dreamorosi
Copy link
Contributor

Description of your changes

This PR introduces some try/catch logic to the parts of the code that are in charge of closing a subsegment in decorators and middleware usage.

As reported in the linked issue, if the segment contains metadata that cannot be serialized calling the subsegment.close() (or subsegment.flush()) method will throw an error.

This happens because the segment is serialized using JSON.stringify() twice right before being emitted and so if the stringify method encounters an entity that doesn't know how to serialize, it'll throw an error.

Even though the linked issue propsosed to add this try/catch logic to the tracer.putMetdata() method, this would be useless as the serialization is done just-in-time before emitting the segment.

For this reason we must guard against runtime errors when closing the segment that we (Powertools) opened. In this case, we are now catching the error and logging a warning.

Customers can use this warning to:

  • detect potential issues in the data being emitted using the provided stack trace
  • be warned about potential data loss

It's important to note that this fix only safeguards against runtime errors for segments that Tracer opens under the hood. If customers try to call segment.close() directly on a segment the error will still be thrown.

We are attempting to work with the X-Ray team to provide a more permanent fix.

Related issues, RFCs

Issue number: #1713

Checklist

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my change is effective and works
  • The PR title follows the conventional commit semantics

Breaking change checklist

Is it a breaking change?: NO

  • I have documented the migration process
  • I have added, implemented necessary warnings (if it can live side by side)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@dreamorosi dreamorosi requested a review from a team as a code owner September 27, 2023 16:20
@boring-cyborg boring-cyborg bot added tracer This item relates to the Tracer Utility tests PRs that add or change tests labels Sep 27, 2023
@pull-request-size pull-request-size bot added the size/L PRs between 100-499 LOC label Sep 27, 2023
@dreamorosi dreamorosi self-assigned this Sep 27, 2023
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
29.5% 29.5% Duplication

@github-actions github-actions bot added the feature PRs that introduce new features or minor changes label Sep 27, 2023
@dreamorosi
Copy link
Contributor Author

@am29d am29d merged commit be16b59 into main Sep 28, 2023
29 checks passed
@am29d am29d deleted the feat/try-catch/putMetadata branch September 28, 2023 14:12
@dreamorosi dreamorosi linked an issue Sep 28, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature PRs that introduce new features or minor changes size/L PRs between 100-499 LOC tests PRs that add or change tests tracer This item relates to the Tracer Utility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: support BigInt serialization in segment metadata
2 participants