bulkwith otel
This commit is contained in:
Родитель
c2043ae85c
Коммит
2d5475fd78
|
@ -1,13 +1,20 @@
|
|||
{
|
||||
"EndPointUrl": "https://localhost:8081",
|
||||
"AuthorizationKey": "Super secret key",
|
||||
"EndPointUrl": "https://sourabhcosmosdbaccount.documents.azure.com:443/",
|
||||
"AuthorizationKey": "",
|
||||
"DatabaseName": "samples",
|
||||
"ContainerName": "bulk-support",
|
||||
"CollectionThroughput": "100000",
|
||||
"ShouldCleanupOnStart": "false",
|
||||
"ShouldCleanupOnStart": "true",
|
||||
"ShouldCleanupOnFinish": "false",
|
||||
"ItemSize": "400",
|
||||
"ItemsToCreate": "10000",
|
||||
"RuntimeInSeconds": "300",
|
||||
"numWorkers": "1"
|
||||
"numWorkers": "1",
|
||||
"Logging": {
|
||||
"OpenTelemetry": {
|
||||
"LogLevel": {
|
||||
"Azure.Cosmos.Operation.Request.Diagnostics": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,10 +9,14 @@
|
|||
<ServerGarbageCollection>true</ServerGarbageCollection>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
|
||||
<PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.3.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.7.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Azure.Cosmos" Version="*" />
|
||||
<PackageReference Include="OpenTelemetry" Version="1.9.0" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Shared\Shared.csproj" />
|
||||
|
|
|
@ -10,10 +10,16 @@
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Azure.Monitor.OpenTelemetry.Exporter;
|
||||
using Microsoft.Azure.Cosmos;
|
||||
using Microsoft.Extensions.Azure;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OpenTelemetry;
|
||||
using OpenTelemetry.Resources;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
// Prerequisites -
|
||||
|
@ -38,19 +44,65 @@
|
|||
private static bool shouldCleanupOnFinish;
|
||||
private static int numWorkers;
|
||||
|
||||
private static TracerProvider? _traceProvider;
|
||||
|
||||
// Async main requires c# 7.1 which is set in the csproj with the LangVersion attribute
|
||||
// <Main>
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Intialize container or create a new container.
|
||||
Container container = await Program.Initialize();
|
||||
IConfigurationRoot configuration = new ConfigurationBuilder()
|
||||
.AddJsonFile("AppSettings.json")
|
||||
.Build();
|
||||
|
||||
// Running bulk ingestion on a container.
|
||||
await Program.CreateItemsConcurrentlyAsync(container);
|
||||
// <SetUpOpenTelemetry>
|
||||
ResourceBuilder resource = ResourceBuilder.CreateDefault().AddService(
|
||||
serviceName: "serviceName",
|
||||
serviceVersion: "1.0.0");
|
||||
|
||||
await Program.RemovePropertyFromAllItemsAsync(container);
|
||||
// Set up logging to forward logs to chosen exporter
|
||||
using ILoggerFactory loggerFactory
|
||||
= LoggerFactory.Create(builder => builder
|
||||
.AddConfiguration(configuration.GetSection("Logging"))
|
||||
.AddOpenTelemetry(options =>
|
||||
{
|
||||
options.IncludeFormattedMessage = true;
|
||||
options.SetResourceBuilder(resource);
|
||||
options.AddAzureMonitorLogExporter(o => o.ConnectionString = ""); // Set up exporter of your choice
|
||||
}));
|
||||
/*.AddFilter(level => level == LogLevel.Error) // Filter is irrespective of event type or event name*/
|
||||
|
||||
AzureEventSourceLogForwarder logforwader = new AzureEventSourceLogForwarder(loggerFactory);
|
||||
logforwader.Start();
|
||||
|
||||
// Configure OpenTelemetry trace provider
|
||||
AppContext.SetSwitch("Azure.Experimental.EnableActivitySource", true);
|
||||
_traceProvider = Sdk.CreateTracerProviderBuilder()
|
||||
.AddSource("Azure.Cosmos.Operation", // Cosmos DB source for operation level telemetry
|
||||
"Sample.Application")
|
||||
.AddAzureMonitorTraceExporter(o => o.ConnectionString = "") //"" Set up exporter of your choice
|
||||
.AddHttpClientInstrumentation() // Added to capture HTTP telemetry
|
||||
.SetResourceBuilder(resource)
|
||||
.Build();
|
||||
// </SetUpOpenTelemetry>
|
||||
|
||||
ActivitySource source = new ActivitySource("Sample.Application");
|
||||
using (_ = source.StartActivity(".Net SDK : Azure Monitor : Open Telemetry Sample")) // Application level activity to track the entire execution of the application
|
||||
{
|
||||
using (_ = source.StartActivity("GATEWAY MODE")) // Activity to track the execution of the gateway mode
|
||||
{
|
||||
// Intialize container or create a new container.
|
||||
Container container = await Program.Initialize();
|
||||
|
||||
// Running bulk ingestion on a container.
|
||||
await Program.CreateItemsConcurrentlyAsync(container);
|
||||
|
||||
await Program.RemovePropertyFromAllItemsAsync(container);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
catch (CosmosException cre)
|
||||
{
|
||||
|
@ -67,6 +119,7 @@
|
|||
{
|
||||
await Program.CleanupAsync();
|
||||
}
|
||||
_traceProvider.Dispose();
|
||||
client.Dispose();
|
||||
|
||||
Console.WriteLine("End of demo, press any key to exit.");
|
||||
|
@ -300,7 +353,15 @@
|
|||
string authKey)
|
||||
{
|
||||
// </Initialization>
|
||||
return new CosmosClient(endpoint, authKey, new CosmosClientOptions() { AllowBulkExecution = true });
|
||||
return new CosmosClient(endpoint, authKey, new CosmosClientOptions()
|
||||
{
|
||||
ConnectionMode = ConnectionMode.Gateway,
|
||||
AllowBulkExecution = true,
|
||||
CosmosClientTelemetryOptions = new CosmosClientTelemetryOptions()
|
||||
{
|
||||
DisableDistributedTracing = false
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// </Initialization>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29123.88
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.10.35027.167
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Cosmos", "Microsoft.Azure.Cosmos\src\Microsoft.Azure.Cosmos.csproj", "{36F6F6A8-CEC8-4261-9948-903495BC3C25}"
|
||||
EndProject
|
||||
|
@ -164,6 +164,18 @@ Global
|
|||
{B5B3631D-AC2F-4257-855D-D6FE12F20B60}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B5B3631D-AC2F-4257-855D-D6FE12F20B60}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{B5B3631D-AC2F-4257-855D-D6FE12F20B60}.Release|x64.Build.0 = Release|Any CPU
|
||||
{021DDC27-02EF-42C4-9A9E-AA600833C2EE}.Cover|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{021DDC27-02EF-42C4-9A9E-AA600833C2EE}.Cover|Any CPU.Build.0 = Debug|Any CPU
|
||||
{021DDC27-02EF-42C4-9A9E-AA600833C2EE}.Cover|x64.ActiveCfg = Debug|Any CPU
|
||||
{021DDC27-02EF-42C4-9A9E-AA600833C2EE}.Cover|x64.Build.0 = Debug|Any CPU
|
||||
{021DDC27-02EF-42C4-9A9E-AA600833C2EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{021DDC27-02EF-42C4-9A9E-AA600833C2EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{021DDC27-02EF-42C4-9A9E-AA600833C2EE}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{021DDC27-02EF-42C4-9A9E-AA600833C2EE}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{021DDC27-02EF-42C4-9A9E-AA600833C2EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{021DDC27-02EF-42C4-9A9E-AA600833C2EE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{021DDC27-02EF-42C4-9A9E-AA600833C2EE}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{021DDC27-02EF-42C4-9A9E-AA600833C2EE}.Release|x64.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -227,17 +227,17 @@ namespace Microsoft.Azure.Cosmos.Telemetry
|
|||
OperationType operationType
|
||||
= (this.response == null || this.response?.OperationType == OperationType.Invalid) ? this.operationType : this.response.OperationType;
|
||||
|
||||
string operationName = Enum.GetName(typeof(OperationType), operationType);
|
||||
this.scope.AddAttribute(OpenTelemetryAttributeKeys.OperationType, operationName);
|
||||
string operationTypeString = Enum.GetName(typeof(OperationType), operationType);
|
||||
this.scope.AddAttribute(OpenTelemetryAttributeKeys.OperationType, operationTypeString);
|
||||
|
||||
if (this.response != null)
|
||||
{
|
||||
if (this.response.BatchOperationName != null)
|
||||
{
|
||||
string batchOpsName = Enum.GetName(typeof(OperationType), this.response.BatchOperationName);
|
||||
operationName = $"{operationName}.{batchOpsName}";
|
||||
operationTypeString = $"{operationTypeString}.{batchOpsName}";
|
||||
}
|
||||
this.scope.AddAttribute(OpenTelemetryAttributeKeys.OperationType, operationName);
|
||||
this.scope.AddAttribute(OpenTelemetryAttributeKeys.OperationType, operationTypeString);
|
||||
|
||||
if (this.response.BatchSize is not null)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче