Skip to content

Commit 18a5a49

Browse files
mjqgggritso
andauthored
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]>
1 parent 121342d commit 18a5a49

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

develop-docs/sdk/telemetry/traces/modules/queries.mdx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Queries Module
33
---
44

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 Neo4j or ClickHouse. Regardless of that, the SDK should instrument database queries as fully and correctly as possible to ensure correct behavior and future compatibility.
66

77
## Span Attributes
88

@@ -29,11 +29,21 @@ SELECT * FROM users WHERE id = ?;
2929

3030
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`).
3131

32+
For MongoDB, the description should contain valid JSON. If replacing values with a placeholder, the string `"?"` should be used.
33+
34+
```json
35+
{ "find": "documents", "filter": { "wordCount": { "$gte": "?" } } }
36+
```
37+
3238
### Span Data
3339

3440
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.
3541

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.
45+
46+
## SQL Instrumentation Example
3747

3848
Consider a hypothetical Python ORM:
3949

develop-docs/sdk/telemetry/traces/span-data-conventions.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Below describes the conventions for the Span interface for the `data` field on t
6868
| ----------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
6969
| `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` |
7070
| `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` |
7172
| `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` |
7273
| `server.address` | string | Name of the database host. | `example.com` |
7374
| `server.port` | int | Logical server port number host. | `8080` |

docs/product/insights/queries.mdx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ Query monitoring works best with up-to-date SDK versions. The following minimum
3838

3939
### Span Eligibility
4040

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>
4244

4345
If you are using <PlatformLink to="/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:
4446

4547
- 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"`).
4850

4951
## Queries Page
5052

@@ -58,19 +60,24 @@ The query description table below shows a list of queries, along with their volu
5860

5961
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.
6062

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.
6264

6365
To view more details, click on a query from the table to open its **Query Summary** page.
6466

6567
### Query Parameterization
6668

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:
6870

6971
- 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`)
7072
- Long lists of `SELECT` arguments are collapsed (e.g., `SELECT id, name, age, city, country, phone FROM users` becomes `SELECT .. FROM users`)
7173
- 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)`)
7274
- `CASE / WHEN` statements are collapsed
7375

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+
7481
You can see the full query by hovering on a truncated description, or clicking it to see its **Query Summary** page.
7582

7683
## Query Summary Page

0 commit comments

Comments
 (0)