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

@opentelemetry/instrumentation-mysql

Package Overview
Dependencies
Maintainers
3
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/instrumentation-mysql

OpenTelemetry instrumentation for `mysql` database client for MySQL

  • 0.45.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created

What is @opentelemetry/instrumentation-mysql?

@opentelemetry/instrumentation-mysql is an npm package that provides automatic instrumentation for MySQL database operations using the OpenTelemetry framework. This allows developers to collect and export telemetry data such as traces and metrics from MySQL queries, which can be used for monitoring and performance analysis.

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

Automatic Instrumentation

This feature allows you to automatically instrument MySQL operations without modifying your existing codebase. The provided code sample shows how to set up the MySQL instrumentation with OpenTelemetry.

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

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

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

Custom Span Attributes

This feature allows you to add custom attributes to spans generated by MySQL operations. The code sample demonstrates how to add a custom attribute to the span that includes the MySQL response.

const { MySQLInstrumentation } = require('@opentelemetry/instrumentation-mysql');

const mysqlInstrumentation = new MySQLInstrumentation({
  responseHook: (span, response) => {
    span.setAttribute('mysql.response', JSON.stringify(response));
  },
});

Error Handling

This feature allows you to handle errors in MySQL operations and set the span status accordingly. The code sample shows how to set the span status to an error code if the MySQL response contains an error.

const { MySQLInstrumentation } = require('@opentelemetry/instrumentation-mysql');

const mysqlInstrumentation = new MySQLInstrumentation({
  responseHook: (span, response) => {
    if (response.error) {
      span.setStatus({ code: 2, message: response.error.message });
    }
  },
});

Other packages similar to @opentelemetry/instrumentation-mysql

Keywords

FAQs

Package last updated on 18 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