Semantic Conventions for Microsoft Cosmos DB

Status: Experimental

The Semantic Conventions for Microsoft Cosmos DB extend and override the Database Semantic Conventions.

Attributes

db.system MUST be set to "cosmosdb" and SHOULD be provided at span creation time.

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 LevelStability
db.collection.namestringCosmos DB container name. [1]public.users; customersConditionally Required if availableExperimental
db.cosmosdb.connection_modestringCosmos client connection mode.gateway; directConditionally Required if not direct (or pick gw as default)Experimental
db.cosmosdb.operation_typestringCosmosDB Operation Type.Invalid; Create; PatchConditionally Required when performing one of the operations in this listExperimental
db.cosmosdb.request_chargedoubleRU consumed for that operation46.18; 1.0Conditionally Required when availableExperimental
db.cosmosdb.status_codeintCosmos DB status code.200; 201Conditionally Required if response was receivedExperimental
db.cosmosdb.sub_status_codeintCosmos DB sub status code.1000; 1002Conditionally Required when response was received and contained sub-code.Experimental
db.namespacestringThe name of the database, fully qualified within the server address and port.customers; test.usersConditionally Required If available.Experimental
db.operation.namestringThe name of the operation or command being executed. [2]findAndModify; HMSET; SELECTConditionally Required [3]Experimental
error.typestringDescribes a class of error the operation ended with. [4]timeout; java.net.UnknownHostException; server_certificate_invalid; 500Conditionally Required If and only if the operation failed.Stable
server.portintServer port number. [5]80; 8080; 443Conditionally Required [6]Stable
db.cosmosdb.client_idstringUnique Cosmos client instance id.3ba4827d-4422-483f-b59f-85b74211c11dRecommendedExperimental
db.cosmosdb.request_content_lengthintRequest payload size in bytesRecommendedExperimental
db.query.textstringThe database query being executed. [7]SELECT * FROM wuser_table where username = ?; SET mykey "WuValue"Recommended [8]Experimental
server.addressstringName of the database host. [9]example.com; 10.1.2.80; /tmp/my.sockRecommendedStable
user_agent.originalstringFull user-agent string is generated by Cosmos DB SDK [10]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|RecommendedStable
db.query.parameter.<key>stringA query parameter used in db.query.text, with <key> being the parameter name, and the attribute value being a string representation of the parameter value. [11]someval; 55Opt-InExperimental

[1]: It is RECOMMENDED to capture the value as provided by the application without attempting to do any case normalization. If the collection name is parsed from the query text, it SHOULD be the first collection name found in the query and it SHOULD match the value provided in the query text including any schema and database name prefix. For batch operations, if the individual operations are known to have the same collection name then that collection name SHOULD be used, otherwise db.collection.name SHOULD NOT be captured.

[2]: It is RECOMMENDED to capture the value as provided by the application without attempting to do any case normalization. If the operation name is parsed from the query text, it SHOULD be the first operation name found in the query. For batch operations, if the individual operations are known to have the same operation name then that operation name SHOULD be used prepended by BATCH , otherwise db.operation.name SHOULD be BATCH or some other database system specific term if more applicable.

[3]: If readily available. The operation name MAY be parsed from the query text, in which case it SHOULD be the first operation name found in the query.

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

[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]: For sanitization see Sanitization of db.query.text. For batch operations, if the individual operations are known to have the same query text then that query text SHOULD be used, otherwise all of the individual query texts SHOULD be concatenated with separator ; or some other database system specific separator if more applicable. Even though parameterized query text can potentially have sensitive data, by using a parameterized query the user is giving a strong signal that any sensitive data will be passed as parameter values, and the benefit to observability of capturing the static part of the query text by default outweighs the risk.

[8]: SHOULD be collected by default only if there is sanitization that excludes sensitive information. See Sanitization of db.query.text.

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

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

The following attributes can be important for making sampling decisions and SHOULD be provided at span creation time (if provided at all):

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

ValueDescriptionStability
directDirect connection.Experimental
gatewayGateway (HTTP) connections modeExperimental

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.

ValueDescriptionStability
BatchbatchExperimental
CreatecreateExperimental
DeletedeleteExperimental
ExecuteexecuteExperimental
ExecuteJavaScriptexecute_javascriptExperimental
HeadheadExperimental
HeadFeedhead_feedExperimental
InvalidinvalidExperimental
PatchpatchExperimental
QueryqueryExperimental
QueryPlanquery_planExperimental
ReadreadExperimental
ReadFeedread_feedExperimental
ReplacereplaceExperimental
UpsertupsertExperimental

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.

ValueDescriptionStability
_OTHERA fallback error value to be used when the instrumentation doesn’t define a custom value.Stable

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 orders"
kind"internal"
az.namespace"Microsoft.DocumentDB"
db.system"cosmosdb"
db.collection.name"orders"
db.namespace"ShopDb"
db.operation.name"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.request_content_length20
db.cosmosdb.status_code201
db.cosmosdb.sub_status_code0
db.cosmosdb.request_charge7.43