semantic-conventions/docs/database/database-spans.md

17 KiB

Semantic Conventions for Database Client Calls

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 the database semantic conventions are marked stable. 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. If the list of values includes:
    • database - emit the new, stable database conventions, and stop emitting the old experimental database conventions that the instrumentation emitted previously.
    • database/dup - emit both the old and the stable database 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 database conventions the instrumentation was emitting previously.
    • Note: database/dup has higher precedence than database 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.

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.

Name

Database spans MUST follow the overall guidelines for span names.

The span name SHOULD be {db.operation.name} {target} if there is a (low-cardinality) db.operation.name available (see below for the exact definition of the {target} placeholder).

If there is no (low-cardinality) db.operation.name available, database span names SHOULD be {target}.

Semantic conventions for individual database systems MAY specify different span name format.

The {target} SHOULD adhere to one of the following values, arranged in prioritized order, provided they are accessible:

  • db.collection.name
  • db.namespace
  • server.address:server.port
  • db.system

Common attributes

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; mssql; mssqlcompact Required Experimental
db.collection.name string The name of a collection (table, container) within the database. [1] public.users; customers Conditionally Required [2] Experimental
db.namespace string The name of the database, fully qualified within the server address and port. [3] customers; test.users Conditionally Required If available. Experimental
db.operation.name string The name of the operation or command being executed. [4] findAndModify; HMSET; SELECT Conditionally Required [5] Experimental
error.type string Describes a class of error the operation ended with. [6] timeout; java.net.UnknownHostException; server_certificate_invalid; 500 Conditionally Required If and only if the operation failed. Stable
server.port int Server port number. [7] 80; 8080; 443 Conditionally Required [8] Stable
db.query.text string The database query being executed. SELECT * FROM wuser_table where username = ?; SET mykey "WuValue" Recommended [9] Experimental
network.peer.address string Peer address of the database node where the operation was performed. [10] 10.1.2.80; /tmp/my.sock Recommended If applicable for this database system. Stable
network.peer.port int Peer port number of the network connection. 65123 Recommended if and only if network.peer.address is set. Stable
server.address string Name of the database host. [11] example.com; 10.1.2.80; /tmp/my.sock Recommended Stable
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. [12] someval; 55 Opt-In Experimental

[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. It is RECOMMENDED to capture the value as provided by the application without attempting to do any case normalization.

[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]: If a database system has multiple namespace components, they SHOULD be concatenated (potentially using database system specific conventions) from most general to most specific namespace component, and more specific namespaces SHOULD NOT be captured without the more general namespaces, to ensure that "startswith" queries for the more general namespaces will be valid. Semantic conventions for individual database systems SHOULD document what db.namespace means in the context of that system. It is RECOMMENDED to capture the value as provided by the application without attempting to do any case normalization.

[4]: It is RECOMMENDED to capture the value as provided by the application without attempting to do any case normalization.

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

[6]: The error.type SHOULD match the error code returned by the database or the client library, the canonical name of exception that occurred, or another low-cardinality error identifier. Instrumentations SHOULD document the list of errors they report.

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

[8]: If using a port other than the default port for this DBMS and if server.address is set.

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

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

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

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

Value Description Stability
other_sql Some other SQL database. Fallback only. See notes. Experimental
mssql Microsoft SQL Server Experimental
mssqlcompact Microsoft SQL Server Compact Experimental
mysql MySQL Experimental
oracle Oracle Database Experimental
db2 IBM Db2 Experimental
postgresql PostgreSQL Experimental
redshift Amazon Redshift Experimental
hive Apache Hive Experimental
cloudscape Cloudscape Experimental
hsqldb HyperSQL DataBase Experimental
progress Progress Database Experimental
maxdb SAP MaxDB Experimental
hanadb SAP HANA Experimental
ingres Ingres Experimental
firstsql FirstSQL Experimental
edb EnterpriseDB Experimental
cache InterSystems Caché Experimental
adabas Adabas (Adaptable Database System) Experimental
firebird Firebird Experimental
derby Apache Derby Experimental
filemaker FileMaker Experimental
informix Informix Experimental
instantdb InstantDB Experimental
interbase InterBase Experimental
mariadb MariaDB Experimental
netezza Netezza Experimental
pervasive Pervasive PSQL Experimental
pointbase PointBase Experimental
sqlite SQLite Experimental
sybase Sybase Experimental
teradata Teradata Experimental
vertica Vertica Experimental
h2 H2 Experimental
coldfusion ColdFusion IMQ Experimental
cassandra Apache Cassandra Experimental
hbase Apache HBase Experimental
mongodb MongoDB Experimental
redis Redis Experimental
couchbase Couchbase Experimental
couchdb CouchDB Experimental
cosmosdb Microsoft Azure Cosmos DB Experimental
dynamodb Amazon DynamoDB Experimental
neo4j Neo4j Experimental
geode Apache Geode Experimental
elasticsearch Elasticsearch Experimental
memcached Memcached Experimental
cockroachdb CockroachDB Experimental
opensearch OpenSearch Experimental
clickhouse ClickHouse Experimental
spanner Cloud Spanner Experimental
trino Trino Experimental

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

Value Description Stability
_OTHER A fallback error value to be used when the instrumentation doesn't define a custom value. Stable

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.query.text.

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.

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