@aspecto/opentelemetry-instrumentation-mongodb
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

OpenTelemetry mongodb Instrumentation for Node.js

Gitter chat dependencies devDependencies Apache License

This is a fork of the instrumentation, to add features required by aspecto until they are merged into the main repo and published.

This module provides automatic instrumentation for mongodb.

For automatic instrumentation see the @opentelemetry/sdk-trace-node package.

Installation

npm install --save @opentelemetry/instrumentation-mongodb

Supported Versions

  • '>=3.3 <4

Usage

OpenTelemetry Mongodb Instrumentation allows the user to automatically collect trace data and export them to their backend of choice, to give observability to distributed systems.

To load a specific instrumentation (mongodb in this case), specify it in the Node Tracer's configuration.

const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { MongoDBInstrumentation } = require('@opentelemetry/instrumentation-mongodb');

const provider = new NodeTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.register();

const mongodbInstrumentation = new MongoDBInstrumentation({
  // see under for available configuration
});

Mongo instrumentation Options

Mongodb instrumentation has few options available to choose from. You can set the following:

Options Type Description
dbStatementSerializer DbStatementSerializer Mongodb instrumentation will serialize db.statement using the specified function.
responseHook MongoDbResponseCustomAttributesFunction Hook called before response is returned, which allows to add custom attributes to span.
moduleVersionAttributeName string If passed, a span attribute will be added to all spans with key of the provided moduleVersionAttributeName and value of the patched module version.
requireParentSpan boolean Require parent to create mongodb span, default when unset is true
ignoreIsMasterCommand boolean If true, a span for periodical isMaster command will not be generated, default when unset is false. The mongodb client library periodically re-run the isMaster command to detect the replica set configuration changes.
aggregateGetMoreOperations boolean If true, a span for a getMore command will not be generated, default when unset is false.
aggregateGetMoreResponseHook MongoDbGetMoreResponseAggregateFunction Hook for aggregate a response payload of a GetMore operation, allows to add custom attributes to span.

Useful links

License

Apache 2.0 - See LICENSE for more information.

Package Sidebar

Install

npm i @aspecto/opentelemetry-instrumentation-mongodb

Weekly Downloads

1,692

Version

0.2.0

License

Apache-2.0

Unpacked Size

98.8 kB

Total Files

15

Last publish

Collaborators

  • habmic
  • amir.aspecto
  • aspecto-release-bot
  • andriy-aspecto
  • yanivd