Semantic Conventions for Microsoft Cosmos DB

Status: Experimental

The Semantic Conventions for Microsoft Cosmos DB extend and override the Database Semantic Conventions that describe common database operations attributes in addition to the Semantic Conventions described on this page.

Call-level attributes

db.system MUST be set to "cosmosdb".

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.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.operation_typestringCosmosDB Operation Type.InvalidConditionally Required: [1]
db.cosmosdb.request_chargedoubleRU consumed for that operation46.18; 1.0Conditionally Required: when 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]
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.connection_mode MUST be one of the following:

ValueDescription
gatewayGateway (HTTP) connections mode
directDirect connection.

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.

ValueDescription
Invalidinvalid
Createcreate
Patchpatch
Readread
ReadFeedread_feed
Deletedelete
Replacereplace
Executeexecute
Queryquery
Headhead
HeadFeedhead_feed
Upsertupsert
Batchbatch
QueryPlanquery_plan
ExecuteJavaScriptexecute_javascript

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

Example

KeyValue
Span name"ReadItemsAsync"
kind"internal"
az.namespace"Microsoft.DocumentDB"
db.system"cosmosdb"
db.name"database name"
db.operation"ReadItemsAsync"
server.address"account.documents.azure.com"
db.cosmosdb.client_id3ba4827d-4422-483f-b59f-85b74211c11d
db.cosmosdb.operation_typeRead
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.connection_mode"Direct"
db.cosmosdb.container"container name"
db.cosmosdb.request_content_length20
db.cosmosdb.status_code201
db.cosmosdb.sub_status_code0
db.cosmosdb.request_charge7.43