aws / aws-xray-sdk-node

The official AWS X-Ray SDK for Node.js.
Apache License 2.0
266 stars 155 forks source link

fix(core): serialize bigint in metadata to string #619

Closed dreamorosi closed 10 months ago

dreamorosi commented 10 months ago

Issue #, if available: closes #616

Description of changes:

This PR introduces a new method called serialize to the prototype of the Segment and Subsegment objects. This method wraps the JSON.stringify() call that was previously made by the toString() and format() methods of these two classes.

When calling the JSON.stringify() function, the method also passes a replacer function. This replacer for now includes an if statement that casts BigInt objects to string. This avoids runtimes errors described in the linked issue.

By extracting the method, customers can easily override it and extend the replacer to suit their needs.

In addition to the method, the PR includes also changes to the type definition and the addition of a test.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

codecov-commenter commented 10 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (6a9f999) 83.41% compared to head (4a2e140) 83.49%. Report is 1 commits behind head on master.

:exclamation: Current head 4a2e140 differs from pull request most recent head b3e3567. Consider uploading reports for the commit b3e3567 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #619 +/- ## ========================================== + Coverage 83.41% 83.49% +0.07% ========================================== Files 37 37 Lines 1797 1805 +8 ========================================== + Hits 1499 1507 +8 Misses 298 298 ``` [see 3 files with indirect coverage changes](https://app.codecov.io/gh/aws/aws-xray-sdk-node/pull/619/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

dreamorosi commented 10 months ago

Hi @carolabadeer thanks for the review and the comments, I have committed both your suggestions!