Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Internal] OpenTelemetry: Adds diagnostics for network level requests #3718

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ClientOfficialVersion>3.32.3</ClientOfficialVersion>
<ClientPreviewVersion>3.32.3</ClientPreviewVersion>
<ClientPreviewSuffixVersion>preview</ClientPreviewSuffixVersion>
<DirectVersion>3.30.4</DirectVersion>
<DirectVersion>3.30.6</DirectVersion>
<EncryptionOfficialVersion>2.0.1</EncryptionOfficialVersion>
<EncryptionPreviewVersion>2.0.1</EncryptionPreviewVersion>
<EncryptionPreviewSuffixVersion>preview</EncryptionPreviewSuffixVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class BenchmarkConfig
public bool EnableTelemetry { get; set; }

[Option(Required = false, HelpText = "Enable Distributed Tracing")]
public bool EnableDistributedTracing { get; set; }
public bool EnableDistributedTracing { get; set; } = true;

[Option(Required = false, HelpText = "Client Telemetry Schedule in Seconds")]
public int TelemetryScheduleInSec { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="MathNet.Numerics" Version="4.15.0" />
<PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="*" />
<PackageReference Include="OpenTelemetry" Version="1.3.2" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.3.2" />
</ItemGroup>

<ItemGroup Condition=" '$(ProjectRef)' != 'True' ">
Expand Down
128 changes: 68 additions & 60 deletions Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace CosmosBenchmark
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos;
using Newtonsoft.Json.Linq;
using OpenTelemetry;
using OpenTelemetry.Trace;

/// <summary>
/// This sample demonstrates how to achieve high performance writes using Azure Comsos DB.
Expand Down Expand Up @@ -87,84 +89,90 @@ private static async Task AddAzureInfoToRunSummary()
/// <returns>a Task object.</returns>
private async Task<RunSummary> ExecuteAsync(BenchmarkConfig config)
{
// V3 SDK client initialization
using (CosmosClient cosmosClient = config.CreateCosmosClient(config.Key))
using (TracerProvider provider = Sdk.CreateTracerProviderBuilder()
.AddConsoleExporter()
.AddSource($"Azure.Cosmos.Request")
.Build())
{
Microsoft.Azure.Cosmos.Database database = cosmosClient.GetDatabase(config.Database);
if (config.CleanupOnStart)
// V3 SDK client initialization
using (CosmosClient cosmosClient = config.CreateCosmosClient(config.Key))
{
await database.DeleteStreamAsync();
}

ContainerResponse containerResponse = await Program.CreatePartitionedContainerAsync(config, cosmosClient);
Container container = containerResponse;
Microsoft.Azure.Cosmos.Database database = cosmosClient.GetDatabase(config.Database);
if (config.CleanupOnStart)
{
await database.DeleteStreamAsync();
}

int? currentContainerThroughput = await container.ReadThroughputAsync();
ContainerResponse containerResponse = await Program.CreatePartitionedContainerAsync(config, cosmosClient);
Container container = containerResponse;

if (!currentContainerThroughput.HasValue)
{
// Container throughput is not configured. It is shared database throughput
ThroughputResponse throughputResponse = await database.ReadThroughputAsync(requestOptions: null);
throw new InvalidOperationException($"Using database {config.Database} with {throughputResponse.Resource.Throughput} RU/s. " +
$"Container {config.Container} must have a configured throughput.");
}
int? currentContainerThroughput = await container.ReadThroughputAsync();

Console.WriteLine($"Using container {config.Container} with {currentContainerThroughput} RU/s");
int taskCount = config.GetTaskCount(currentContainerThroughput.Value);
if (!currentContainerThroughput.HasValue)
{
// Container throughput is not configured. It is shared database throughput
ThroughputResponse throughputResponse = await database.ReadThroughputAsync(requestOptions: null);
throw new InvalidOperationException($"Using database {config.Database} with {throughputResponse.Resource.Throughput} RU/s. " +
$"Container {config.Container} must have a configured throughput.");
}

Console.WriteLine("Starting Inserts with {0} tasks", taskCount);
Console.WriteLine();
Console.WriteLine($"Using container {config.Container} with {currentContainerThroughput} RU/s");
int taskCount = config.GetTaskCount(currentContainerThroughput.Value);

string partitionKeyPath = containerResponse.Resource.PartitionKeyPath;
int opsPerTask = config.ItemCount / taskCount;
Console.WriteLine("Starting Inserts with {0} tasks", taskCount);
Console.WriteLine();

// TBD: 2 clients SxS some overhead
RunSummary runSummary;
string partitionKeyPath = containerResponse.Resource.PartitionKeyPath;
int opsPerTask = config.ItemCount / taskCount;

// V2 SDK client initialization
using (Microsoft.Azure.Documents.Client.DocumentClient documentClient = config.CreateDocumentClient(config.Key))
{
Func<IBenchmarkOperation> benchmarkOperationFactory = this.GetBenchmarkFactory(
config,
partitionKeyPath,
cosmosClient,
documentClient);
// TBD: 2 clients SxS some overhead
RunSummary runSummary;

if (config.DisableCoreSdkLogging)
// V2 SDK client initialization
using (Microsoft.Azure.Documents.Client.DocumentClient documentClient = config.CreateDocumentClient(config.Key))
{
// Do it after client initialization (HACK)
Program.ClearCoreSdkListeners();
Func<IBenchmarkOperation> benchmarkOperationFactory = this.GetBenchmarkFactory(
config,
partitionKeyPath,
cosmosClient,
documentClient);

if (config.DisableCoreSdkLogging)
{
// Do it after client initialization (HACK)
Program.ClearCoreSdkListeners();
}

IExecutionStrategy execution = IExecutionStrategy.StartNew(benchmarkOperationFactory);
runSummary = await execution.ExecuteAsync(config, taskCount, opsPerTask, 0.01);
}

IExecutionStrategy execution = IExecutionStrategy.StartNew(benchmarkOperationFactory);
runSummary = await execution.ExecuteAsync(config, taskCount, opsPerTask, 0.01);
}
if (config.CleanupOnFinish)
{
Console.WriteLine($"Deleting Database {config.Database}");
await database.DeleteStreamAsync();
}

if (config.CleanupOnFinish)
{
Console.WriteLine($"Deleting Database {config.Database}");
await database.DeleteStreamAsync();
}
string consistencyLevel = config.ConsistencyLevel;
if (string.IsNullOrWhiteSpace(consistencyLevel))
{
AccountProperties accountProperties = await cosmosClient.ReadAccountAsync();
consistencyLevel = accountProperties.Consistency.DefaultConsistencyLevel.ToString();
}
runSummary.ConsistencyLevel = consistencyLevel;

string consistencyLevel = config.ConsistencyLevel;
if (string.IsNullOrWhiteSpace(consistencyLevel))
{
AccountProperties accountProperties = await cosmosClient.ReadAccountAsync();
consistencyLevel = accountProperties.Consistency.DefaultConsistencyLevel.ToString();
}
runSummary.ConsistencyLevel = consistencyLevel;

if (config.PublishResults)
{
runSummary.Diagnostics = CosmosDiagnosticsLogger.GetDiagnostics();
await this.PublishResults(
config,
runSummary,
cosmosClient);
}

if (config.PublishResults)
{
runSummary.Diagnostics = CosmosDiagnosticsLogger.GetDiagnostics();
await this.PublishResults(
config,
runSummary,
cosmosClient);
return runSummary;
}

return runSummary;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Microsoft.Azure.Cosmos
{
using System;
using System.Runtime.Serialization;
using global::Azure.Core.Pipeline;
using global::Azure.Core;
using Microsoft.Azure.Cosmos.Telemetry;
using Microsoft.Azure.Cosmos.Telemetry.Diagnostics;

Expand Down
17 changes: 13 additions & 4 deletions Microsoft.Azure.Cosmos/src/DocumentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ internal partial class DocumentClient : IDisposable, IAuthorizationTokenProvider
//RemoteCertificateValidationCallback
internal RemoteCertificateValidationCallback remoteCertificateValidationCallback;

//Distributed Tracing Flag
internal bool isDistributedTracingEnabled;

//SessionContainer.
internal ISessionContainer sessionContainer;

Expand Down Expand Up @@ -426,6 +429,7 @@ internal DocumentClient(Uri serviceEndpoint,
/// <param name="isLocalQuorumConsistency">Flag to allow Quorum Read with Eventual Consistency Account</param>
/// <param name="cosmosClientId"></param>
/// <param name="remoteCertificateValidationCallback">This delegate responsible for validating the third party certificate. </param>
/// <param name="isDistributedTracingEnabled">This is distributed tracing flag</param>
/// <remarks>
/// The service endpoint can be obtained from the Azure Management Portal.
/// If you are connecting using one of the Master Keys, these can be obtained along with the endpoint from the Azure Management Portal
Expand All @@ -452,7 +456,8 @@ internal DocumentClient(Uri serviceEndpoint,
IStoreClientFactory storeClientFactory = null,
bool isLocalQuorumConsistency = false,
string cosmosClientId = null,
RemoteCertificateValidationCallback remoteCertificateValidationCallback = null)
RemoteCertificateValidationCallback remoteCertificateValidationCallback = null,
bool isDistributedTracingEnabled = false)
{
if (sendingRequestEventArgs != null)
{
Expand Down Expand Up @@ -485,7 +490,8 @@ internal DocumentClient(Uri serviceEndpoint,
enableCpuMonitor: enableCpuMonitor,
storeClientFactory: storeClientFactory,
cosmosClientId: cosmosClientId,
remoteCertificateValidationCallback: remoteCertificateValidationCallback);
remoteCertificateValidationCallback: remoteCertificateValidationCallback,
isDistributedTracingEnabled: isDistributedTracingEnabled);
}

/// <summary>
Expand Down Expand Up @@ -668,7 +674,8 @@ internal virtual void Initialize(Uri serviceEndpoint,
IStoreClientFactory storeClientFactory = null,
TokenCredential tokenCredential = null,
string cosmosClientId = null,
RemoteCertificateValidationCallback remoteCertificateValidationCallback = null)
RemoteCertificateValidationCallback remoteCertificateValidationCallback = null,
bool isDistributedTracingEnabled = false)
{
if (serviceEndpoint == null)
{
Expand All @@ -677,6 +684,7 @@ internal virtual void Initialize(Uri serviceEndpoint,

this.clientId = cosmosClientId;
this.remoteCertificateValidationCallback = remoteCertificateValidationCallback;
this.isDistributedTracingEnabled = isDistributedTracingEnabled;

this.queryPartitionProvider = new AsyncLazy<QueryPartitionProvider>(async () =>
{
Expand Down Expand Up @@ -6658,7 +6666,8 @@ private void InitializeDirectConnectivity(IStoreClientFactory storeClientFactory
enableTcpConnectionEndpointRediscovery: this.ConnectionPolicy.EnableTcpConnectionEndpointRediscovery,
addressResolver: this.AddressResolver,
rntbdMaxConcurrentOpeningConnectionCount: this.rntbdMaxConcurrentOpeningConnectionCount,
remoteCertificateValidationCallback: this.remoteCertificateValidationCallback );
remoteCertificateValidationCallback: this.remoteCertificateValidationCallback,
isDistributedTracingEnabled: this.isDistributedTracingEnabled);

if (this.transportClientHandlerFactory != null)
{
Expand Down

This file was deleted.

Loading