-
Notifications
You must be signed in to change notification settings - Fork 469
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(instrumentation-mongoose): Fix instrumentation for Mongoose Model methods, save() and remove(), by passing options argument to original method calls #2009
Conversation
|
JSON.stringify(payload), | ||
dbStatementSerializer: (_operation: string, payload) => { | ||
return JSON.stringify(payload, (key, value) => { | ||
return key === 'session' ? '[Session]' : value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Note this replacer function was only introduced here to avoid an error due to the Session object having cyclical reference
…sion_instrumentation
…sion_instrumentation
…sion_instrumentation
Hi @blumamir, wondering if you could have a look at this PR when you have some time? |
@open-telemetry/javascript-approvers Hi there, wondering if somebody could have a look at this PR? |
Hello, @blumamir and @open-telemetry/javascript-approvers just reaching out to check if anyone could have a look at this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the time it took to review and thank you for creating a fix for this issue 🙏
Not sure I fully understood the logic in this PR regarding adding new callback to the existing array.
@blumamir , I've update the PR to simplify the usage of Please let me know what you think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks again for the fix and sorry it took so long to review 🙏
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2009 +/- ##
==========================================
- Coverage 90.97% 90.01% -0.97%
==========================================
Files 146 140 -6
Lines 7492 6909 -583
Branches 1502 1457 -45
==========================================
- Hits 6816 6219 -597
- Misses 676 690 +14 |
No worries! |
@ferrelucas let me know if you need any help fixing the CI issues. once it is green we can merge and release this fix |
@blumamir thanks, I have fixed the lint issues. I just realized the Unit Test issues are giving the I happen to not have this issue running the tests locally because I was already running a MongDB Replica Set. I can have a better look on how to do it soon - any directions on it would be helpful |
Hi @blumamir I've taken one of the CI unit tests as example It is running:
I think we could add the I believe I don't have permissions to make these changes in the Github Actions |
perhaps we can use another option property instead of I can see you use this code to test passing both options and callback await user.save({ session }, async () => { we can consider using something else instead of |
If I am not mistake, the mongo service is started here which you can edit, but I really think it would be easier to just use some other option for the test instead of |
… of transactions in the instrumentation test
@blumamir thanks! I've updated the PR unit tests to use |
Hey, @blumamir thanks again for the review! 🙌 |
Which problem is this PR solving?
Fixes #1678
This PR fixes the issue where transactions cannot be used for the Model methods
save()
andremove()
(and their aliases eg.create()
) because after instrumentation is applied to these methods, specifically when bothoptions
andcallback
are defined, the final method call loses the first argumentoption
making the final call not take theoption.session
into consideration when making database operations.This could lead to save updates in transactions not being properly rolled back as well as multiple operations that are supposed to share the same session not being able to do so because their calls would eventually be made without the
session
reference.Short description of the changes
args
intohandleCallbackResponse()
handleCallbackResponse()
so that we createnewArgs
including the originaloptions
and the instrumentedcallback
function.options
argument withcallback