Skip to content
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

Add a SQL span naming suggestion: <db.operation> <db.name>.<db.sql.table> #1219

Merged
merged 10 commits into from
Nov 24, 2020
13 changes: 10 additions & 3 deletions specification/trace/semantic_conventions/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
**Span kind:** MUST always be `CLIENT`.

The **span name** SHOULD be set to a low cardinality value representing the statement executed on the database.
It may be a stored procedure name (without arguments), SQL statement without variable arguments, operation name, etc.
It MAY be a stored procedure name (without arguments), DB statement without variable arguments, operation name, etc.
Since SQL statements may have very high cardinality even without arguments, SQL spans SHOULD be named the
following way, unless the statement is known to be of low cardinality:
`<db.operation> <db.name>.<db.sql.table>`, provided that `db.operation` and `db.sql.table` are available.
arminru marked this conversation as resolved.
Show resolved Hide resolved
If `db.sql.table` is not available due to its semantics, the span SHOULD be named `<db.operation> <db.name>`.
It is not recommended to attempt any client-side parsing of `db.statement` just to get these properties,
they should be used if the library being instrumented provides them.
mateuszrzeszutek marked this conversation as resolved.
Show resolved Hide resolved
When it's otherwise impossible to get any meaningful span name, `db.name` or the tech-specific database name MAY be used.

## Connection-level attributes
Expand Down Expand Up @@ -178,7 +184,7 @@ For example, when retrieving a document, `db.operation` would be set to (literal

| Key | Value |
| :---------------------- | :----------------------------------------------------------- |
| Span name | `"SELECT * FROM orders WHERE order_id = ?"` |
| Span name | `"SELECT ShopDb.orders"` |
| `db.system` | `"mysql"` |
| `db.connection_string` | `"Server=shopdb.example.com;Database=ShopDb;Uid=billing_user;TableCache=true;UseCompression=True;MinimumPoolSize=10;MaximumPoolSize=50;"` |
| `db.user` | `"billing_user"` |
Expand All @@ -188,7 +194,8 @@ For example, when retrieving a document, `db.operation` would be set to (literal
| `net.transport` | `"IP.TCP"` |
| `db.name` | `"ShopDb"` |
| `db.statement` | `"SELECT * FROM orders WHERE order_id = 'o4711'"` |
| `db.operation` | not set |
| `db.operation` | `"SELECT"` |
| `db.sql.table` | `"orders"` |

### Redis

Expand Down