Skip to content

Commit f9dfdd5

Browse files
authored
Database: clarify network attributes usage on common semconv (#768)
1 parent cfff890 commit f9dfdd5

File tree

6 files changed

+77
-57
lines changed

6 files changed

+77
-57
lines changed

.chloggen/768.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
change_type: breaking
2+
3+
component: db
4+
5+
note: Remove `network.transport` and `network.type` attributes from database semantic conventions, clarify when `network.peer.address|port` should be populated.
6+
7+
issues: [690, 768]

docs/database/cassandra.md

+4
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ described on this page.
2525
| [`db.cassandra.speculative_execution_count`](../attributes-registry/db.md) | int | The number of times a query was speculatively executed. Not set or `0` if the query was not executed speculatively. | `0`; `2` | Recommended |
2626
| [`db.cassandra.table`](../attributes-registry/db.md) | string | The name of the primary Cassandra table that the operation is acting upon, including the keyspace name (if applicable). [1] | `mytable` | Recommended |
2727
| [`db.name`](../attributes-registry/db.md) | string | The keyspace name in Cassandra. [2] | `mykeyspace` | Conditionally Required: If applicable. |
28+
| [`network.peer.address`](../attributes-registry/network.md) | string | Peer address of the database node where the operation was performed. [3] | `10.1.2.80`; `/tmp/my.sock` | Recommended |
29+
| [`network.peer.port`](../attributes-registry/network.md) | int | Peer port number of the network connection. | `65123` | Recommended: if and only if `network.peer.address` is set. |
2830

2931
**[1]:** This mirrors the db.sql.table attribute but references cassandra rather than sql. 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.
3032

3133
**[2]:** For Cassandra the `db.name` should be set to the Cassandra keyspace name.
3234

35+
**[3]:** If a database operation involved multiple network calls (for example retries), the address of the last contacted node SHOULD be used.
36+
3337
`db.cassandra.consistency_level` MUST be one of the following:
3438

3539
| Value | Description |

docs/database/database-spans.md

+9-32
Original file line numberDiff line numberDiff line change
@@ -79,32 +79,25 @@ Some database systems may allow a connection to switch to a different `db.user`,
7979
| [`db.statement`](../attributes-registry/db.md) | string | The database statement being executed. | `SELECT * FROM wuser_table`; `SET mykey "WuValue"` | Recommended: [3] |
8080
| [`db.system`](../attributes-registry/db.md) | string | An identifier for the database management system (DBMS) product being used. See below for a list of well-known identifiers. | `other_sql` | Required |
8181
| [`db.user`](../attributes-registry/db.md) | string | Username for accessing the database. | `readonly_user`; `reporting_user` | Recommended |
82-
| [`network.peer.address`](../attributes-registry/network.md) | string | Peer address of the network connection - IP address or Unix domain socket name. | `10.1.2.80`; `/tmp/my.sock` | Recommended |
83-
| [`network.peer.port`](../attributes-registry/network.md) | int | Peer port number of the network connection. | `65123` | Recommended: If `network.peer.address` is set. |
84-
| [`network.transport`](../attributes-registry/network.md) | string | [OSI transport layer](https://osi-model.com/transport-layer/) or [inter-process communication method](https://wikipedia.org/wiki/Inter-process_communication). [4] | `tcp`; `udp` | Recommended |
85-
| [`network.type`](../attributes-registry/network.md) | string | [OSI network layer](https://osi-model.com/network-layer/) or non-OSI equivalent. [5] | `ipv4`; `ipv6` | Recommended |
86-
| [`server.address`](../attributes-registry/server.md) | string | Name of the database host. [6] | `example.com`; `10.1.2.80`; `/tmp/my.sock` | Recommended |
87-
| [`server.port`](../attributes-registry/server.md) | int | Server port number. [7] | `80`; `8080`; `443` | Conditionally Required: [8] |
82+
| [`network.peer.address`](../attributes-registry/network.md) | string | Peer address of the database node where the operation was performed. [4] | `10.1.2.80`; `/tmp/my.sock` | Recommended: If applicable for this database system. |
83+
| [`network.peer.port`](../attributes-registry/network.md) | int | Peer port number of the network connection. | `65123` | Recommended: if and only if `network.peer.address` is set. |
84+
| [`server.address`](../attributes-registry/server.md) | string | Name of the database host. [5] | `example.com`; `10.1.2.80`; `/tmp/my.sock` | Recommended |
85+
| [`server.port`](../attributes-registry/server.md) | int | Server port number. [6] | `80`; `8080`; `443` | Conditionally Required: [7] |
8886

8987
**[1]:** In some SQL databases, the database name to be used is called "schema name". In case there are multiple layers that could be considered for database name (e.g. Oracle instance name and schema name), the database name to be used is the more specific layer (e.g. Oracle schema name).
9088

9189
**[2]:** 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.
9290

9391
**[3]:** Should be collected by default only if there is sanitization that excludes sensitive information.
9492

95-
**[4]:** The value SHOULD be normalized to lowercase.
93+
**[4]:** Semantic conventions for individual database systems SHOULD document whether `network.peer.*` attributes are applicable. Network peer address and port are useful when the application interacts with individual database nodes directly.
94+
If a database operation involved multiple network calls (for example retries), the address of the last contacted node SHOULD be used.
9695

97-
Consider always setting the transport when setting a port number, since
98-
a port number is ambiguous without knowing the transport. For example
99-
different processes could be listening on TCP port 12345 and UDP port 12345.
96+
**[5]:** When observed from the client side, and when communicating through an intermediary, `server.address` SHOULD represent the server address behind any intermediaries, for example proxies, if it's available.
10097

101-
**[5]:** The value SHOULD be normalized to lowercase.
98+
**[6]:** When observed from the client side, and when communicating through an intermediary, `server.port` SHOULD represent the server port behind any intermediaries, for example proxies, if it's available.
10299

103-
**[6]:** When observed from the client side, and when communicating through an intermediary, `server.address` SHOULD represent the server address behind any intermediaries, for example proxies, if it's available.
104-
105-
**[7]:** When observed from the client side, and when communicating through an intermediary, `server.port` SHOULD represent the server port behind any intermediaries, for example proxies, if it's available.
106-
107-
**[8]:** If using a port other than the default port for this DBMS and if `server.address` is set.
100+
**[7]:** If using a port other than the default port for this DBMS and if `server.address` is set.
108101

109102
`db.system` has the following list of well-known values. If one of them applies, then the respective value MUST be used, otherwise a custom value MAY be used.
110103

@@ -162,22 +155,6 @@ different processes could be listening on TCP port 12345 and UDP port 12345.
162155
| `clickhouse` | ClickHouse |
163156
| `spanner` | Cloud Spanner |
164157
| `trino` | Trino |
165-
166-
`network.transport` has the following list of well-known values. If one of them applies, then the respective value MUST be used, otherwise a custom value MAY be used.
167-
168-
| Value | Description |
169-
|---|---|
170-
| `tcp` | TCP |
171-
| `udp` | UDP |
172-
| `pipe` | Named or anonymous pipe. |
173-
| `unix` | Unix domain socket |
174-
175-
`network.type` has the following list of well-known values. If one of them applies, then the respective value MUST be used, otherwise a custom value MAY be used.
176-
177-
| Value | Description |
178-
|---|---|
179-
| `ipv4` | IPv4 |
180-
| `ipv6` | IPv6 |
181158
<!-- endsemconv -->
182159

183160
### Notes and well-known identifiers for `db.system`

docs/database/elasticsearch.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ If the endpoint id is not available, the span name SHOULD be the `http.request.m
3232
| [`db.operation`](../attributes-registry/db.md) | string | The endpoint identifier for the request. [4] | `search`; `ml.close_job`; `cat.aliases` | Required |
3333
| [`db.statement`](../attributes-registry/db.md) | string | The request body for a [search-type query](https://www.elastic.co/guide/en/elasticsearch/reference/current/search.html), as a json string. | `"{\"query\":{\"term\":{\"user.id\":\"kimchy\"}}}"` | Recommended: [5] |
3434
| [`http.request.method`](../attributes-registry/http.md) | string | HTTP request method. [6] | `GET`; `POST`; `HEAD` | Required |
35-
| [`server.address`](../attributes-registry/server.md) | string | Name of the database host. [7] | `example.com`; `10.1.2.80`; `/tmp/my.sock` | Recommended |
36-
| [`server.port`](../attributes-registry/server.md) | int | Server port number. [8] | `80`; `8080`; `443` | Conditionally Required: [9] |
37-
| [`url.full`](../attributes-registry/url.md) | string | Absolute URL describing a network resource according to [RFC3986](https://www.rfc-editor.org/rfc/rfc3986) [10] | `https://localhost:9200/index/_search?q=user.id:kimchy` | Required |
35+
| [`network.peer.address`](../attributes-registry/network.md) | string | Peer address of the database node where the operation was performed. [7] | `10.1.2.80`; `/tmp/my.sock` | Recommended |
36+
| [`network.peer.port`](../attributes-registry/network.md) | int | Peer port number of the network connection. | `65123` | Recommended: if and only if `network.peer.address` is set. |
37+
| [`server.address`](../attributes-registry/server.md) | string | Name of the database host. [8] | `example.com`; `10.1.2.80`; `/tmp/my.sock` | Recommended |
38+
| [`server.port`](../attributes-registry/server.md) | int | Server port number. [9] | `80`; `8080`; `443` | Conditionally Required: [10] |
39+
| [`url.full`](../attributes-registry/url.md) | string | Absolute URL describing a network resource according to [RFC3986](https://www.rfc-editor.org/rfc/rfc3986) [11] | `https://localhost:9200/index/_search?q=user.id:kimchy` | Required |
3840

3941
**[1]:** When communicating with an Elastic Cloud deployment, this should be collected from the "X-Found-Handling-Cluster" HTTP response header.
4042

@@ -61,13 +63,15 @@ HTTP method names are case-sensitive and `http.request.method` attribute value M
6163
Instrumentations for specific web frameworks that consider HTTP methods to be case insensitive, SHOULD populate a canonical equivalent.
6264
Tracing instrumentations that do so, MUST also set `http.request.method_original` to the original value.
6365

64-
**[7]:** When observed from the client side, and when communicating through an intermediary, `server.address` SHOULD represent the server address behind any intermediaries, for example proxies, if it's available.
66+
**[7]:** If a database operation involved multiple network calls (for example retries), the address of the last contacted node SHOULD be used.
6567

66-
**[8]:** When observed from the client side, and when communicating through an intermediary, `server.port` SHOULD represent the server port behind any intermediaries, for example proxies, if it's available.
68+
**[8]:** When observed from the client side, and when communicating through an intermediary, `server.address` SHOULD represent the server address behind any intermediaries, for example proxies, if it's available.
6769

68-
**[9]:** If using a port other than the default port for this DBMS and if `server.address` is set.
70+
**[9]:** When observed from the client side, and when communicating through an intermediary, `server.port` SHOULD represent the server port behind any intermediaries, for example proxies, if it's available.
6971

70-
**[10]:** For network calls, URL usually has `scheme://host[:port][path][?query][#fragment]` format, where the fragment is not transmitted over HTTP, but if it is known, it SHOULD be included nevertheless.
72+
**[10]:** If using a port other than the default port for this DBMS and if `server.address` is set.
73+
74+
**[11]:** For network calls, URL usually has `scheme://host[:port][path][?query][#fragment]` format, where the fragment is not transmitted over HTTP, but if it is known, it SHOULD be included nevertheless.
7175
`url.full` MUST NOT contain credentials passed via URL in form of `https://username:password@www.example.com/`. In such case username and password SHOULD be redacted and attribute's value SHOULD be `https://REDACTED:REDACTED@www.example.com/`.
7276
`url.full` SHOULD capture the absolute URL when it is available (or can be reconstructed). Sensitive content provided in `url.full` SHOULD be scrubbed when instrumentations can identify it.
7377

docs/database/redis.md

+4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ described on this page.
1919
|---|---|---|---|---|
2020
| [`db.redis.database_index`](../attributes-registry/db.md) | int | 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` | Conditionally Required: If other than the default database (`0`). |
2121
| [`db.statement`](../attributes-registry/db.md) | string | The full syntax of the Redis CLI command. [1] | `HMSET myhash field1 'Hello' field2 'World'` | Recommended: [2] |
22+
| [`network.peer.address`](../attributes-registry/network.md) | string | Peer address of the database node where the operation was performed. [3] | `10.1.2.80`; `/tmp/my.sock` | Recommended |
23+
| [`network.peer.port`](../attributes-registry/network.md) | int | Peer port number of the network connection. | `65123` | Recommended: if and only if `network.peer.address` is set. |
2224

2325
**[1]:** For **Redis**, the value provided for `db.statement` SHOULD correspond to the syntax of the Redis CLI. If, for example, the [`HMSET` command](https://redis.io/commands/hmset) is invoked, `"HMSET myhash field1 'Hello' field2 'World'"` would be a suitable value for `db.statement`.
2426

2527
**[2]:** Should be collected by default only if there is sanitization that excludes sensitive information.
28+
29+
**[3]:** If a database operation involved multiple network calls (for example retries), the address of the last contacted node SHOULD be used.
2630
<!-- endsemconv -->
2731

2832
## Example

model/trace/database.yaml

+42-18
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
groups:
2-
- id: db
3-
type: span
4-
brief: >
5-
This document defines the attributes used to perform database client calls.
6-
span_kind: client
2+
- id: db.common.attributes
3+
type: attribute_group
4+
brief: This group defines the attributes used to perform database client calls.
75
attributes:
86
- ref: db.system
97
requirement_level: required
@@ -24,15 +22,41 @@ groups:
2422
- ref: server.port
2523
requirement_level:
2624
conditionally_required: If using a port other than the default port for this DBMS and if `server.address` is set.
25+
- ref: db.instance.id
26+
requirement_level:
27+
recommended: If different from the `server.address`
2728
- ref: network.peer.address
29+
brief: Peer address of the database node where the operation was performed.
30+
requirement_level:
31+
recommended: If applicable for this database system.
32+
note: >
33+
Semantic conventions for individual database systems SHOULD document whether `network.peer.*` attributes are applicable.
34+
Network peer address and port are useful when the application interacts with individual database nodes directly.
35+
36+
If a database operation involved multiple network calls (for example retries), the address of the last contacted node SHOULD be used.
2837
- ref: network.peer.port
2938
requirement_level:
30-
recommended: If `network.peer.address` is set.
31-
- ref: network.transport
32-
- ref: network.type
33-
- ref: db.instance.id
39+
recommended: if and only if `network.peer.address` is set.
40+
41+
- id: db.tech_specific.network.attributes
42+
type: attribute_group
43+
brief: This group documents attributes that describe database call along with network information.
44+
extends: db.common.attributes
45+
attributes:
46+
- ref: network.peer.address
3447
requirement_level:
35-
recommended: If different from the `server.address`
48+
recommended
49+
note: >
50+
If a database operation involved multiple network calls (for example retries), the address of the last contacted node SHOULD be used.
51+
tag: tech-specific
52+
- ref: network.peer.port
53+
tag: tech-specific
54+
55+
- id: db
56+
type: span
57+
brief: This span defines the attributes used to perform database client calls.
58+
span_kind: client
59+
extends: db.common.attributes
3660

3761
- id: db.mssql
3862
type: span
@@ -45,7 +69,7 @@ groups:
4569

4670
- id: db.cassandra
4771
type: span
48-
extends: db
72+
extends: db.tech_specific.network.attributes
4973
brief: >
5074
Attributes for Cassandra
5175
attributes:
@@ -72,7 +96,7 @@ groups:
7296

7397
- id: db.hbase
7498
type: span
75-
extends: db
99+
extends: db.common.attributes
76100
brief: >
77101
Attributes for HBase
78102
attributes:
@@ -85,7 +109,7 @@ groups:
85109

86110
- id: db.couchdb
87111
type: span
88-
extends: db
112+
extends: db.common.attributes
89113
brief: >
90114
Attributes for CouchDB
91115
attributes:
@@ -103,7 +127,7 @@ groups:
103127
104128
- id: db.redis
105129
type: span
106-
extends: db
130+
extends: db.tech_specific.network.attributes
107131
brief: >
108132
Attributes for Redis
109133
attributes:
@@ -122,7 +146,7 @@ groups:
122146
123147
- id: db.mongodb
124148
type: span
125-
extends: db
149+
extends: db.common.attributes
126150
brief: >
127151
Attributes for MongoDB
128152
attributes:
@@ -132,7 +156,7 @@ groups:
132156

133157
- id: db.elasticsearch
134158
type: span
135-
extends: db
159+
extends: db.tech_specific.network.attributes
136160
brief: >
137161
Attributes for Elasticsearch
138162
attributes:
@@ -177,7 +201,7 @@ groups:
177201

178202
- id: db.sql
179203
type: span
180-
extends: 'db'
204+
extends: db.common.attributes
181205
brief: >
182206
Attributes for SQL databases
183207
attributes:
@@ -186,7 +210,7 @@ groups:
186210

187211
- id: db.cosmosdb
188212
type: span
189-
extends: db
213+
extends: db.common.attributes
190214
prefix: db.cosmosdb
191215
brief: >
192216
Attributes for Cosmos DB.

0 commit comments

Comments
 (0)