Skip to content

Commit 507ce50

Browse files
authored
update cosmos integration docs (#1698)
1 parent eaabcc8 commit 507ce50

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

docs/database/azure-cosmos-db-integration.md

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ For more information, see [dotnet add package](/dotnet/core/tools/dotnet-add-pac
3535
In the _:::no-loc text="Program.cs":::_ file of your client-consuming project, call the <xref:Microsoft.Extensions.Hosting.AspireMicrosoftAzureCosmosExtensions.AddAzureCosmosClient%2A> extension to register a <xref:Microsoft.Azure.Cosmos.CosmosClient?displayProperty=fullName> for use via the dependency injection container.
3636

3737
```csharp
38-
builder.AddAzureCosmosClient("cosmosdb");
38+
builder.AddAzureCosmosClient("cosmosConnectionName");
3939
```
4040

4141
You can then retrieve the `CosmosClient` instance using dependency injection. For example, to retrieve the client from a service:
@@ -51,7 +51,7 @@ For more information on using the <xref:Microsoft.Azure.Cosmos.CosmosClient>, se
5151

5252
## App host usage
5353

54-
To add Azure Cosmos DB hosting support to your <xref:Aspire.Hosting.IDistributedApplicationBuilder>, install the [Aspire.Hosting.Azure.CosmosDB](https://www.nuget.org/packages/Aspire.Hosting.Azure.CosmosDB) NuGet package in the [app host](xref:aspire/app-host) project.
54+
To add Azure Cosmos DB hosting support to your <xref:Aspire.Hosting.IDistributedApplicationBuilder>, install the [Aspire.Hosting.Azure.CosmosDB](https://www.nuget.org/packages/Aspire.Hosting.Azure.CosmosDB) NuGet package in the [app host](xref:aspire/app-host) project. This is helpful if you want Aspire to provision a new Azure Cosmos DB account for you, or if you want to use the Azure Cosmos DB emulator. If you want to use an Azure Cosmos DB account that is already provisioned, there's no need to add it to the app host project.
5555

5656
### [.NET CLI](#tab/dotnet-cli)
5757

@@ -73,8 +73,8 @@ In your app host project, register the .NET Aspire Azure Cosmos DB integration a
7373
```csharp
7474
var builder = DistributedApplication.CreateBuilder(args);
7575

76-
var cosmos = builder.AddAzureCosmosDB("cosmos");
77-
var cosmosdb = cosmos.AddDatabase("cosmosdb");
76+
var cosmos = builder.AddAzureCosmosDB("myNewCosmosAccountName");
77+
var cosmosdb = cosmos.AddDatabase("myCosmosDatabaseName");
7878

7979
var exampleProject = builder.AddProject<Projects.ExampleProject>()
8080
.WithReference(cosmosdb);
@@ -89,14 +89,14 @@ var exampleProject = builder.AddProject<Projects.ExampleProject>()
8989
9090
## Configuration
9191
92-
The .NET Aspire Azure Cosmos DB library provides multiple options to configure the Azure Cosmos DB connection based on the requirements and conventions of your project.
92+
The .NET Aspire Azure Cosmos DB library provides multiple options to configure the `CosmosClient` connection based on the requirements and conventions of your project.
9393
9494
### Use a connection string
9595
96-
When using a connection string from the `ConnectionStrings` configuration section, you can provide the name of the connection string when calling `builder.AddAzureCosmosDB`:
96+
When using a connection string from the `ConnectionStrings` configuration section, you can provide the name of the connection string when calling `builder.AddAzureCosmosClient`:
9797
9898
```csharp
99-
builder.AddAzureCosmosDB("cosmosConnectionName");
99+
builder.AddAzureCosmosClient("cosmosConnectionName");
100100
```
101101
102102
And then the connection string will be retrieved from the `ConnectionStrings` configuration section:
@@ -152,15 +152,15 @@ The .NET Aspire Azure Cosmos DB integration supports <xref:Microsoft.Extensions.
152152
You can also pass the `Action<MicrosoftAzureCosmosSettings >` delegate to set up some or all the options inline, for example to disable tracing from code:
153153

154154
```csharp
155-
builder.AddAzureCosmosDB(
155+
builder.AddAzureCosmosClient(
156156
"cosmosConnectionName",
157157
static settings => settings.DisableTracing = true);
158158
```
159159

160-
You can also set up the <xref:Microsoft.Azure.Cosmos.CosmosClientOptions?displayProperty=fullName> using the optional `Action<CosmosClientOptions> configureClientOptions` parameter of the `AddAzureCosmosDB` method. For example to set the <xref:Microsoft.Azure.Cosmos.CosmosClientOptions.ApplicationName?displayProperty=nameWithType> user-agent header suffix for all requests issues by this client:
160+
You can also set up the <xref:Microsoft.Azure.Cosmos.CosmosClientOptions?displayProperty=fullName> using the optional `Action<CosmosClientOptions> configureClientOptions` parameter of the `AddAzureCosmosClient` method. For example to set the <xref:Microsoft.Azure.Cosmos.CosmosClientOptions.ApplicationName?displayProperty=nameWithType> user-agent header suffix for all requests issues by this client:
161161

162162
```csharp
163-
builder.AddAzureCosmosDB(
163+
builder.AddAzureCosmosClient(
164164
"cosmosConnectionName",
165165
configureClientOptions:
166166
clientOptions => clientOptions.ApplicationName = "myapp");
@@ -178,12 +178,36 @@ The .NET Aspire Azure Cosmos DB integration uses the following log categories:
178178

179179
- Azure-Cosmos-Operation-Request-Diagnostics
180180

181+
In addition to getting Azure Cosmos DB request diagnostics for failed requests, you can configure latency thresholds to determine which successful Azure Cosmos DB request diagnostics will be logged. The default values are 100 ms for point operations and 500 ms for non point operations.
182+
183+
```csharp
184+
builder.AddAzureCosmosClient(
185+
"cosmosConnectionName",
186+
configureClientOptions:
187+
clientOptions => {
188+
clientOptions.CosmosClientTelemetryOptions = new()
189+
{
190+
CosmosThresholdOptions = new()
191+
{
192+
PointOperationLatencyThreshold = TimeSpan.FromMilliseconds(50),
193+
NonPointOperationLatencyThreshold = TimeSpan.FromMilliseconds(300)
194+
}
195+
};
196+
});
197+
```
198+
181199
### Tracing
182200

183201
The .NET Aspire Azure Cosmos DB integration will emit the following tracing activities using OpenTelemetry:
184202

185203
- Azure.Cosmos.Operation
186204

205+
Azure Cosmos DB tracing is currently in preview, so you must set the experimental switch to ensure traces are emitted. [Learn more about tracing in Azure Cosmos DB.](/azure/cosmos-db/nosql/sdk-observability#trace-attributes)
206+
207+
```csharp
208+
AppContext.SetSwitch("Azure.Experimental.EnableActivitySource", true);
209+
```
210+
187211
### Metrics
188212

189213
The .NET Aspire Azure Cosmos DB integration currently doesn't support metrics by default due to limitations with the Azure SDK.

0 commit comments

Comments
 (0)