opentelemetry-js-contrib icon indicating copy to clipboard operation
opentelemetry-js-contrib copied to clipboard

`@opentelemetry/instrumentation-mongoose` does not instrument `insertMany` method

Open Vovcharaa opened this issue 1 year ago • 3 comments

What version of OpenTelemetry are you using?

"@opentelemetry/api": "^1.9.0", "@opentelemetry/context-async-hooks": "^1.26.0", "@opentelemetry/exporter-metrics-otlp-grpc": "^0.53.0", "@opentelemetry/exporter-trace-otlp-grpc": "^0.53.0", "@opentelemetry/instrumentation-mongodb": "^0.47.0", "@opentelemetry/instrumentation-mongoose": "^0.42.0", "@opentelemetry/sdk-metrics": "^1.26.0", "@opentelemetry/sdk-node": "^0.53.0", "@opentelemetry/sdk-trace-node": "^1.26.0",

What version of Node are you using?

Node 20.18.0

What did you do?

SDK configuration

const sdk = new opentelemetry.NodeSDK({
  autoDetectResources: false,
  serviceName: process.env.SERVICE_NAME,
  traceExporter: new OTLPTraceExporter(),
  metricReader: new PeriodicExportingMetricReader({
    exporter: new OTLPMetricExporter(),
  }),
  contextManager: new AsyncLocalStorageContextManager(),
  instrumentations: [
    new MongooseInstrumentation({
      suppressInternalInstrumentation: true,
    }),
    new MongoDBInstrumentation({
      dbStatementSerializer: () => 'omitted',
    }),
  ],
  resource: new Resource({
    [ATTR_DEPLOYMENT_ENVIRONMENT]: process.env.ENVIRONMENT,
  }),
  resourceDetectors: [envDetector, hostDetector],
});

sdk.start();

Mongoose code

Model.insertMany(data);

What did you expect to see?

insertMany is instrumented by @opentelemetry/instrumentation-mongoose.

What did you see instead?

@opentelemetry/instrumentation-mongoose ignores insertMany and instead span is created by @opentelemetry/instrumentation-mongodb.
If @opentelemetry/instrumentation-mongodb is not used I don't see any traces from insertMany operation.

Additional context

I believe some other methods are also not instrumented but I have not encountered them yet.

Vovcharaa avatar Oct 16 '24 15:10 Vovcharaa

cc @blumamir (component owner)

pichlermarc avatar Oct 16 '24 16:10 pichlermarc

@blumamir Any updates on this?

Vovcharaa avatar Oct 29 '24 17:10 Vovcharaa

@blumamir It looks like only static methods are not instrumented. I found these to be missing from spans.

Model.insertMany()
Model.bulkWrite()
Model.bulkSave()

Can you look at them?

Vovcharaa avatar Nov 28 '24 23:11 Vovcharaa