You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(insights): detail MongoDB support for Queries module (#11234)
Documents the upcoming MongoDB support in the Queries insights module. Adds docs for both users and SDK developers.
---------
Co-authored-by: George Gritsouk <[email protected]>
Copy file name to clipboardExpand all lines: develop-docs/sdk/telemetry/traces/modules/queries.mdx
+12-2Lines changed: 12 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: Queries Module
3
3
---
4
4
5
-
The SDK should auto-instrument all database queries, and each query to the database should result in a span. This includes queries made manually, or via ORM. The Queries module supports SQL databases like PostgreSQL and MySQL. It does not support databases like Neo4j, ClickHouse, or MongoDB. Regardless of that, the SDK should instrument database queries as fully and correctly as possible to ensure correct behavior and future compatibility.
5
+
The SDK should auto-instrument all database queries, and each query to the database should result in a span. This includes queries made manually, or via ORM. The Queries module supports SQL databases like PostgreSQL and MySQL, as well as MongoDB. It does not support other databases like Neo4jor ClickHouse. Regardless of that, the SDK should instrument database queries as fully and correctly as possible to ensure correct behavior and future compatibility.
6
6
7
7
## Span Attributes
8
8
@@ -29,11 +29,21 @@ SELECT * FROM users WHERE id = ?;
29
29
30
30
The `?` parameter is a placeholder in the query. The SDK must scrub out all values and replace them with a placeholder. Supported placeholder values are `%s`, `?`, `:c0` (e.g., `:c0`, `:c1`) and `$1` (e.g., `$1`, `$2`).
31
31
32
+
For MongoDB, the description should contain valid JSON. If replacing values with a placeholder, the string `"?"` should be used.
For full support, each database span should have a `data` attribute. `data` is itself a key-value lookup of attributes. Refer to [Database Span Data Conventions](/sdk/performance/span-data-conventions/#database) for a full list of attributes that database spans should have. We recommend that the SDK provide _all_ of those attributes for every span. However, the _minimal_ requirement is that the SDK provides the `db.system` attribute.
35
41
36
-
## Instrumentation Example
42
+
#### MongoDB Data
43
+
44
+
MongoDB support requires a few extra data attributes. In addition to a `db.system` value of `"mongodb"`, the `db.operation` and `db.collection.name` attributes are also required to contain the command and collection name respectively.
|`db.system`| string | An identifier for the database management system (DBMS) product being used. See [OpenTelemetry docs for a list of well-known identifiers](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-spans.md#notes-and-well-known-identifiers-for-dbsystem). |`postgresql`|
70
70
|`db.operation`| string | The name of the operation being executed, e.g. the MongoDB command name such as findAndModify, or the SQL keyword. Based on [OpenTelemetry's common db attributes](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-spans.md#common-attributes)|`SELECT`|
71
+
|`db.collection.name`| string | The name of the collection (or table, etc) being queried. |`users`|
71
72
|`db.name`| string | This attribute is used to report the name of the database being accessed. For commands that switch the database, this should be set to the target database (even if the command fails). |`customers`|
72
73
|`server.address`| string | Name of the database host. |`example.com`|
73
74
|`server.port`| int | Logical server port number host. |`8080`|
Copy file name to clipboardExpand all lines: docs/product/insights/queries.mdx
+12-5Lines changed: 12 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,13 +38,15 @@ Query monitoring works best with up-to-date SDK versions. The following minimum
38
38
39
39
### Span Eligibility
40
40
41
-
Sentry tries to extract metrics for all SQL-like dialects. NoSQL databases like MongoDB, graph databases like Neo4j, and other non-SQL database systems are not currently eligible for this feature.
41
+
Sentry tries to extract metrics for all SQL-like dialects, as well as MongoDB. Other NoSQL databases like Elasticsearch, graph databases like Neo4j, and other non-SQL database systems are not currently eligible for this feature.
42
+
43
+
<Note>MongoDB support is currently available to [Early Adopters](/organization/early-adopter-features/). Early Adopter features are still in-progress and may have bugs. We recognize the irony.</Note>
42
44
43
45
If you are using <PlatformLinkto="/tracing/instrumentation/automatic-instrumentation">automatic instrumentation</PlatformLink>, query monitoring should work without any configuration. If you've manually instrumented Sentry, you'll need to make sure that your spans conform to our standards for the best experience:
44
46
45
47
- The span `op` field is set to an [eligible value](https://develop.sentry.dev/sdk/performance/span-operations/#database).
46
-
- The span's description contains the full, parameterized SQL query (e.g. `"SELECT * FROM users WHERE id = ?"`). Supported placeholder values are `%s`, `?`, `:c0` (e.g. `:c0`, `:c1`) and `$1` (e.g. `$1`, `$2`).
47
-
- The `db.system` span data value is set to the [correct identifier](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/attributes-registry/db.md#generic-database-attributes) (e.g., `"postgresql"` or `"mysql"`).
48
+
- The span's description contains the full, parameterized query (e.g. `"SELECT * FROM users WHERE id = ?"`). Supported placeholder values for SQL are `%s`, `?`, `:c0` (e.g. `:c0`, `:c1`) and `$1` (e.g. `$1`, `$2`). MongoDB span descriptions should contain valid JSON, and placeholders should be the string `"?"`.
49
+
- The `db.system` span data value is set to the [correct identifier](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/attributes-registry/db.md#generic-database-attributes) (e.g., `"postgresql"` or `"mongodb"`).
48
50
49
51
## Queries Page
50
52
@@ -58,19 +60,24 @@ The query description table below shows a list of queries, along with their volu
58
60
59
61
By default, this table is sorted by most [time spent](#what-is-time-spent). This means that queries at the top are usually really slow, very frequent, or both. You can change this to sort by queries per minute to see the most frequently run queries, or by average duration to see the slowest queries.
60
62
61
-
You can also use the dropdowns above to filter the table for specific SQL commands (such as `SELECT` and `UPDATE`) and tables queried.
63
+
You can also use the dropdowns above to filter all data for specific commands (such as `SELECT` and `UPDATE`) and tables/collections queried.
62
64
63
65
To view more details, click on a query from the table to open its **Query Summary** page.
64
66
65
67
### Query Parameterization
66
68
67
-
In some cases, Sentry processes queries and simplifies them to improve readability. For example:
69
+
In some cases, Sentry processes queries and simplifies them to improve readability. For example, for SQL queries:
68
70
69
71
- Table names are removed from column selections if possible (e.g., `SELECT "users"."name", "users"."id", "users.age" FROM users` becomes `SELECT name, id, age FROM users`)
70
72
- Long lists of `SELECT` arguments are collapsed (e.g., `SELECT id, name, age, city, country, phone FROM users` becomes `SELECT .. FROM users`)
71
73
- Long lists of `VALUES` arguments are collapsed (e.g., `INSERT INTO users (id, email, name, age) VALUES (%s %s %s %s)` becomes `INSERT INTO users (..) VALUES (%s)`)
72
74
-`CASE / WHEN` statements are collapsed
73
75
76
+
For MongoDB queries:
77
+
78
+
- Leaf values are replaced with the placeholder `"?"`
79
+
- A maximum depth is applied to deeply nested query objects
80
+
74
81
You can see the full query by hovering on a truncated description, or clicking it to see its **Query Summary** page.
0 commit comments