CosmosDiagnosticsContext Class

  • java.lang.Object
    • com.azure.cosmos.CosmosDiagnosticsContext

public final class CosmosDiagnosticsContext

This class provides metadata for an operation in the Cosmos DB SDK that can be used by diagnostic handlers

Method Summary

Modifier and Type Method and Description
String getAccountName()

The name of the account related to the operation

Integer getActualItemCount()

The actual number of items returned by a feed operation

String getConnectionMode()

Returns the connection mode used in the client.

Set<String> getContactedRegionNames()

Returns the set of contacted regions

String getContainerName()

The name of the container related to the operation

String getDatabaseName()

The name of the database related to the operation

Collection<CosmosDiagnostics> getDiagnostics()

The diagnostic records for service interactions within the scope of this SDK operation

Duration getDuration()

The total end-to-end duration of the operation.

ConsistencyLevel getEffectiveConsistencyLevel()

The effective consistency level of the operation

Throwable getFinalError()

The final error when the operation failed

Set<String> getKeywordIdentifiers()

Gets the custom ids.

Integer getMaxItemCount()

The max.

int getMaxRequestPayloadSizeInBytes()

The max.

int getMaxResponsePayloadSizeInBytes()

The max.

String getOperationId()

The operation identifier of the operation - this can be used to add a dimension for feed operations - like queries - so, metrics and diagnostics can be separated for different query types etc.

String getOperationType()

The operation type of the operation

String getQueryStatement()

The query statement send by client

Collection<CosmosDiagnosticsRequestInfo> getRequestInfo()

Gets a collection of CosmosDiagnosticsRequestInfo records providing more information about individual requests issued in the transport layer to process this operation.

String getResourceType()

The resource type of the operation

int getRetryCount()

Returns the number of retries and/or attempts for speculative processing.

int getStatusCode()

The final status code of the operation (possibly after retries)

int getSubStatusCode()

The final sub-status code of the operation (possibly after retries)

Map<String,Object> getSystemUsage()

Returns the system usage NOTE: this information is not included in the json representation returned from toJson() because it is usually only relevant when thresholds are violated, in which case the entire diagnostics json-string is included.

float getTotalRequestCharge()

The total request charge across all retries.

String getTrackingId()

The trackingId of a write operation.

String getUserAgent()

Gets the UserAgent header value used by the client issuing this operation NOTE: this information is not included in the json representation returned from toJson() because it is usually only relevant when thresholds are violated, in which case the entire diagnostics json-string is included.

boolean isCompleted()

Returns a flag indicating whether the operation has been completed yet.

boolean isFailure()

A flag indicating whether the operation should be considered failed or not based on the status code handling rules in CosmosDiagnosticsThresholds#setFailureHandler(java.util.function.BiPredicate)

boolean isPointOperation()

A flag indicating whether the operation is a point operation or not.

boolean isThresholdViolated()

Indicates whether the latency, request charge or payload size of the operation exceeded the given threshold

String toJson()

Returns a json-string representation of the diagnostics context.

Methods inherited from java.lang.Object

Method Details

getAccountName

public String getAccountName()

The name of the account related to the operation

Returns:

the name of the account related to the operation

getActualItemCount

public Integer getActualItemCount()

The actual number of items returned by a feed operation

Returns:

the actual number of items returned by a feed operation. Will be null for point operations.

getConnectionMode

public String getConnectionMode()

Returns the connection mode used in the client. NOTE: this information is not included in the json representation returned from toJson() because it is usually only relevant when thresholds are violated, in which case the entire diagnostics json-string is included.

Returns:

the connection mode used in the client.

getContactedRegionNames

public Set getContactedRegionNames()

Returns the set of contacted regions

Returns:

the set of contacted regions

getContainerName

public String getContainerName()

The name of the container related to the operation

Returns:

the name of the collection related to the operation

getDatabaseName

public String getDatabaseName()

The name of the database related to the operation

Returns:

the name of the database related to the operation

getDiagnostics

public Collection getDiagnostics()

The diagnostic records for service interactions within the scope of this SDK operation

Returns:

the diagnostic records for service interactions within the scope of this SDK operation

getDuration

public Duration getDuration()

The total end-to-end duration of the operation.

Returns:

the total end-to-end duration of the operation.

getEffectiveConsistencyLevel

public ConsistencyLevel getEffectiveConsistencyLevel()

The effective consistency level of the operation

Returns:

the effective consistency level of the operation

getFinalError

public Throwable getFinalError()

The final error when the operation failed

Returns:

the final error when the operation failed

getKeywordIdentifiers

public Set getKeywordIdentifiers()

Gets the custom ids.

Returns:

the custom ids.

getMaxItemCount

public Integer getMaxItemCount()

The max. number of items requested in a feed operation

Returns:

the max. number of items requested in a feed operation. Will be null for point operations.

getMaxRequestPayloadSizeInBytes

public int getMaxRequestPayloadSizeInBytes()

The max. request payload size in bytes

Returns:

the max. request payload size in bytes

getMaxResponsePayloadSizeInBytes

public int getMaxResponsePayloadSizeInBytes()

The max. response payload size in bytes.

Returns:

the max. response payload size in bytes

getOperationId

public String getOperationId()

The operation identifier of the operation - this can be used to add a dimension for feed operations - like queries - so, metrics and diagnostics can be separated for different query types etc.

Returns:

the operation identifier of the operation

getOperationType

public String getOperationType()

The operation type of the operation

Returns:

the operation type of the operation

getQueryStatement

public String getQueryStatement()

The query statement send by client

Returns:

the query statement

getRequestInfo

public Collection getRequestInfo()

Gets a collection of CosmosDiagnosticsRequestInfo records providing more information about individual requests issued in the transport layer to process this operation. NOTE: this information is not included in the json representation returned from toJson() because it is usually only relevant when thresholds are violated, in which case the entire diagnostics json-string is included. Calling this method will lazily collect the user agent - which can be useful when writing a custom CosmosDiagnosticsHandler

Returns:

a collection of CosmosDiagnosticsRequestInfo records providing more information about individual requests issued in the transport layer to process this operation.

getResourceType

public String getResourceType()

The resource type of the operation

Returns:

the resource type of the operation

getRetryCount

public int getRetryCount()

Returns the number of retries and/or attempts for speculative processing.

Returns:

the number of retries and/or attempts for speculative processing.

getStatusCode

public int getStatusCode()

The final status code of the operation (possibly after retries)

Returns:

the final status code of the operation (possibly after retries)

getSubStatusCode

public int getSubStatusCode()

The final sub-status code of the operation (possibly after retries)

Returns:

the final sub-status code of the operation (possibly after retries)

getSystemUsage

public Map getSystemUsage()

Returns the system usage NOTE: this information is not included in the json representation returned from toJson() because it is usually only relevant when thresholds are violated, in which case the entire diagnostics json-string is included. Calling this method will lazily collect the system usage - which can be useful when writing a custom CosmosDiagnosticsHandler

Returns:

the system usage

getTotalRequestCharge

public float getTotalRequestCharge()

The total request charge across all retries.

Returns:

the total request charge across all retries.

getTrackingId

public String getTrackingId()

The trackingId of a write operation. Will be null for read-/query- or feed operations or when non-idempotent writes are disabled for writes or only enabled without trackingId propagation.

Returns:

the trackingId of an operation

getUserAgent

public String getUserAgent()

Gets the UserAgent header value used by the client issuing this operation NOTE: this information is not included in the json representation returned from toJson() because it is usually only relevant when thresholds are violated, in which case the entire diagnostics json-string is included.

Returns:

the UserAgent header value used for the client that issued this operation

isCompleted

public boolean isCompleted()

Returns a flag indicating whether the operation has been completed yet.

Returns:

a flag indicating whether the operation has been completed yet.

isFailure

public boolean isFailure()

A flag indicating whether the operation should be considered failed or not based on the status code handling rules in CosmosDiagnosticsThresholds#setFailureHandler(java.util.function.BiPredicate)

Returns:

a flag indicating whether the operation should be considered failed or not

isPointOperation

public boolean isPointOperation()

A flag indicating whether the operation is a point operation or not.

Returns:

a flag indicating whether the operation is a point operation or not.

isThresholdViolated

public boolean isThresholdViolated()

Indicates whether the latency, request charge or payload size of the operation exceeded the given threshold

Returns:

a flag indicating whether the latency, request charge or payload size of the operation exceeded its threshold.

toJson

public String toJson()

Returns a json-string representation of the diagnostics context. This string uses json format for readability, but it should be treated as an opaque string - the format can and will change between SDK versions - for any automatic processing of the diagnostics information the get-properties of public API should be used.

Returns:

a json-string representation of the diagnostics context. This string uses json format for readability, but it should be treated as an opaque string - the format can and will change between SDK versions - for any automatic processing of the diagnostics information the get-properties of public API should be used.

Applies to