Semantic Conventions for Database Client Calls
Warning Existing Database instrumentations that are using v1.20.0 of this document (or prior):
- SHOULD NOT change the version of the networking attributes that they emit until the HTTP semantic conventions are marked stable (HTTP stabilization will include stabilization of a core set of networking attributes which are also used in Database instrumentations).
- SHOULD introduce an environment variable
OTEL_SEMCONV_STABILITY_OPT_INin 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 attributes, and stop emitting the old experimental networking attributes that the instrumentation emitted previously.
http/dup- emit both the old and the stable networking attributes, 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 attributes the instrumentation was emitting previously.
- SHOULD maintain (security patching at a minimum) the existing major version for at least six months after it starts emitting both sets of attributes.
- SHOULD drop the environment variable in the next major version (stable next major version SHOULD NOT be released prior to October 1, 2023).
Span kind: MUST always be
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> <db.name>.<db.sql.table>, provided that
db.sql.table are available.
db.sql.table is not available due to its semantics, the span SHOULD be named
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.
These attributes will usually be the same for all operations performed over the same database connection.
Some database systems may allow a connection to switch to a different
db.user, for example, and other database systems may not even have the concept of a connection at all.
|string||An identifier for the database management system (DBMS) product being used. See below for a list of well-known identifiers.||Required|
|string||The connection string used to connect to the database. It is recommended to remove embedded credentials.||Recommended|
|string||Username for accessing the database.||Recommended|
|string||OSI Transport Layer or Inter-process Communication method. The value SHOULD be normalized to lowercase.||Recommended|
|string||OSI Network Layer or non-OSI equivalent. The value SHOULD be normalized to lowercase.||Recommended|
|string||Name of the database host.||Conditionally Required: See alternative attributes below.|
|int||Logical server port number||Conditionally Required: |
|string||Physical server IP address or Unix socket address. If set from the client, should simply use the socket’s peer address, and not attempt to find any actual server IP (i.e., if set from client, this may represent some proxy server instead of the logical server).||See below|
|int||Physical server port.||Recommended: If different than |
: If using a port other than the default port for this DBMS and if
server.address is set.
Additional attribute requirements: At least one of the following sets of attributes is required:
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.
|Some other SQL database. Fallback only. See notes.|
|Microsoft SQL Server|
|Microsoft SQL Server Compact|
|Adabas (Adaptable Database System)|
|Microsoft Azure Cosmos DB|
Notes and well-known identifiers for
The list above is a non-exhaustive list of well-known identifiers to be specified for
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.
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
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.
These attributes may be different for each operation performed, even if the same connection is used for multiple operations.
Usually only one
db.name will be used per connection though.
|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). ||Conditionally Required: If applicable.|
|string||The database statement being executed.||Recommended: |
|string||The name of the operation being executed, e.g. the MongoDB command name such as ||Conditionally Required: If |
: 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).
: Should be collected by default only if there is sanitization that excludes sensitive information.
: 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.
Semantic Conventions for specific database technologies
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.
- GraphQL: Semantic Conventions for GraphQL Server.
- 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.