📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP
Socket
Sign inDemoInstall
Socket

@opentelemetry/instrumentation-mysql

Package Overview
Dependencies
Maintainers
3
Versions
42
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.46.0
latest
Source
npm
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

instrumentation

FAQs

Package last updated on 18 Mar 2025

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