Skip to content

ref: Node DB auto-instrumentation docs #3563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 16 additions & 41 deletions src/platforms/node/common/performance/database.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,31 @@
title: Database integrations
---

Node.js has a few integrations that support tracking database queries as Spans. For now you only need to use the latest version of our SDK and add the specific integration to `Sentry.init`:
Node.js integrations support tracking database queries as spans. Starting in version `6.4.0`, `@sentry/tracing` will auto-detect supported database drivers or ORMs being used in your project, and automatically enable the relevant integrations with default options - without needing additional code.

### MongoDB
Supported packages and their integration name:
- `pg` (Postgres)
- `mongodb` (Mongo)
- `mongoose` (Mongo)
- `mysql` (MySQL)

```javascript
const Sentry = require("@sentry/node");
const Tracing = require("@sentry/tracing");
const mongodb = require("mongodb");

Sentry.init({
// ....
integrations: [
// ....
new Tracing.Integrations.Mongo(), // Add this integration
],
// ....
});
```
### Disabling Automatic Instrumentation

### MySQL / MariaDB
You can also (remove an automatically-enabled integration)[integrations](/platforms/node/configuration/integrations/#removing-an-integration), if needed.

```javascript
const Sentry = require("@sentry/node");
const Tracing = require("@sentry/tracing");
const mysql = require("mysql");

Sentry.init({
// ....
integrations: [
// ....
new Tracing.Integrations.Mysql(), // Add this integration
],
// ....
});
```
### Manually Adding Integrations

### PostgreSQL
If you need to add a specific database integration manually (for example, when using multiple client instances), you can import them from the `@sentry/tracing` package under the `Integrations` namespace.

For example, to add MongoDB instrumentation to a custom client:

```javascript
const Sentry = require("@sentry/node");
const Tracing = require("@sentry/tracing");
const pg = require("pg");

Sentry.init({
// ....
integrations: [
// ....
new Tracing.Integrations.Postgres(), // Add this integration
],
// ....
const mongodb = require("mongodb");

const client = new Sentry.NodeClient({
dsn: "___PUBLIC_DSN___",
integrations: [new Tracing.Integrations.Mongo()],
});
```