-
Notifications
You must be signed in to change notification settings - Fork 234
fix: set outcome for mongodb spans #3695
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
Conversation
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.
/test tav mongodb
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.
/test tav mongodb
TAV tests failing for
I think it was not considered an error before so:
|
If we could find a reliable way to have a mongo client failure for testing, that would be great. I would try for a little bit to find one, but if you cannot after 5-10 minutes, then it is fine to reduce the error test to just the versions on which we know how to trigger one. |
I've tried both promise and callback ways // with Promises
try {
await collection.deleteOne({ item: 'eggs' }, { hint: 'foo' });
console.info('success in .deleteOne() with bogus "hint"'); // <- it call this log
} catch (err) {
console.info('error in .deleteOne() with bogus "hint"');
}
// with callback
collection.deleteOne({ item: 'eggs' }, { hint: 'foo' }, function (err, res) {
if (err) {
console.log('error on callback', err);
} else {
console.log('no error on callback', res); // <- it call this log
}
}); And inspecting the // both Promises & callbacks return the same shape
{
"connectionId": "localhost:27017",
"requestId": 1,
"commandName": "delete",
"duration": 1,
"reply": {
"n": 0,
"ok": 1
}
} This is consistent through ALL tested versions, the difference is that |
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.
/test tav mongodb
|
||
// From mongodb@3.6.0 and up some commands like `deleteOne` may contain | ||
// error data inside the `reply` property. It makes sense to capture it. | ||
const writeErrors = event && event.reply && event.reply.writeErrors; |
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.
FWIW, I think we could use optional chaining with our new min-node version now: https://node.green/#ES2020-features-optional-chaining-operator-----
No need to. Just saying it is an option for our new code now.
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.
IMO this a proper use case for optional chaining. I'll add it in the next commit. Thanks for pointing that out :)
const writeErrors = event && event.reply && event.reply.writeErrors; | ||
|
||
if (writeErrors && writeErrors.length) { | ||
// TODO: this gets linked to the parent transaction. How to link it to the span? |
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.
captureError
has a parent
option for just this case:
// - `opts.parent` - A Transaction or Span instance to make the parent of
// this error. If not given (undefined), then the current span or
// transaction will be used. If `null` is given, then no span or transaction
// will be used.
I guess the emitted CommandSucceededEvent
s (and the other events) are not in the context of the created span, which is fine.
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.
You're right, events fired run in a different context so the parent
option comes in handy
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.
done!
const TEST_USE_CALLBACKS = semver.satisfies(MONGODB_VERSION, '<5'); | ||
|
||
// From mongodb@3.6.0 and up CommandSuccessEvents may contain errors | ||
const MONGODB_SUCESS_WITH_ERRORS = semver.satisfies(MONGODB_VERSION, '>=3.6.0'); |
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.
nit: typo
const MONGODB_SUCESS_WITH_ERRORS = semver.satisfies(MONGODB_VERSION, '>=3.6.0'); | |
const MONGODB_SUCCESS_WITH_ERRORS = semver.satisfies(MONGODB_VERSION, '>=3.6.0'); |
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.
At this pace I'll earn a typo master
badge from github 😅
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.
/test tav mongodb
This PR sets span outcome for
mongodb
commands. The tests realised (see related issue) reveals that a failed command triggers:failure
reply
. The presence of a sub-property namedwriteErrors
indicates the command failed.Closes: #3182
Checklist