Semantic conventions for database client calls

NOTICE Semantic Conventions are moving to a new location.

No changes to this document are allowed.

Status: Experimental

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_IN in the existing major version which supports the following values:
    • none - continue emitting whatever version of the old experimental database attributes the instrumentation was emitting previously. This is the default value.
    • 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.
  • 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 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> <>.<db.sql.table>, provided that db.operation and db.sql.table are available. If db.sql.table is not available due to its semantics, the span SHOULD be named <db.operation> <>. 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, or the tech-specific database name MAY be used.

Connection-level attributes

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.

AttributeTypeDescriptionExamplesRequirement Level
db.systemstringAn identifier for the database management system (DBMS) product being used. See below for a list of well-known identifiers.other_sqlRequired
db.connection_stringstringThe connection string used to connect to the database. It is recommended to remove embedded credentials.Server=(localdb)\v11.0;Integrated Security=true;Recommended
db.userstringUsername for accessing the database.readonly_user; reporting_userRecommended
network.transportstringOSI Transport Layer or Inter-process Communication method. The value SHOULD be normalized to lowercase.tcp; udpRecommended
network.typestringOSI Network Layer or non-OSI equivalent. The value SHOULD be normalized to lowercase.ipv4; ipv6Recommended
server.addressstringName of the database host.example.comConditionally Required: See alternative attributes below.
server.portintLogical server port number80; 8080; 443Conditionally Required: [1]
server.socket.addressstringPhysical server IP address or Unix socket address. below
server.socket.portintPhysical server port.16456Recommended: If different than server.port.

[1]: 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.

other_sqlSome other SQL database. Fallback only. See notes.
mssqlMicrosoft SQL Server
mssqlcompactMicrosoft SQL Server Compact
oracleOracle Database
db2IBM Db2
redshiftAmazon Redshift
hiveApache Hive
hsqldbHyperSQL DataBase
progressProgress Database
maxdbSAP MaxDB
hanadbSAP HANA
cacheInterSystems Caché
adabasAdabas (Adaptable Database System)
derbyApache Derby
pervasivePervasive PSQL
coldfusionColdFusion IMQ
cassandraApache Cassandra
hbaseApache HBase
cosmosdbMicrosoft Azure Cosmos DB
dynamodbAmazon DynamoDB
geodeApache Geode
spannerCloud Spanner

Notes and well-known identifiers for db.system

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.

Connection-level attributes for specific technologies

AttributeTypeDescriptionExamplesRequirement Level
db.jdbc.driver_classnamestringThe fully-qualified class name of the Java Database Connectivity (JDBC) driver used to;
db.mssql.instance_namestringThe Microsoft SQL Server instance name connecting to. This name is used to determine the port of a named instance. [1]MSSQLSERVERRecommended

[1]: If setting a db.mssql.instance_name, server.port is no longer required (but still recommended if non-standard).

Call-level attributes

These attributes may be different for each operation performed, even if the same connection is used for multiple operations. Usually only one will be used per connection though.

AttributeTypeDescriptionExamplesRequirement Level
db.namestringThis 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). [1]customers; mainConditionally Required: If applicable.
db.statementstringThe database statement being executed.SELECT * FROM wuser_table; SET mykey "WuValue"Recommended: [2]
db.operationstringThe name of the operation being executed, e.g. the MongoDB command name such as findAndModify, or the SQL keyword. [3]findAndModify; HMSET; SELECTConditionally Required: If db.statement is not applicable.

[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).

[2]: Should be collected by default only if there is sanitization that excludes sensitive information.

[3]: 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.

For Redis, the value provided for db.statement SHOULD correspond to the syntax of the Redis CLI. If, for example, the HMSET command is invoked, "HMSET myhash field1 'Hello' field2 'World'" would be a suitable value for db.statement.

In CouchDB, db.operation should be set to the HTTP method + the target REST route according to the API reference documentation. For example, when retrieving a document, db.operation would be set to (literally, i.e., without replacing the placeholders with concrete values): GET /{db}/{docid}.

In Cassandra, SHOULD be set to the keyspace name.

In HBase, SHOULD be set to the HBase namespace.

Call-level attributes for specific technologies

AttributeTypeDescriptionExamplesRequirement Level
db.redis.database_indexintThe index of the database being accessed as used in the SELECT command, provided as an integer. To be used instead of the generic attribute.0; 1; 15Conditionally Required: If other than the default database (0).
db.mongodb.collectionstringThe collection being accessed within the database stated in; productsRequired
db.sql.tablestringThe name of the primary table that the operation is acting upon, including the database name (if applicable). [1]public.users; customersRecommended

[1]: 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.


Separated for clarity.

AttributeTypeDescriptionExamplesRequirement Level
db.cassandra.page_sizeintThe fetch size used for paging, i.e. how many rows will be returned at once.5000Recommended
db.cassandra.consistency_levelstringThe consistency level of the query. Based on consistency values from CQL.allRecommended
db.cassandra.tablestringThe name of the primary table that the operation is acting upon, including the keyspace name (if applicable). [1]mytableRecommended
db.cassandra.idempotencebooleanWhether or not the query is idempotent.Recommended
db.cassandra.speculative_execution_countintThe number of times a query was speculatively executed. Not set or 0 if the query was not executed speculatively.0; 2Recommended
db.cassandra.coordinator.idstringThe ID of the coordinating node for a query.be13faa2-8574-4d71-926d-27f16cf8a7afRecommended
db.cassandra.coordinator.dcstringThe data center of the coordinating node for a

[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.

Microsoft Azure Cosmos DB Attributes

Cosmos DB instrumentation includes call-level (public API) surface spans and network spans. Depending on the connection mode (Gateway or Direct), network-level spans may also be created.

AttributeTypeDescriptionExamplesRequirement Level
db.cosmosdb.client_idstringUnique Cosmos client instance id.3ba4827d-4422-483f-b59f-85b74211c11dRecommended
db.cosmosdb.operation_typestringCosmosDB Operation Type.InvalidConditionally Required: [1]
db.cosmosdb.connection_modestringCosmos client connection mode.gatewayConditionally Required: if not direct (or pick gw as default)
db.cosmosdb.containerstringCosmos DB container name.anystringConditionally Required: if available
db.cosmosdb.request_content_lengthintRequest payload size in bytesRecommended
db.cosmosdb.status_codeintCosmos DB status code.200; 201Conditionally Required: if response was received
db.cosmosdb.sub_status_codeintCosmos DB sub status code.1000; 1002Conditionally Required: [2]
db.cosmosdb.request_chargedoubleRU consumed for that operation46.18; 1.0Conditionally Required: when available
user_agent.originalstringFull user-agent string is generated by Cosmos DB SDK [3]cosmos-netstandard-sdk/3.23.0|3.23.1|1|X64|Linux 5.4.0-1098-azure 104 18|.NET Core 3.1.32|S|Recommended

[1]: when performing one of the operations in this list

[2]: when response was received and contained sub-code.

[3]: The user-agent value is generated by SDK which is a combination of
sdk_version : Current version of SDK. e.g. ‘cosmos-netstandard-sdk/3.23.0’
direct_pkg_version : Direct package version used by Cosmos DB SDK. e.g. ‘3.23.1’
number_of_client_instances : Number of cosmos client instances created by the application. e.g. ‘1’
type_of_machine_architecture : Machine architecture. e.g. ‘X64’
operating_system : Operating System. e.g. ‘Linux 5.4.0-1098-azure 104 18’
runtime_framework : Runtime Framework. e.g. ‘.NET Core 3.1.32’
failover_information : Generated key to determine if region failover enabled. Format Reg-{D (Disabled discovery)}-S(application region)|L(List of preferred regions)|N(None, user did not configure it). Default value is “NS”.

db.cosmosdb.operation_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.


db.cosmosdb.connection_mode MUST be one of the following:

gatewayGateway (HTTP) connections mode
directDirect connection.

In addition to Cosmos DB attributes, all spans include az.namespace attribute representing Azure Resource Provider namespace that MUST be equal to Microsoft.DocumentDB.



Span name"SELECT ShopDb.orders"
db.statement"SELECT * FROM orders WHERE order_id = 'o4711'"


In this example, Redis is connected using a unix domain socket and therefore the connection string and server.address are left out. Furthermore, is not specified as there is no database name in Redis and db.redis.database_index is set instead.

Span name"HMSET myhash"
db.connection_stringnot set
db.usernot set
db.namenot set
db.statement"HMSET myhash field1 'Hello' field2 'World"
db.operationnot set


Span name"products.findAndModify"
db.connection_stringnot set
db.statementnot set

Microsoft Azure Cosmos DB

Span name"ReadItemsAsync"
db.system"cosmosdb""database name"
user_agent.originalcosmos-netstandard-sdk/3.23.0|3.23.1|1|X64|Linux 5.4.0-1098-azure 104 18|.NET Core 3.1.32|S|
db.cosmosdb.container"container name"