Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
@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/mysql for a short example.
Options | Type | Default | Description |
---|---|---|---|
enhancedDatabaseReporting | boolean | false | If true, an attribute containing the query's parameters will be attached the spans generated to represent the query |
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,654,623 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
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.