Socket
Socket
Sign inDemoInstall

opentelemetry-instrumentation-mongoose

Package Overview
Dependencies
22
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    opentelemetry-instrumentation-mongoose

open telemetry instrumentation for the `mongoose` module


Version published
Weekly downloads
3K
decreased by-9.82%
Maintainers
1
Install size
3.30 MB
Created
Weekly downloads
 

Readme

Source

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 ❤️

Keywords

FAQs

Last updated on 21 Nov 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc