|
2 | 2 | title: Database integrations |
3 | 3 | --- |
4 | 4 |
|
5 | | -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`: |
| 5 | +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. |
6 | 6 |
|
7 | | -### MongoDB |
| 7 | +Supported packages and their integration name: |
| 8 | +- `pg` (Postgres) |
| 9 | +- `mongodb` (Mongo) |
| 10 | +- `mongoose` (Mongo) |
| 11 | +- `mysql` (MySQL) |
8 | 12 |
|
9 | | -```javascript |
10 | | -const Sentry = require("@sentry/node"); |
11 | | -const Tracing = require("@sentry/tracing"); |
12 | | -const mongodb = require("mongodb"); |
13 | | - |
14 | | -Sentry.init({ |
15 | | - // .... |
16 | | - integrations: [ |
17 | | - // .... |
18 | | - new Tracing.Integrations.Mongo(), // Add this integration |
19 | | - ], |
20 | | - // .... |
21 | | -}); |
22 | | -``` |
| 13 | +### Disabling Automatic Instrumentation |
23 | 14 |
|
24 | | -### MySQL / MariaDB |
| 15 | +You can also (remove an automatically-enabled integration)[integrations](/platforms/node/configuration/integrations/#removing-an-integration), if needed. |
25 | 16 |
|
26 | | -```javascript |
27 | | -const Sentry = require("@sentry/node"); |
28 | | -const Tracing = require("@sentry/tracing"); |
29 | | -const mysql = require("mysql"); |
30 | | - |
31 | | -Sentry.init({ |
32 | | - // .... |
33 | | - integrations: [ |
34 | | - // .... |
35 | | - new Tracing.Integrations.Mysql(), // Add this integration |
36 | | - ], |
37 | | - // .... |
38 | | -}); |
39 | | -``` |
| 17 | +### Manually Adding Integrations |
40 | 18 |
|
41 | | -### PostgreSQL |
| 19 | +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. |
42 | 20 |
|
| 21 | +For example, to add MongoDB instrumentation to a custom client: |
43 | 22 |
|
44 | 23 | ```javascript |
45 | 24 | const Sentry = require("@sentry/node"); |
46 | 25 | const Tracing = require("@sentry/tracing"); |
47 | | -const pg = require("pg"); |
48 | | - |
49 | | -Sentry.init({ |
50 | | - // .... |
51 | | - integrations: [ |
52 | | - // .... |
53 | | - new Tracing.Integrations.Postgres(), // Add this integration |
54 | | - ], |
55 | | - // .... |
| 26 | +const mongodb = require("mongodb"); |
| 27 | + |
| 28 | +const client = new Sentry.NodeClient({ |
| 29 | + dsn: "___PUBLIC_DSN___", |
| 30 | + integrations: [new Tracing.Integrations.Mongo()], |
56 | 31 | }); |
57 | 32 | ``` |
0 commit comments