Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@opentelemetry/instrumentation-mongodb

Package Overview
Dependencies
Maintainers
3
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/instrumentation-mongodb

OpenTelemetry instrumentation for `mongodb` database client for MongoDB

  • 0.50.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created

What is @opentelemetry/instrumentation-mongodb?

@opentelemetry/instrumentation-mongodb is an npm package that provides automatic tracing for MongoDB operations using the OpenTelemetry framework. It helps in monitoring and collecting performance metrics and distributed traces for MongoDB operations, which can be useful for debugging and optimizing database interactions.

What are @opentelemetry/instrumentation-mongodb's main functionalities?

Automatic Tracing

This feature allows you to automatically trace MongoDB operations. The code sample shows how to set up the NodeTracerProvider and register the MongoDB instrumentation to start collecting traces.

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

const provider = new NodeTracerProvider();
provider.register();

registerInstrumentations({
  instrumentations: [
    new MongoDBInstrumentation(),
  ],
});

Custom Span Attributes

This feature allows you to add custom attributes to the spans created for MongoDB operations. The code sample demonstrates how to use the `responseHook` to add the MongoDB operation result as a span attribute.

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

const mongoInstrumentation = new MongoDBInstrumentation({
  responseHook: (span, result) => {
    span.setAttribute('mongodb.result', JSON.stringify(result));
  },
});

Error Handling

This feature allows you to handle errors in MongoDB operations and set the span status accordingly. The code sample shows how to use the `responseHook` to check if the result is an error and set the span status.

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

const mongoInstrumentation = new MongoDBInstrumentation({
  responseHook: (span, result) => {
    if (result instanceof Error) {
      span.setStatus({ code: 2, message: result.message });
    }
  },
});

Other packages similar to @opentelemetry/instrumentation-mongodb

Keywords

FAQs

Package last updated on 05 Dec 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc