25 KiB
Semantic Conventions for Database Metrics
Status: Experimental
The conventions described in this section are specific to SQL and NoSQL clients.
Disclaimer: These are initial database client metric instruments and attributes but more may be added in the future.
- Database operation
- Connection pools
- Metric:
db.client.connections.usage - Metric:
db.client.connections.idle.max - Metric:
db.client.connections.idle.min - Metric:
db.client.connections.max - Metric:
db.client.connections.pending_requests - Metric:
db.client.connections.timeouts - Metric:
db.client.connections.create_time - Metric:
db.client.connections.wait_time - Metric:
db.client.connections.use_time
- Metric:
Warning Existing database instrumentations that are using v1.24.0 of this document (or prior) SHOULD NOT change the version of the database conventions that they emit until a transition plan to the (future) stable semantic conventions has been published. Conventions include, but are not limited to, attributes, metric and span names, and unit of measure.
Database operation
Metric: db.client.operation.duration
Status: Experimental
This metric is required.
When this metric is reported alongside a database operation span, the metric value SHOULD be the same as the database operation span duration.
This metric SHOULD be specified with
ExplicitBucketBoundaries
of [ 0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10 ].
| Name | Instrument Type | Unit (UCUM) | Description | Stability |
|---|---|---|---|---|
db.client.operation.duration |
Histogram | s |
Duration of database client operations. |
| Attribute | Type | Description | Examples | Requirement Level | Stability |
|---|---|---|---|---|---|
db.system |
string | An identifier for the database management system (DBMS) product being used. See below for a list of well-known identifiers. | other_sql |
Required |
|
db.collection.name |
string | The name of a collection (table, container) within the database. [1] | public.users; customers |
Conditionally Required [2] |
|
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). [3] | customers; main |
Conditionally Required If applicable. |
|
db.operation.name |
string | The name of the operation or command being executed. | findAndModify; HMSET; SELECT |
Conditionally Required [4] |
|
server.port |
int | Server port number. [5] | 80; 8080; 443 |
Conditionally Required [6] |
|
db.instance.id |
string | An identifier (address, unique name, or any other identifier) of the database instance that is executing queries or mutations on the current connection. This is useful in cases where the database is running in a clustered environment and the instrumentation is able to record the node executing the query. The client may obtain this value in databases like MySQL using queries like select @@hostname. |
mysql-e26b99z.example.com |
Recommended If different from the server.address |
|
network.peer.address |
string | Peer address of the database node where the operation was performed. [7] | 10.1.2.80; /tmp/my.sock |
Recommended If applicable for this database system. |
|
network.peer.port |
int | Peer port number of the network connection. | 65123 |
Recommended if and only if network.peer.address is set. |
|
server.address |
string | Name of the database host. [8] | example.com; 10.1.2.80; /tmp/my.sock |
Recommended |
[1]: If the collection name is parsed from the query, it SHOULD match the value provided in the query and may be qualified with the schema and database name.
[2]: If readily available. Otherwise, if the instrumentation library parses db.query.text to capture db.collection.name, then it SHOULD be the first collection name found in the query.
[3]: 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).
[4]: If readily available. Otherwise, if the instrumentation library parses db.query.text to capture db.operation.name, then it SHOULD be the first operation name found in the query.
[5]: 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.
[6]: If using a port other than the default port for this DBMS and if server.address is set.
[7]: 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.
If a database operation involved multiple network calls (for example retries), the address of the last contacted node SHOULD be used.
[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.
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.
Connection pools
The following metric instruments describe database client connection pool operations.
Metric: db.client.connections.usage
This metric is required.
| Name | Instrument Type | Unit (UCUM) | Description | Stability |
|---|---|---|---|---|
db.client.connections.usage |
UpDownCounter | {connection} |
The number of connections that are currently in state described by the state attribute |
| Attribute | Type | Description | Examples | Requirement Level | Stability |
|---|---|---|---|---|---|
db.client.connections.pool.name |
string | The name of the connection pool; unique within the instrumented application. In case the connection pool implementation doesn't provide a name, instrumentation should use a combination of server.address and server.port attributes formatted as server.address:server.port. |
myDataSource |
Required |
|
db.client.connections.state |
string | The state of a connection in the pool | idle |
Required |
db.client.connections.state 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.
| Value | Description | Stability |
|---|---|---|
idle |
idle | |
used |
used |
Metric: db.client.connections.idle.max
This metric is recommended.
| Name | Instrument Type | Unit (UCUM) | Description | Stability |
|---|---|---|---|---|
db.client.connections.idle.max |
UpDownCounter | {connection} |
The maximum number of idle open connections allowed |
| Attribute | Type | Description | Examples | Requirement Level | Stability |
|---|---|---|---|---|---|
db.client.connections.pool.name |
string | The name of the connection pool; unique within the instrumented application. In case the connection pool implementation doesn't provide a name, instrumentation should use a combination of server.address and server.port attributes formatted as server.address:server.port. |
myDataSource |
Required |
Metric: db.client.connections.idle.min
This metric is recommended.
| Name | Instrument Type | Unit (UCUM) | Description | Stability |
|---|---|---|---|---|
db.client.connections.idle.min |
UpDownCounter | {connection} |
The minimum number of idle open connections allowed |
| Attribute | Type | Description | Examples | Requirement Level | Stability |
|---|---|---|---|---|---|
db.client.connections.pool.name |
string | The name of the connection pool; unique within the instrumented application. In case the connection pool implementation doesn't provide a name, instrumentation should use a combination of server.address and server.port attributes formatted as server.address:server.port. |
myDataSource |
Required |
Metric: db.client.connections.max
This metric is recommended.
| Name | Instrument Type | Unit (UCUM) | Description | Stability |
|---|---|---|---|---|
db.client.connections.max |
UpDownCounter | {connection} |
The maximum number of open connections allowed |
| Attribute | Type | Description | Examples | Requirement Level | Stability |
|---|---|---|---|---|---|
db.client.connections.pool.name |
string | The name of the connection pool; unique within the instrumented application. In case the connection pool implementation doesn't provide a name, instrumentation should use a combination of server.address and server.port attributes formatted as server.address:server.port. |
myDataSource |
Required |
Metric: db.client.connections.pending_requests
This metric is recommended.
| Attribute | Type | Description | Examples | Requirement Level | Stability |
|---|---|---|---|---|---|
db.client.connections.pool.name |
string | The name of the connection pool; unique within the instrumented application. In case the connection pool implementation doesn't provide a name, instrumentation should use a combination of server.address and server.port attributes formatted as server.address:server.port. |
myDataSource |
Required |
Metric: db.client.connections.timeouts
This metric is recommended.
| Attribute | Type | Description | Examples | Requirement Level | Stability |
|---|---|---|---|---|---|
db.client.connections.pool.name |
string | The name of the connection pool; unique within the instrumented application. In case the connection pool implementation doesn't provide a name, instrumentation should use a combination of server.address and server.port attributes formatted as server.address:server.port. |
myDataSource |
Required |
Metric: db.client.connections.create_time
This metric is recommended.
| Name | Instrument Type | Unit (UCUM) | Description | Stability |
|---|---|---|---|---|
db.client.connections.create_time |
Histogram | ms |
The time it took to create a new connection |
| Attribute | Type | Description | Examples | Requirement Level | Stability |
|---|---|---|---|---|---|
db.client.connections.pool.name |
string | The name of the connection pool; unique within the instrumented application. In case the connection pool implementation doesn't provide a name, instrumentation should use a combination of server.address and server.port attributes formatted as server.address:server.port. |
myDataSource |
Required |
Metric: db.client.connections.wait_time
This metric is recommended.
| Name | Instrument Type | Unit (UCUM) | Description | Stability |
|---|---|---|---|---|
db.client.connections.wait_time |
Histogram | ms |
The time it took to obtain an open connection from the pool |
| Attribute | Type | Description | Examples | Requirement Level | Stability |
|---|---|---|---|---|---|
db.client.connections.pool.name |
string | The name of the connection pool; unique within the instrumented application. In case the connection pool implementation doesn't provide a name, instrumentation should use a combination of server.address and server.port attributes formatted as server.address:server.port. |
myDataSource |
Required |
Metric: db.client.connections.use_time
This metric is recommended.
| Name | Instrument Type | Unit (UCUM) | Description | Stability |
|---|---|---|---|---|
db.client.connections.use_time |
Histogram | ms |
The time between borrowing a connection and returning it to the pool |
| Attribute | Type | Description | Examples | Requirement Level | Stability |
|---|---|---|---|---|---|
db.client.connections.pool.name |
string | The name of the connection pool; unique within the instrumented application. In case the connection pool implementation doesn't provide a name, instrumentation should use a combination of server.address and server.port attributes formatted as server.address:server.port. |
myDataSource |
Required |