Skip to content

Commit

Permalink
Adding diagnostics guidelines (#45)
Browse files Browse the repository at this point in the history
* adding readme note

* adjusting API doc
  • Loading branch information
ealsur authored Jun 23, 2021
1 parent 0bdc0c4 commit a37e985
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@ Azure Cosmos DB has [multiple options](https://docs.microsoft.com/azure/cosmos-d

Using other consistency levels is not recommended as read operations could be getting a stale version of the session.

### Diagnosing and troubleshooting

The provider executes operations on Cosmos DB based on the calls to the `IDistributedCache` APIs. There might be scenarios when the user wants to troubleshoot or diagnose these interactions (for example, on high latency scenarios).

The `CosmosCacheOptions` expose a delegate that can be configured to capture the [Diagnostics](https://docs.microsoft.com/dotnet/api/microsoft.azure.cosmos.cosmosdiagnostics?view=azure-dotnet) from the SDK calls that are happening internally and decide to log them.

```csharp
void captureDiagnostics(CosmosDiagnostics diagnostics)
{
if (diagnostics.GetClientElapsedTime() > SomePredefinedThresholdTime)
{
Console.WriteLine(diagnostics.ToString());
}
}

services.AddCosmosCache((CosmosCacheOptions cacheOptions) =>
{
cacheOptions.DiagnosticsHandler = captureDiagnostics;
/* other options */
});
```

# Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Expand Down
9 changes: 5 additions & 4 deletions src/CosmosCacheOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ public class CosmosCacheOptions : IOptions<CosmosCacheOptions>
/// }
/// }
///
/// CosmosCacheOptions options = new CosmosCacheOptions(){
/// /* Other options */,
/// DiagnosticsHandler = captureDiagnostics
/// };
/// services.AddCosmosCache((CosmosCacheOptions cacheOptions) =>
/// {
/// cacheOptions.DiagnosticsHandler = captureDiagnostics;
/// /* other options */
/// });
/// ]]>
/// </code>
/// </example>
Expand Down

0 comments on commit a37e985

Please sign in to comment.