# aws-xray-sdk-mysql

> AWS X-Ray Patcher for MySQL (Javascript)

Latest version **3.12.0** (published 2025-11-20) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install aws-xray-sdk-mysql
pnpm add aws-xray-sdk-mysql
yarn add aws-xray-sdk-mysql
bun add aws-xray-sdk-mysql
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 3.12.0 |
| Published | 2025-11-20 |
| First published | 2017-03-30 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 14.x |
| Dependencies | 1 |
| Unpacked size | 52.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 280 |
| Author | Amazon Web Services |
| Maintainers | aws-sdk-team, nosovsky, amzn-oss, aws-sdk-bot, awsxray, aws-iot-sdk, aws-amplify-ops, zheallan, mohit0193, rishabh6788, weicongs, sayaligaikawad, peterzhuamazon, forrest-not-gump, cayblood, evertonfraga, osa-publish, amazon-q-cli-bot, yogiraj07, gkwicker.amazon, haotianw465, awssandra, jsq, armiros |
| Keywords | amazon, api, aws, mysql, xray, x-ray, x ray |

## Links

- npm: https://www.npmjs.com/package/aws-xray-sdk-mysql
- Repository: https://github.com/aws/aws-xray-sdk-node.git#master
- Homepage: https://github.com/aws/aws-xray-sdk-node/tree/master#readme
- Issues: https://github.com/aws/aws-xray-sdk-node/issues
- npm.io page: https://npm.io/package/aws-xray-sdk-mysql

## Dependencies (1)

- [@types/mysql](https://npm.io/package/@types/mysql.md) *

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 3.12.0 (latest) — 2025-11-20
- 3.0.0-alpha.2 (alpha) — 2020-03-23
- 2.5.0-experimental.1 (experimental) — 2019-11-13
- 3.11.0 — 2025-10-15
- 3.10.3 — 2025-01-24
- 3.10.2 — 2024-11-12
- 3.10.1 — 2024-09-19
- 3.10.0 — 2024-09-09
- 3.9.0 — 2024-06-10
- 3.8.0 — 2024-06-06
- 3.7.0 — 2024-06-05
- 3.6.0 — 2024-03-25
- 3.5.4 — 2024-02-22
- 3.5.3 — 2023-10-26
- 3.5.2 — 2023-09-25
- … 51 more at https://npm.io/package/aws-xray-sdk-mysql/versions

## README

## Requirements

* AWS X-Ray SDK Core
* MySQL 2.12.0 or greater

## AWS X-Ray and MySQL

The AWS X-Ray MySQL package automatically records query information and request and
response data. Simply patch the MySQL package via `captureMySQL` as shown below.

The AWS X-Ray SDK Core has two modes - `manual` and `automatic`.
Automatic mode uses the `cls-hooked` package and automatically
tracks the current segment and subsegment. This is the default mode.
Manual mode requires that you pass around the segment reference. See the examples below.

### Environment variables

    MYSQL_DATABASE_VERSION           Sets additional data for the sql subsegment.
    MYSQL_DRIVER_VERSION             Sets additional data for the sql subsegment.

### Lambda Example

```js
var AWSXRay = require('aws-xray-sdk');
var pg = AWSXRay.captureMySQL(require('mysql'));

...

exports.handler = function (event, context, callback) {
  // Make MySQL queries normally
}
```

## Automatic mode example

```js
var AWSXRay = require('aws-xray-sdk-core');
var captureMySQL = require('aws-xray-sdk-mysql');

var mysql = captureMySQL(require('mysql'));

var config = { ... };

...

var connection = mysql.createConnection(config);

connection.query('SELECT * FROM cats', function(err, rows) {
  //Automatically captures query information and errors (if any)
});

...

var pool = mysql.createPool(config);

pool.query('SELECT * FROM cats', function(err, rows, fields) {
  //Automatically captures query information and errors (if any)
}
```

## Manual mode example

```js
var AWSXRay = require('aws-xray-sdk-core');
var captureMySQL = require('aws-xray-sdk-mysql');

var mysql = captureMySQL(require('mysql'));

var config = { ... };

...

var connection = mysql.createConnection(config);

connection.query('SELECT * FROM cats', function(err, rows) {
  //Automatically captures query information and errors (if any)
}, segment);

...

var pool = mysql.createPool(config);

pool.query('SELECT * FROM cats', function(err, rows, fields) {
  //Automatically captures query information and errors (if any)
}, segment);
```

---
_Source: https://npm.io/package/aws-xray-sdk-mysql · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
