From 2cd9fbb85970ea8cec5b3c84965bb2bf62e695c1 Mon Sep 17 00:00:00 2001 From: Justin Foote Date: Mon, 9 Nov 2020 10:47:40 -0800 Subject: [PATCH] Database semantic conventions: Add db.table, allow SQL keyword as db.operation (#1141) * Add db.table to database semantic conventions * Fix spacing in db semantic conventions * Move db.table to SQL-specific call level attributes * Clarify instructions for setting db.operation to a SQL keyword * Specify that db.sql.table MUST NOT be set when not applicable Co-authored-by: Armin Ruech * Add db.table and db.operation to CHANGELOG Co-authored-by: Armin Ruech --- semantic_conventions/trace/database.yaml | 35 ++++++++++++++++--- .../trace/semantic_conventions/database.md | 7 ++-- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/semantic_conventions/trace/database.yaml b/semantic_conventions/trace/database.yaml index faf7284ec..8106d8857 100644 --- a/semantic_conventions/trace/database.yaml +++ b/semantic_conventions/trace/database.yaml @@ -191,12 +191,15 @@ groups: conditional: Required, if `db.statement` is not applicable. brief: > The name of the operation being executed, e.g. the [MongoDB command name](https://docs.mongodb.com/manual/reference/command/#database-operations) - such as `findAndModify`. + such as `findAndModify`, or the SQL keyword. note: > - While it would semantically make sense to set this, e.g., to a SQL keyword like `SELECT` or `INSERT`, - it is not recommended to attempt any client-side parsing of `db.statement` just to get this property - (the back end can do that if required). - examples: ['findAndModify', 'HMSET'] + When setting this to an SQL keyword, it is not recommended to + attempt any client-side parsing of `db.statement` just to get this + property, but it should be set if the operation name is provided by + the library being instrumented. + If the SQL statement has an ambiguous operation, or performs more + than one operation, this value may be omitted. + examples: ['findAndModify', 'HMSET', 'SELECT'] - ref: net.peer.name tag: connection-level required: @@ -294,6 +297,27 @@ groups: The collection being accessed within the database stated in `db.name`. examples: [ 'customers', 'products' ] + - id: db.sql + prefix: 'db.sql' + extends: 'db' + brief: > + Call-level attrbiutes for SQL databases + attributes: + - id: table + tag: call-level-tech-specific + type: string + required: + conditional: Recommended if available. + brief: The name of the primary table that the operation is acting upon, including the schema name (if applicable). + note: > + It is not recommended to attempt any client-side parsing of + `db.statement` just to get this property, but it should be set if + it is provided by the library being instrumented. + If the operation is acting upon an anonymous table, or more than one table, this + value MUST NOT be set. + examples: ['public.users', 'customers'] + + - id: db.tech brief: "Semantic convention group for specific technologies" constraints: @@ -301,3 +325,4 @@ groups: - include: 'db.hbase' - include: 'db.redis' - include: 'db.mongodb' + - include: 'db.sql' diff --git a/specification/trace/semantic_conventions/database.md b/specification/trace/semantic_conventions/database.md index 37c7f6d45..f2b1500e5 100644 --- a/specification/trace/semantic_conventions/database.md +++ b/specification/trace/semantic_conventions/database.md @@ -135,7 +135,7 @@ Usually only one `db.name` will be used per connection though. |---|---|---|---|---| | `db.name` | string | If no [tech-specific attribute](#call-level-attributes-for-specific-technologies) is defined, 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). [1] | `customers`
`main` | Conditional [2] | | `db.statement` | string | The database statement being executed. [3] | `SELECT * FROM wuser_table`
`SET mykey "WuValue"` | Conditional
Required if applicable. | -| `db.operation` | string | The name of the operation being executed, e.g. the [MongoDB command name](https://docs.mongodb.com/manual/reference/command/#database-operations) such as `findAndModify`. [4] | `findAndModify`
`HMSET` | Conditional
Required, if `db.statement` is not applicable. | +| `db.operation` | string | The name of the operation being executed, e.g. the [MongoDB command name](https://docs.mongodb.com/manual/reference/command/#database-operations) such as `findAndModify`, or the SQL keyword. [4] | `findAndModify`
`HMSET`
`SELECT` | Conditional
Required, if `db.statement` is not applicable. | **[1]:** In some SQL databases, the database name to be used is called "schema name". @@ -143,7 +143,7 @@ Usually only one `db.name` will be used per connection though. **[3]:** The value may be sanitized to exclude sensitive information. -**[4]:** While it would semantically make sense to set this, e.g., to a SQL keyword like `SELECT` or `INSERT`, it is not recommended to attempt any client-side parsing of `db.statement` just to get this property (the back end can do that if required). +**[4]:** When setting this to an SQL keyword, it is not recommended to attempt any client-side parsing of `db.statement` just to get this property, but it should be set if the operation name is provided by the library being instrumented. If the SQL statement has an ambiguous operation, or performs more than one operation, this value may be omitted. For **Redis**, the value provided for `db.statement` SHOULD correspond to the syntax of the Redis CLI. @@ -165,8 +165,11 @@ For example, when retrieving a document, `db.operation` would be set to (literal | `db.hbase.namespace` | string | The [HBase namespace](https://hbase.apache.org/book.html#_namespace) being accessed. To be used instead of the generic `db.name` attribute. | `default` | Yes | | `db.redis.database_index` | number | The index of the database being accessed as used in the [`SELECT` command](https://redis.io/commands/select), provided as an integer. To be used instead of the generic `db.name` attribute. | `0`
`1`
`15` | Conditional [1] | | `db.mongodb.collection` | string | The collection being accessed within the database stated in `db.name`. | `customers`
`products` | Yes | +| `db.sql.table` | string | The name of the primary table that the operation is acting upon, including the schema name (if applicable). [2] | `public.users`
`customers` | Conditional
Recommended if available. | **[1]:** Required, if other than the default database (`0`). + +**[2]:** It is not recommended to attempt any client-side parsing of `db.statement` just to get this property, but it should be set if it is provided by the library being instrumented. If the operation is acting upon an anonymous table, or more than one table, this value MUST NOT be set. ## Examples