16 KiB
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.
| Attribute | Type | Description | Examples | Requirement Level | Stability |
|---|---|---|---|---|---|
db.collection.name |
string | Cosmos DB container name. [1] | public.users; customers |
Conditionally Required if available |
|
db.cosmosdb.connection_mode |
string | Cosmos client connection mode. | gateway; direct |
Conditionally Required [2] |
|
db.cosmosdb.operation_type |
string | Cosmos DB Operation Type. | batch; create; delete |
Conditionally Required when performing one of the operations in this list |
|
db.cosmosdb.request_charge |
double | RU consumed for that operation | 46.18; 1.0 |
Conditionally Required when available |
|
db.cosmosdb.status_code |
int | Cosmos DB status code. | 200; 201 |
Conditionally Required if response was received |
|
db.cosmosdb.sub_status_code |
int | Cosmos DB sub status code. | 1000; 1002 |
Conditionally Required when response was received and contained sub-code. |
|
db.namespace |
string | The name of the database, fully qualified within the server address and port. | customers; test.users |
Conditionally Required If available. |
|
db.operation.name |
string | The name of the operation or command being executed. [3] | create_item; query_items; read_item |
Conditionally Required [4] |
|
error.type |
string | Describes a class of error the operation ended with. [5] | timeout; java.net.UnknownHostException; server_certificate_invalid; 500 |
Conditionally Required If and only if the operation failed. |
|
server.port |
int | Server port number. [6] | 80; 8080; 443 |
Conditionally Required If not default (443). |
|
az.namespace |
string | Azure Resource Provider Namespace as recognized by the client. [7] | Microsoft.DocumentDB |
Recommended |
|
db.cosmosdb.client_id |
string | Unique Cosmos client instance id. | 3ba4827d-4422-483f-b59f-85b74211c11d |
Recommended |
|
db.cosmosdb.request_content_length |
int | Request payload size in bytes | Recommended |
||
db.query.text |
string | The database query being executed. [8] | SELECT * FROM wuser_table where username = ?; SET mykey "WuValue" |
Recommended [9] |
|
server.address |
string | Name of the database host. [10] | example.com; 10.1.2.80; /tmp/my.sock |
Recommended |
|
user_agent.original |
string | Full user-agent string is generated by Cosmos DB SDK [11] | 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 |
|
db.query.parameter.<key> |
string | A 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. [12] |
someval; 55 |
Opt-In |
[1]: It is RECOMMENDED to capture the value as provided by the application without attempting to do any case normalization.
[2]: if not gateway (the default value is assumed to be gateway).
[3]: The db.operation.name has the following list of well-known values.
If one of them applies, then the respective value MUST be used.
Batch operations:
execute_batch
Bulk operations:
execute_bulkSHOULD be used on spans reported for methods likeexecuteBulkOperations). which represents a bulk execution of multiple operations.bulk_{operation name}(bulk_create_item,bulk_upsert_item, etc) SHOULD be used on spans describing individual operations (when they are reported) within the bulk. This pattern SHOULD be used when instrumentation creates span per each operation, but operations are buffered and then performed in bulk. For example, this applies whenAllowBulkExecutionproperty is configured on theMicrosoft.Azure.Cosmosclient.
Change feed operations:
query_change_feed
Conflicts operations:
delete_conflictquery_conflictsread_all_conflictsread_conflict
Container operations:
create_containercreate_container_if_not_existsdelete_containerquery_containersread_all_containersread_containerread_container_throughputreplace_containerreplace_container_throughput
Database operations:
create_databasecreate_database_if_not_existsdelete_databasequery_databasesread_all_databasesread_databaseread_database_throughputreplace_database_throughput
Encryption key operations:
create_client_encryption_keyquery_client_encryption_keysread_all_client_encryption_keysread_client_encryption_keyreplace_client_encryption_key
Item operations:
create_itemdelete_all_items_by_partition_keydelete_itempatch_itemquery_itemsread_all_itemsread_all_items_of_logical_partitionread_many_itemsread_itemreplace_itemupsert_item
Permission operations:
create_permissiondelete_permissionquery_permissionsread_all_permissionsread_permissionreplace_permissionupsert_permission
Stored procedure operations:
create_stored_proceduredelete_stored_procedureexecute_stored_procedurequery_stored_proceduresread_all_stored_proceduresread_stored_procedurereplace_stored_procedure
Trigger operations:
create_triggerdelete_triggerquery_triggersread_all_triggersread_triggerreplace_trigger
User operations:
create_userdelete_userquery_usersread_all_usersread_userreplace_userupsert_user
User-defined function operations:
create_user_defined_functiondelete_user_defined_functionquery_user_defined_functionsread_all_user_defined_functionsread_user_defined_function
If none of them applies, it's RECOMMENDED to use language-agnostic representation of client method name in snake_case. Instrumentations SHOULD document additional values when introducing new operations.
[4]: 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.
[5]: 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.
[6]: 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.
[7]: When az.namespace attribute is populated, it MUST be set to Microsoft.DocumentDB for all operations performed by Cosmos DB client.
[8]: 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.
[9]: SHOULD be collected by default only if there is sanitization that excludes sensitive information. See Sanitization of db.query.text.
[10]: 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.
[11]: 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".
[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.
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.
| Value | Description | Stability |
|---|---|---|
direct |
Direct connection. | |
gateway |
Gateway (HTTP) connections mode |
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.
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. |
Example
| Key | Value |
|---|---|
| Span name | "read_item orders" |
az.namespace |
"Microsoft.DocumentDB" |
db.system |
"cosmosdb" |
db.collection.name |
"orders" |
db.namespace |
"ShopDb" |
db.operation.name |
"read_item" |
server.address |
"account.documents.azure.com" |
db.cosmosdb.client_id |
"3ba4827d-4422-483f-b59f-85b74211c11d" |
db.cosmosdb.operation_type |
"read" |
user_agent.original |
"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|" |
db.cosmosdb.request_content_length |
20 |
db.cosmosdb.status_code |
201 |
db.cosmosdb.sub_status_code |
0 |
db.cosmosdb.request_charge |
7.43 |