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

@opentelemetry/instrumentation-mysql2

Package Overview
Dependencies
Maintainers
3
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/instrumentation-mysql2

OpenTelemetry instrumentation for `mysql2` database client for MySQL

  • 0.44.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created

What is @opentelemetry/instrumentation-mysql2?

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

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

Automatic Tracing

This feature allows you to automatically trace MySQL2 queries. The code sample demonstrates how to set up the OpenTelemetry NodeTracerProvider and register the MySQL2 instrumentation. Once set up, any MySQL2 queries executed will be automatically traced.

const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { MySQL2Instrumentation } = require('@opentelemetry/instrumentation-mysql2');

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

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

const mysql = require('mysql2');
const connection = mysql.createConnection({
  host: 'localhost',
  user: 'root',
  database: 'test'
});

connection.query('SELECT 1', (err, results) => {
  if (err) throw err;
  console.log(results);
  connection.end();
});

Custom Span Attributes

This feature allows you to add custom attributes to spans. The code sample shows how to use the `responseHook` option to add the number of rows returned by a MySQL2 query as a custom attribute to the span.

const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { MySQL2Instrumentation } = require('@opentelemetry/instrumentation-mysql2');

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

registerInstrumentations({
  instrumentations: [
    new MySQL2Instrumentation({
      responseHook: (span, response) => {
        span.setAttribute('mysql2.rows', response.length);
      }
    }),
  ],
});

const mysql = require('mysql2');
const connection = mysql.createConnection({
  host: 'localhost',
  user: 'root',
  database: 'test'
});

connection.query('SELECT 1', (err, results) => {
  if (err) throw err;
  console.log(results);
  connection.end();
});

Other packages similar to @opentelemetry/instrumentation-mysql2

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