# @metis-data/sequelize-interceptor

> Intercept sequelize queries using OpenTelemetry and enrich spans

Latest version **2.3.1** (published 2023-02-16) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @metis-data/sequelize-interceptor
pnpm add @metis-data/sequelize-interceptor
yarn add @metis-data/sequelize-interceptor
bun add @metis-data/sequelize-interceptor
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.3.1 |
| Published | 2023-02-16 |
| First published | 2022-09-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 15.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Metisdata |
| Maintainers | metisdata.io |

## Links

- npm: https://www.npmjs.com/package/@metis-data/sequelize-interceptor
- Repository: https://github.com/metis-data/metis-js-collectors
- Homepage: https://github.com/metis-data/metis-js-collectors#readme
- Issues: https://github.com/metis-data/metis-js-collectors/issues
- npm.io page: https://npm.io/package/@metis-data/sequelize-interceptor

## Dependencies (2)

- [shimmer](https://npm.io/package/shimmer.md) ^1.2.1
- [@metis-data/base-interceptor](https://npm.io/package/@metis-data/base-interceptor.md) ^2.3.1

## Recent versions

- 2.3.1 (latest) — 2023-02-16
- 2.0.11-alpha.0 — 2023-02-04
- 2.0.10 — 2023-01-31
- 2.0.9 — 2023-01-16
- 2.0.8 — 2023-01-15
- 2.0.7 — 2023-01-10
- 2.0.7-beta.0 — 2023-01-08
- 2.0.6 — 2022-12-22
- 2.0.5 — 2022-12-19
- 2.0.4 — 2022-12-18
- 2.0.3 — 2022-12-15
- 2.0.1 — 2022-12-15
- 0.1.5 — 2022-12-15
- 1.4.1 — 2022-12-12
- 1.4.0 — 2022-12-12
- … 9 more at https://npm.io/package/@metis-data/sequelize-interceptor/versions

## README

# `@metis-data/sequelize-interceptor`

Intercept sequelize queries using OpenTelemetry and enrich spans.

## Usage

Create a `Sequelize` instrumentation object using `getSequelizeInstrumentation` function.

The `Sequelize` instance passed to this function will NOT be instrumented. It is only used for getting the execution plans from the database.

The rest are optional parameters.
You can switch between `Actual` and `Estimated` plans collection using `PlanType`.
Internal errors can be collected using the `errorHandler` function.
Plan collection can be disabled using a flag.

```javascript
import { PlanType } from '@metis-data/base-interceptor';
import { getSequelizeInstrumentation } from '@metis-data/sequelize-interceptor';

// Create the instrumentation object to use with Open Telemetry.
const sequelizeInstrumentation = getSequelizeInstrumentation(
  sequelize, // The sequelize instance, not instrumented.
  PlanType.ESTIMATED, // the type of plan to get, default to Estimated.
  console.error, // error handler, exception are still sent to metis' Sentry account.
  true, // Collect plans and add them to spans. default to true.
);
```

Add the instrumentation to your existing `OpenTelemetry` setup.

```javascript
registerInstrumentations({
  ...
  instrumentations: [..., sequelizeInstrumentation],
});
```

## Known Issues

### CommonJS and ES Modules.

Currently this package can **only** be used in `CommonJS` modules, and it will not work with `ES` modules. The issue stems from the fact that we need to provide a `Sequelize` instance to the instrumentation. That means we need to import `Sequelize`, and that causes issues with the patching of `Sequelize`. To solve this issue we clear the required cache internally when `instrument` is called.

Typescript can be used, but it needs to target `CommonJS`.

---
_Source: https://npm.io/package/@metis-data/sequelize-interceptor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
