diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/README.md b/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/README.md new file mode 100644 index 0000000000..14323fe244 --- /dev/null +++ b/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/README.md @@ -0,0 +1,56 @@ +# Integrate ApplicationInsights with Cosmos DB + +This project provides a demo showcasing the usage of the integrating ApplicationInsights with Cosmos DB. The goal is to trace requests. + +## Prerequisites + +- Azure Cosmos DB NoSQL Account + - Create a DataBase and Container +- Azure ApplicationInsights Account + - Create a Azure ApplicationInsights account + +## Run + +Before running the application you need fill out `CosmosDBEndPointUrl`, `CosmosDBAuthorizationKey` and `ApplicationInsightsConnectionString` params in the [AppSettings.json](AppSettings.json) + +```PowerShell +dotnet run +``` + +## Getting Started + +### Configure Application Insights Telemetry + +```C# +IServiceCollection services = new ServiceCollection(); +services.AddApplicationInsightsTelemetryWorkerService((ApplicationInsightsServiceOptions options) => options.ConnectionString = aiConnectionString); + +IServiceProvider serviceProvider = services.BuildServiceProvider(); +_telemetryClient = serviceProvider.GetRequiredService(); +``` + +### Prepare Client, Database and Container + +```C# +using (CosmosClient client = new CosmosClient(endpoint, authKey, options)) +{ + Console.WriteLine($"Getting container reference for {containerName}."); + + ContainerProperties properties = new ContainerProperties(containerName, partitionKeyPath: "/id"); + + await client.CreateDatabaseIfNotExistsAsync(databaseName); + Container container = await client.GetDatabase(databaseName).CreateContainerIfNotExistsAsync(properties); + + await Program.RunCrudDemo(container); +} +``` + +### Flush telemetry data + +```C# +_telemetryClient?.Flush(); +``` + +### Check captured telemetry in Application Insights + +![Alt text](image.png) diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/image.png b/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/image.png new file mode 100644 index 0000000000..be35ae7f0d Binary files /dev/null and b/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/image.png differ diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/AzureFunctions/README.md b/Microsoft.Azure.Cosmos.Samples/Usage/AzureFunctions/README.md new file mode 100644 index 0000000000..2c3014e2cf --- /dev/null +++ b/Microsoft.Azure.Cosmos.Samples/Usage/AzureFunctions/README.md @@ -0,0 +1,34 @@ +# Cosmos client with Azure Function + +This sample demonstrates how to maintain a Cosmos client instance following Singleton pattern and reuse the instance across Azure Function executions. + +## Prerequisites + +- Azure Cosmos DB NoSQL Account +- Create a Database and Container +- Microsoft.Azure.Cosmos NuGet [package](http://www.nuget.org/packages/Microsoft.Azure.Cosmos/) + +## Run + +Before running the application you need fill out `EndpointUrl` and `AuthorizationKey` params in the [AppSettings.json](../appSettings.json) + +```PowerShell +dotnet run +``` + +## Getting Started + +### Create Database and Container + +### Send post request + +```bash +curl --location 'http://localhost:7071/api/CosmosClient' \ +--header 'Content-Type: application/json' \ +--data '{ + "id": "id", + "name" : "name", + "description" : "description", + "isComplete": false +}' +``` diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/BulkExecutorMigration/README.md b/Microsoft.Azure.Cosmos.Samples/Usage/BulkExecutorMigration/README.md new file mode 100644 index 0000000000..a1d8c574e1 --- /dev/null +++ b/Microsoft.Azure.Cosmos.Samples/Usage/BulkExecutorMigration/README.md @@ -0,0 +1,41 @@ +# Cosmos Bulk Executor migration + +This sample demonstrates how to migrate from Bulk Executor Library to V3 SDK with Bulk support. + +## Prerequisites + +- Azure Cosmos DB NoSQL Account + - Create a DataBase and Container +- Microsoft.Azure.Cosmos NuGet [package](http://www.nuget.org/packages/Microsoft.Azure.Cosmos/) + +## Run + +Before running the application you need fill out `EndPointUrl` and `AuthorizationKey` params in the [AppSettings.json](../appSettings.json) + +```PowerShell +dotnet run +``` + +## Getting Started + +### Create Database and Container + +### Run and you will see the result + +```PowerShell +The demo will create a container, press any key to continue. +Running bulk operations demo for container bulkMigration with a Bulk enabled CosmosClient. +Bulk create operation finished in 00:00:00.5426833 +Consumed 5520.0000000001 RUs in total +Created 1000 documents +Failed 0 documents +Bulk update operation finished in 00:00:00.4598077 +Consumed 10290.000000000151 RUs in total +Updated 1000 documents +Failed 0 documents +Bulk update operation finished in 00:00:00.3676135 +Consumed 5520.0000000001 RUs in total +Deleted 1000 documents +Failed 0 documents +End of demo, press any key to exit. +``` diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/BulkSupport/README.md b/Microsoft.Azure.Cosmos.Samples/Usage/BulkSupport/README.md new file mode 100644 index 0000000000..334208f24d --- /dev/null +++ b/Microsoft.Azure.Cosmos.Samples/Usage/BulkSupport/README.md @@ -0,0 +1,22 @@ +# Cosmos Bulk support + +This sample demonstrates the basic usage of the CosmosClient bulk mode by performing a high volume of operations. + +## Prerequisites + +- Azure Cosmos DB NoSQL Account + - Create a DataBase and Container +- Microsoft.Azure.Cosmos NuGet [package](http://www.nuget.org/packages/Microsoft.Azure.Cosmos/) +- Async main requires c# 7.1 which is set in the csproj with the LangVersion attribute + +## Run + +Before running the application you need fill out `EndPointUrl` and `AuthorizationKey` params in the [AppSettings.json](../appSettings.json) + +```PowerShell +dotnet run +``` + +## Getting Started + +### Create Database and Container diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/ContainerManagement/README.md b/Microsoft.Azure.Cosmos.Samples/Usage/ContainerManagement/README.md new file mode 100644 index 0000000000..b32f564234 --- /dev/null +++ b/Microsoft.Azure.Cosmos.Samples/Usage/ContainerManagement/README.md @@ -0,0 +1,27 @@ +# Cosmos Bulk support + +This sample demonstrates the example of the following basic usages + +- Create a container with fixed throughput +- Create a container with autoscale throughput +- Create a container with custom index policy (consistent indexing) +- Create a container with ttl expiration +- Change throughtput for an existing container +- List all existing containers in database + +## Prerequisites + +- Azure Cosmos DB NoSQL Account + - Create a DataBase +- Microsoft.Azure.Cosmos NuGet [package](http://www.nuget.org/packages/Microsoft.Azure.Cosmos/) +- Async main requires c# 7.1 which is set in the csproj with the LangVersion attribute + +## Getting Started + +### Run + +Before running the application you need fill out `EndPointUrl` and `AuthorizationKey` params in the [AppSettings.json](../appSettings.json) + +```PowerShell +dotnet run +``` diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/README.md b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/README.md new file mode 100644 index 0000000000..73677fc1c8 --- /dev/null +++ b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/README.md @@ -0,0 +1,27 @@ +# Cosmos Bulk support + +This sample demonstrates the example of implementig custom diagnostic and event listener + +## Description + +This listener can cover following aspects: + +1. Write its own monitoring library with the custom implementation of aggregation or whatever you want to do with this data. +2. Support an APM tool which is not open telemetry compliant. + +## Prerequisites + +- Azure Cosmos DB NoSQL Account + - Create a DataBase +- Microsoft.Azure.Cosmos NuGet [package](http://www.nuget.org/packages/Microsoft.Azure.Cosmos/) +- Async main requires c# 7.1 which is set in the csproj with the LangVersion attribute + +## Getting Started + +### Run + +Before running the application you need fill out `EndPointUrl` and `AuthorizationKey` params in the [AppSettings.json](../appSettings.json) + +```PowerShell +dotnet run +``` diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/CustomSerialization/README.md b/Microsoft.Azure.Cosmos.Samples/Usage/CustomSerialization/README.md new file mode 100644 index 0000000000..f01fa4ae3e --- /dev/null +++ b/Microsoft.Azure.Cosmos.Samples/Usage/CustomSerialization/README.md @@ -0,0 +1,38 @@ +# Cosmos Bulk support + +This sample demonstrates an example of configuring custom serialization + +## Description + +This example covers several options leveraging CosmosClientOptions.CosmosSerializationOptions: + +- IgnoreNullValues +- Disable indented +- CamelCase property naming policy + +## Prerequisites + +- Azure Cosmos DB NoSQL Account + - Create a DataBase +- Microsoft.Azure.Cosmos NuGet [package](http://www.nuget.org/packages/Microsoft.Azure.Cosmos/) +- Async main requires c# 7.1 which is set in the csproj with the LangVersion attribute + +## Getting Started + +### Run + +Before running the application you need fill out `EndPointUrl` and `AuthorizationKey` params in the [AppSettings.json](../appSettings.json) + +```PowerShell +dotnet run +``` + +```json + { + "id": "CapitalId", + "pk": "12345", + "_rid": "+RVXAM52ojQBAAAAAAAAAA==", + "_etag": "\"00000000-0000-0000-e59b-6f7166ef01d9\"", + "_attachments": "attachments\/", + } +```