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(core): serialize bigint in metadata to string #619

Merged
merged 5 commits into from
Oct 21, 2023
Merged

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

merged 5 commits into from
Oct 21, 2023

Conversation

dreamorosi
Copy link
Contributor

@dreamorosi dreamorosi commented Oct 18, 2023

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.

Copy link

@misterjoshua misterjoshua left a comment

Choose a reason for hiding this comment

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

Looks pretty good. I have a few suggestions.

child.addMetadata('key', BigInt(9007199254740991));
child.flush();
emitStub.should.have.been.calledOnce;
});

Choose a reason for hiding this comment

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

I'd like to see a similar test for Segment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The existing test harness for Segment stops at mocking the Segment.flush() method and asserting that it's been called. Given that segment is serialized within the flush method, the serialization is never done.

Adding this test would mean rearchitecting the tests and requires knowledge of the codebase that I don't have.

If the maintainers want to add this, I'd suggest them to either: 1/ address this in a future PR, 2/ contribute to this PR and provide the test fixture.

packages/core/lib/segments/segment.js Outdated Show resolved Hide resolved
Copy link

@misterjoshua misterjoshua left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@carolabadeer carolabadeer left a comment

Choose a reason for hiding this comment

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

Thanks for making this change! Left a few small comments, but otherwise looks good

packages/core/lib/segments/attributes/subsegment.d.ts Outdated Show resolved Hide resolved
packages/core/lib/segments/segment.d.ts Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Oct 20, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

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

❗ 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
@@            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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

dreamorosi and others added 2 commits October 20, 2023 22:51
Co-authored-by: Carol Abadeer <60774943+carolabadeer@users.noreply.github.com>
Co-authored-by: Carol Abadeer <60774943+carolabadeer@users.noreply.github.com>
@dreamorosi
Copy link
Contributor Author

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

@carolabadeer carolabadeer merged commit 45a180b into aws:master Oct 21, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segment containing BigInt in metadata throws an error when serialized
4 participants