Status: Experimental
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.
Warning Existing Database instrumentations that are using v1.20.0 of this document (or prior):
- SHOULD NOT change the version of the networking conventions that they emit until the HTTP semantic conventions are marked stable (HTTP stabilization will include stabilization of a core set of networking conventions which are also used in Database instrumentations). Conventions include, but are not limited to, attributes, metric and span names, and unit of measure.
- SHOULD introduce an environment variable
OTEL_SEMCONV_STABILITY_OPT_IN
in the existing major version which is a comma-separated list of values. The only values defined so far are:
http
- emit the new, stable networking conventions, and stop emitting the old experimental networking conventions that the instrumentation emitted previously.http/dup
- emit both the old and the stable networking conventions, allowing for a seamless transition.- The default behavior (in the absence of one of these values) is to continue emitting whatever version of the old experimental networking conventions the instrumentation was emitting previously.
- Note:
http/dup
has higher precedence thanhttp
in case both values are present- SHOULD maintain (security patching at a minimum) the existing major version for at least six months after it starts emitting both sets of conventions.
- SHOULD drop the environment variable in the next major version.
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), 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.name> <db.name>.<db.collection.name>
, provided that db.operation.name
and db.collection.name
are available.
If db.collection.name
is not available due to its semantics, the span SHOULD be named <db.operation.name> <db.name>
.
It is not recommended to attempt any client-side parsing of db.statement
just to get these properties,
they should only be used if the library being instrumented already provides them.
When it's otherwise impossible to get any meaningful span name, db.name
or the tech-specific database name MAY be used.
Span that describes database call SHOULD cover the duration of the corresponding call as if it was observed by the caller (such as client application). For example, if a transient issue happened and was retried within this database call, the corresponding span should cover the duration of the logical operation with all retries.
These attributes will usually be the same for all operations performed over the same database connection.
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 |
|
db.query.text |
string | The database query being executed. | SELECT * FROM wuser_table where username = ? ; SET mykey "WuValue" |
Recommended [7] |
|
network.peer.address |
string | Peer address of the database node where the operation was performed. [8] | 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. [9] | example.com ; 10.1.2.80 ; /tmp/my.sock |
Recommended |
|
db.query.parameter.<key> |
string | The query parameters used in db.query.text , with <key> being the parameter name, and the attribute value being the parameter value. [10] |
someval ; 55 |
Opt-In |
[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]: Should be collected by default only if there is sanitization that excludes sensitive information.
[8]: 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.
[9]: 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.
[10]: Query parameters should only be captured when db.query.text
is parameterized with placeholders.
If a parameter has no name and instead is referenced only by index, then <key>
SHOULD be the 0-based index.
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.
The list above is a non-exhaustive list of well-known identifiers to be specified for db.system
.
If a value defined in this list applies to the DBMS to which the request is sent, this value MUST be used. If no value defined in this list is suitable, a custom value MUST be provided. This custom value MUST be the name of the DBMS in lowercase and without a version number to stay consistent with existing identifiers.
It is encouraged to open a PR towards this specification to add missing values to the list, especially when instrumentations for those missing databases are written. This allows multiple instrumentations for the same database to be aligned and eases analyzing for backends.
The value other_sql
is intended as a fallback and MUST only be used if the DBMS is known to be SQL-compliant but the concrete product is not known to the instrumentation.
If the concrete DBMS is known to the instrumentation, its specific identifier MUST be used.
Back ends could, for example, use the provided identifier to determine the appropriate SQL dialect for parsing the db.statement
.
When additional attributes are added that only apply to a specific DBMS, its identifier SHOULD be used as a namespace in the attribute key as for the attributes in the sections below.
More specific Semantic Conventions are defined for the following database technologies:
- AWS DynamoDB: Semantic Conventions for AWS DynamoDB.
- Cassandra: Semantic Conventions for Cassandra.
- Cosmos DB: Semantic Conventions for Microsoft Cosmos DB.
- CouchDB: Semantic Conventions for CouchDB.
- Elasticsearch: Semantic Conventions for Elasticsearch.
- HBase: Semantic Conventions for HBase.
- MongoDB: Semantic Conventions for MongoDB.
- MSSQL: Semantic Conventions for MSSQL.
- Redis: Semantic Conventions for Redis.
- SQL: Semantic Conventions for SQL databases.