Skip to content

[Bug] mongoose run error in skywalking-nodejs #10253

@KkZsc

Description

@KkZsc

Search before asking

  • I had searched in the issues and found no similar issues.

Apache SkyWalking Component

NodeJS Server Side Agent (apache/skywalking-nodejs)

What happened

When skywalking-nodejs is used in the project, mongoose will have errors like this:
dict_info_1.default.findOne(...).lean is not a function.
and the source code is like this:
const result = await DictInfoModel.findOne({ dict_key: 'xxx' }).lean().exec();

I tried to browse through the skywalking-nodejs code and found that there is a piece of code like this in the MongoosePlugin.ts file:

if (!hasCB) {
  if (ret && typeof ret.then === 'function') {
    // generic Promise check
    ret = wrapPromise(span, ret);
  } else {
    // no callback passed in and no Promise or Cursor returned, play it safe
    span.stop();

    return ret;
  }
}

ret is changed to Promise at ret = wrapPromise(span, ret);, no longer has mongoose methods.

And this is the version information I use:
mongoose: ^4.7.3
skywalking-nodejs: 0.6.0

What you expected to happen

mongoose can run correctly

How to reproduce

  1. Create a project using mongoose
  2. Install skywalking-nodejs
  3. Write mongoose query code: tableName.findOne().lean().exec()
  4. Run app and will see an error in the console

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

Labels

bugSomething isn't working and you are sure it's a bug!no updateThe owner doesn't provide further feedback.nodejsNodeJS backend agent related

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions