Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@opentelemetry/instrumentation-mysql
Advanced tools
OpenTelemetry mysql automatic instrumentation package.
@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.
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 });
}
},
});
@opentelemetry/instrumentation-pg provides similar functionality for PostgreSQL databases. It allows for automatic instrumentation of PostgreSQL operations, enabling the collection of telemetry data for monitoring and performance analysis. The main difference is that it is specifically designed for PostgreSQL rather than MySQL.
mysql2 is a MySQL client for Node.js that supports Promises and async/await. While it does not provide automatic instrumentation, it can be used in conjunction with OpenTelemetry to manually instrument MySQL operations. This package is more focused on providing a robust and performant MySQL client rather than telemetry.
sequelize is a promise-based Node.js ORM for various SQL databases, including MySQL. It does not provide automatic instrumentation out of the box, but it can be integrated with OpenTelemetry for manual instrumentation. Sequelize is more focused on providing an ORM layer for database operations rather than telemetry.
This module provides automatic instrumentation for the mysql
module, which may be loaded using the @opentelemetry/sdk-trace-node
package and is included in the @opentelemetry/auto-instrumentations-node
bundle.
If total installation size is not constrained, it is recommended to use the @opentelemetry/auto-instrumentations-node
bundle with @opentelemetry/sdk-node for the most seamless instrumentation experience.
Compatible with OpenTelemetry JS API and SDK 1.0+
.
npm install --save @opentelemetry/instrumentation-mysql
2.x
OpenTelemetry MySQL Instrumentation allows the user to automatically collect trace data and export them to the backend of choice, to give observability to distributed systems when working with mysql.
To load a specific plugin (MySQL in this case), specify it in the registerInstrumentations's configuration
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { MySQLInstrumentation } = require('@opentelemetry/instrumentation-mysql');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const provider = new NodeTracerProvider();
provider.register();
registerInstrumentations({
instrumentations: [
new MySQLInstrumentation(),
],
})
See examples for a short example.
Apache 2.0 - See LICENSE for more information.
FAQs
OpenTelemetry instrumentation for `mysql` database client for MySQL
The npm package @opentelemetry/instrumentation-mysql receives a total of 1,901,705 weekly downloads. As such, @opentelemetry/instrumentation-mysql popularity was classified as popular.
We found that @opentelemetry/instrumentation-mysql demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
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.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.