# @metis-data/sequelize-express-interceptor

> Intercept sequelize queries and express requests using OpenTelemetry, enrich spans and send them to metis platform

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-express-interceptor
pnpm add @metis-data/sequelize-express-interceptor
yarn add @metis-data/sequelize-express-interceptor
bun add @metis-data/sequelize-express-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 | 10 |
| Unpacked size | 11 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Metisdata |
| Maintainers | metisdata.io |

## Links

- npm: https://www.npmjs.com/package/@metis-data/sequelize-express-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-express-interceptor

## Dependencies (10)

- [@opentelemetry/api](https://npm.io/package/@opentelemetry/api.md) ^1.1.0
- [@opentelemetry/resources](https://npm.io/package/@opentelemetry/resources.md) ^1.4.0
- [@metis-data/base-interceptor](https://npm.io/package/@metis-data/base-interceptor.md) ^2.3.1
- [@opentelemetry/sdk-trace-node](https://npm.io/package/@opentelemetry/sdk-trace-node.md) ^1.4.0
- [@opentelemetry/instrumentation](https://npm.io/package/@opentelemetry/instrumentation.md) ^0.31.0
- [@metis-data/sequelize-interceptor](https://npm.io/package/@metis-data/sequelize-interceptor.md) ^2.3.1
- [@opentelemetry/instrumentation-http](https://npm.io/package/@opentelemetry/instrumentation-http.md) ^0.30.0
- [@opentelemetry/semantic-conventions](https://npm.io/package/@opentelemetry/semantic-conventions.md) ^1.4.0
- [@opentelemetry/instrumentation-express](https://npm.io/package/@opentelemetry/instrumentation-express.md) ^0.30.0
- [opentelemetry-instrumentation-sequelize](https://npm.io/package/opentelemetry-instrumentation-sequelize.md) ^0.29.0

## 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
- 1.4.1 — 2022-12-12
- 1.4.0 — 2022-12-12
- 0.0.9 — 2022-10-02
- 0.0.8 — 2022-09-22
- … 7 more at https://npm.io/package/@metis-data/sequelize-express-interceptor/versions

## README

# `@metis-data/sequelize-express-interceptor`

On this page, we get you up and running with Metis' SDK for Javascript, so that it will automatically send the SQL commands, with their caller REST / GraphQL, from the application. Metis SDK supports Javascript Sequezlie ORM with Express Framework.
If you don't have an API Key yet, sign up to Metis at http://metisdata.io to get one. It can be found under the API Key page.

## Install

Install

### Using NPM:

```bash
npm install --save @metis-data/sequelize-express-interceptor
```

## Setup

The interception of Sequelize queries is done by replacing the query function with a function that opens a span, collects the plan, and then executes the actual query.
To get the plan we must provide the interceptor with a Sequelize instance. That instance would not be instrumented, and should not be used in the application.
You must create a new Sequelize instance after instrumentation started. That should be the instance used in the application.

```javascript
const {
  deafult: SequelizeExpressInterceptor,
} = require('@metis-data/sequelize-express-interceptor');

const interceptor = SequelizeExpressInterceptor.create({
  serviceName: 'your-service-name', // The name of the service
  serviceVersion: '0.0.1', // The version of the service
});

interceptor.instrument(
  sequelize, // The Sequelize instance for getting the plan
  {
    errorHandler: console.error, // Error handler, errors are still reporterd to metis' Sentry account
    shouldCollectPlans: true, // Get the plan for each intercepted query (default to true)
    excludedUrls: [/favicon.ico/], // URLs to exclude from tracing
    printToConsole: true, // Print outgoing spans in console (default to false, passed to exporter)
  },
);
```

## Configure

It is possible to configure the service name and version, and the exporter URL and API key, in code (by passing an object in create) or in environment variables.

When starting the interceptor it will merge the configuration from create and environment. The configuration from create will override values in environment.

| **Environment**    | **Code**       | **Description**                                                                                                                            |
|--------------------|----------------| ------------------------------------------------------------------------------------------------------------------------------------------ |
| METIS_EXPORTER_URL | exporterUrl    | The URL of Metis API Gateway. Default: https://ingest.metisdata.io/                                                                        |
| METIS_API_KEY      | apiKey         | _Required. A valid API key. Use the page API Key in the web app to see existing ones or create a new one_                                  |
| METIS_SERVICE_NAME | serviceName    | _Optional. A short name of the service to easily group the traces belonging to this service_                                               |
| SERVICE_VERSION    | serviceVersion | _Optional. An internal version of the service, to help the developers to distinguish between traces of the latest version and older ones._ |

## 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`.

Configure

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