0.34.0 • Published 1 year ago

opentelemetry-instrumentation-mongoose v0.34.0

Weekly downloads
194
License
Apache-2.0
Repository
github
Last release
1 year ago

OpenTelemetry Mongoose Instrumentation for Node.js

NPM version

This package is heavily based on @wdalmut/opentelemetry-plugin-mongoose.
This module provides automatic instrumentation for mongoose and follows otel DB Semantic Conventions.

Installation

npm install --save opentelemetry-instrumentation-mongoose

Usage

For further automatic instrumentation instruction see the @opentelemetry/instrumentation package.

const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { MongooseInstrumentation } = require('opentelemetry-instrumentation-mongoose');

registerInstrumentations({
  tracerProvider,
  instrumentations: [
    new MongooseInstrumentation({
      // see under for available configuration
    })
  ]
});

Mongoose Instrumentation Options

Mongoose instrumentation has few options available to choose from. You can set the following (all optional):

OptionsTypeDescription
suppressInternalInstrumentationbooleanMongoose operation use mongodb under the hood. Setting this to true will hide the underlying mongodb spans (if instrumented).
responseHookMongooseResponseCustomAttributesFunctionHook called before response is returned, which allows to add custom attributes to span.
dbStatementSerializerDbStatementSerializerMongoose instrumentation will serialize db.statement using the specified function.
moduleVersionAttributeNamestringIf passed, a span attribute will be added to all spans with key of the provided moduleVersionAttributeName and value of the patched module version
requireParentSpanbooleanSet to true if you do not want to collect traces that start with mongoose

Custom db.statement Serializer

By default, this instrumentation does not populate the db.statement attribute.
If you pass dbStatementSerializer while using this plugin, the return value of the serializer will be placed in the db.statement.

Serializer meets the following interfaces:

interface SerializerPayload {
    condition?: any;
    options?: any;
    updates?: any;
    document?: any;
    aggregatePipeline?: any;
}

type DbStatementSerializer = (operation: string, payload: SerializerPayload) => string;

Please make sure dbStatementSerializer is error proof, as errors are not handled while executing this function.

Difference from opentelemetry-plugin-mongoose

  • This lib is using the opentelemetry instrumentation api, as opposed to the old plugin api.
  • This lib is using the latest opentelemetry version, as opposed to 0.6.0.
  • Strictly follows opentelemetry database client semantic conventions.
  • Has the ability to suppress internal instrumentation.
  • Provides statement serializer and a response hook.
  • Contains several bug fixes.

This extension (and many others) was developed by Aspecto with ❤️

0.34.0

1 year ago

0.32.0

2 years ago

0.29.0

2 years ago

0.28.0

2 years ago

0.27.1

2 years ago

0.27.0

2 years ago

0.26.1

2 years ago

0.26.0

3 years ago

0.25.0

3 years ago

0.24.1

3 years ago

0.24.0

3 years ago

0.23.0

3 years ago

0.22.1

3 years ago

0.22.0

3 years ago

0.21.0

3 years ago

0.5.1

3 years ago

0.4.5

3 years ago

0.4.4

3 years ago

0.5.0

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.3.0

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.1.0

3 years ago

0.2.0

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago