@aspecto/opentelemetry-instrumentation-mongodb
v0.2.0
Published
Aspecto fork of OpenTelemetry mongodb automatic instrumentation package.
Downloads
4,507
Readme
OpenTelemetry mongodb Instrumentation for Node.js
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
- For more information on OpenTelemetry, visit: https://opentelemetry.io/
- For more about OpenTelemetry JavaScript: https://github.com/open-telemetry/opentelemetry-js
- For help or feedback on this project, join us on gitter
License
Apache 2.0 - See LICENSE for more information.