Class CosmosDiagnosticsContext

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

public final class CosmosDiagnosticsContext extends Object
This class provides metadata for an operation in the Cosmos DB SDK that can be used by diagnostic handlers
  • 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
    • getDatabaseName

      public String getDatabaseName()
      The name of the database related to the operation
      Returns:
      the name of the database related to the operation
    • getContainerName

      public String getContainerName()
      The name of the container related to the operation
      Returns:
      the name of the collection related to the operation
    • getResourceType

      public String getResourceType()
      The resource type of the operation
      Returns:
      the resource type of the operation
    • getOperationType

      public String getOperationType()
      The operation type of the operation
      Returns:
      the operation type of the operation
    • 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
    • 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.
    • 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
    • getEffectiveConsistencyLevel

      public ConsistencyLevel getEffectiveConsistencyLevel()
      The effective consistency level of the operation
      Returns:
      the effective consistency level of the operation
    • 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.
    • 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.
    • 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.
    • 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)
    • getFinalError

      public Throwable getFinalError()
      The final error when the operation failed
      Returns:
      the final error when the operation failed
    • 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
    • getTotalRequestCharge

      public float getTotalRequestCharge()
      The total request charge across all retries.
      Returns:
      the total request charge across all retries.
    • getContactedRegionNames

      public Set<String> getContactedRegionNames()
      Returns the set of contacted regions
      Returns:
      the set of contacted regions
    • getSystemUsage

      public 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. Calling this method will lazily collect the system usage - which can be useful when writing a custom CosmosDiagnosticsHandler
      Returns:
      the system usage
    • 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.
    • getDiagnostics

      public Collection<CosmosDiagnostics> 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
    • 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.
    • getDuration

      public Duration getDuration()
      The total end-to-end duration of the operation.
      Returns:
      the total end-to-end duration of the operation.
    • 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
    • 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.
    • 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
    • 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.
    • getRequestInfo

      public Collection<CosmosDiagnosticsRequestInfo> 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.