From 705d0c6e878d1afa9fae9ff1e25b5871db3b3d55 Mon Sep 17 00:00:00 2001 From: Sourabh Jain Date: Mon, 4 Sep 2023 16:38:10 +0530 Subject: [PATCH] public API changes --- .../Tools/Benchmark/BenchmarkConfig.cs | 12 ++-- .../Tools/CTL/CTLConfig.cs | 6 +- .../Tools/CTL/Program.cs | 7 +-- .../src/ConnectionPolicy.cs | 22 +++----- .../src/CosmosClientOptions.cs | 10 +++- .../src/CosmosClientTelemetryOptions.cs | 28 +++++++--- .../src/Fluent/CosmosClientBuilder.cs | 9 ++- .../Filters/DiagnosticsFilterHelper.cs | 1 + .../src/Telemetry/TelemetryToServiceHelper.cs | 4 +- ...aselineTests.TypedPointOperationsAsync.xml | 8 --- .../ClientTelemetryTestsBase.cs | 4 +- .../DistributedTracingOTelTests.cs | 24 ++++---- .../SynchronizationContextTests.cs | 2 +- .../Mocks/MockDocumentClient.cs | 6 +- .../Contracts/DotNetPreviewSDKAPI.json | 55 +++++++++++++++++++ .../Contracts/DotNetSDKAPI.json | 43 --------------- .../CosmosClientOptionsUnitTests.cs | 11 ++++ .../CosmosClientTests.cs | 52 ++---------------- .../Utils/MockCosmosUtil.cs | 5 +- 19 files changed, 153 insertions(+), 156 deletions(-) diff --git a/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/BenchmarkConfig.cs b/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/BenchmarkConfig.cs index dccac3b9eb..0fde6a8926 100644 --- a/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/BenchmarkConfig.cs +++ b/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/BenchmarkConfig.cs @@ -103,8 +103,8 @@ public class BenchmarkConfig [Option(Required = false, HelpText = "Disable core SDK logging")] public bool DisableCoreSdkLogging { get; set; } - [Option(Required = false, HelpText = "Enable Distributed Tracing")] - public bool EnableDistributedTracing { get; set; } + [Option(Required = false, HelpText = "Disable Distributed Tracing feature from source")] + public bool DisableDistributedTracing { get; set; } = false; [Option(Required = false, HelpText = "Client Telemetry Schedule in Seconds")] public int TelemetryScheduleInSec { get; set; } @@ -138,8 +138,8 @@ public class BenchmarkConfig [Option(Required = false, HelpText = "Application Insights connection string")] public string AppInsightsConnectionString { get; set; } - [Option(Required = false, HelpText = "Enable Client Telemetry Feature in SDK. Make sure you enable it from the portal also.")] - public bool EnableClientTelemetry { get; set; } = true; + [Option(Required = false, HelpText = "Disable Client Telemetry Feature in SDK. Make sure you enable it from the portal also.")] + public bool DisableClientTelemetry { get; set; } = false; internal int GetTaskCount(int containerThroughput) { @@ -222,8 +222,8 @@ internal Microsoft.Azure.Cosmos.CosmosClient CreateCosmosClient(string accountKe MaxTcpConnectionsPerEndpoint = this.MaxTcpConnectionsPerEndpoint, CosmosClientTelemetryOptions = new Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions() { - EnableSendingMetricsToService = this.EnableClientTelemetry, - DisableDistributedTracing = !this.EnableDistributedTracing + DisableSendingMetricsToService = this.DisableClientTelemetry, + DisableDistributedTracing = this.DisableDistributedTracing } }; diff --git a/Microsoft.Azure.Cosmos.Samples/Tools/CTL/CTLConfig.cs b/Microsoft.Azure.Cosmos.Samples/Tools/CTL/CTLConfig.cs index 022a22b124..e1888de0f9 100644 --- a/Microsoft.Azure.Cosmos.Samples/Tools/CTL/CTLConfig.cs +++ b/Microsoft.Azure.Cosmos.Samples/Tools/CTL/CTLConfig.cs @@ -103,8 +103,8 @@ public string DiagnosticsThresholdDuration [Option("ctl_reservoir_sample_size", Required = false, HelpText = "The reservoir sample size.")] public int ReservoirSampleSize { get; set; } = 1028; - [Option("ctl_enable_client_telemetry", Required = false, HelpText = "Enable Client Telemetry Feature in SDK. Make sure you enable it from the portal also.")] - public bool EnableClientTelemetry { get; set; } = true; + [Option("ctl_disable_client_telemetry", Required = false, HelpText = "Disable Client Telemetry Feature in SDK. Make sure you enable it from the portal also.")] + public bool DisableClientTelemetry { get; set; } = false; internal TimeSpan RunningTimeDurationAsTimespan { get; private set; } = TimeSpan.FromHours(10); internal TimeSpan DiagnosticsThresholdDurationAsTimespan { get; private set; } = TimeSpan.FromSeconds(60); @@ -132,7 +132,7 @@ internal CosmosClient CreateCosmosClient() ApplicationName = CTLConfig.UserAgentSuffix, CosmosClientTelemetryOptions = new CosmosClientTelemetryOptions() { - EnableSendingMetricsToService = true, + DisableSendingMetricsToService = this.DisableClientTelemetry, } }; diff --git a/Microsoft.Azure.Cosmos.Samples/Tools/CTL/Program.cs b/Microsoft.Azure.Cosmos.Samples/Tools/CTL/Program.cs index 82da48016f..1cb7ff8367 100644 --- a/Microsoft.Azure.Cosmos.Samples/Tools/CTL/Program.cs +++ b/Microsoft.Azure.Cosmos.Samples/Tools/CTL/Program.cs @@ -14,7 +14,6 @@ namespace CosmosCTL using App.Metrics.Gauge; using Microsoft.Azure.Cosmos; using Microsoft.Extensions.Logging; - using Microsoft.Azure.Cosmos.Telemetry; public sealed class Program { @@ -52,10 +51,8 @@ await scenario.InitializeAsync( logger.LogInformation("Initialization completed."); - if(client.ClientOptions.CosmosClientTelemetryOptions.EnableSendingMetricsToService) { - logger.LogInformation("Telemetry is enabled for CTL."); - } else { - logger.LogInformation("Telemetry is disabled for CTL."); + if(client.ClientOptions.CosmosClientTelemetryOptions.DisableSendingMetricsToService) { + logger.LogInformation("Telemetry Feature flag is disabled for CTL."); } List tasks = new List diff --git a/Microsoft.Azure.Cosmos/src/ConnectionPolicy.cs b/Microsoft.Azure.Cosmos/src/ConnectionPolicy.cs index 40ac108451..508292d643 100644 --- a/Microsoft.Azure.Cosmos/src/ConnectionPolicy.cs +++ b/Microsoft.Azure.Cosmos/src/ConnectionPolicy.cs @@ -10,7 +10,6 @@ namespace Microsoft.Azure.Cosmos using System.Net.Http; using System.Net.Security; using System.Security.Cryptography.X509Certificates; - using Microsoft.Azure.Cosmos.Telemetry; using Microsoft.Azure.Documents; using Microsoft.Azure.Documents.Client; @@ -48,8 +47,9 @@ public ConnectionPolicy() this.MaxConnectionLimit = defaultMaxConcurrentConnectionLimit; this.RetryOptions = new RetryOptions(); this.EnableReadRequestsFallback = null; - this.EnableClientTelemetry = false; // by default feature flag is off this.ServerCertificateCustomValidationCallback = null; + + this.CosmosClientTelemetryOptions = new CosmosClientTelemetryOptions(); } /// @@ -211,15 +211,6 @@ public bool EnableTcpConnectionEndpointRediscovery set; } - /// - /// Gets or sets the flag to enable client telemetry feature. - /// - internal bool EnableClientTelemetry - { - get; - set; - } - /// /// Gets the default connection policy used to connect to the Azure Cosmos DB service. /// @@ -490,9 +481,14 @@ internal int? MaxTcpPartitionCount } /// - /// ClientTelemetryOptions + /// Gets or sets Client Telemetry Options like feature flags and corresponding options /// - public CosmosClientTelemetryOptions CosmosClientTelemetryOptions +#if PREVIEW + public +#else + internal +#endif + CosmosClientTelemetryOptions CosmosClientTelemetryOptions { get; set; diff --git a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs index cfdddc642d..b3b21e4f3b 100644 --- a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs +++ b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs @@ -11,7 +11,6 @@ namespace Microsoft.Azure.Cosmos using System.Linq; using System.Net; using System.Net.Http; - using System.Net.Http.Headers; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using Microsoft.Azure.Cosmos.Fluent; @@ -731,9 +730,14 @@ internal Protocol ConnectionProtocol internal bool? EnableCpuMonitor { get; set; } /// - /// Client Telemetry Options + /// Gets or sets Client Telemetry Options like feature flags and corresponding options /// - public CosmosClientTelemetryOptions CosmosClientTelemetryOptions { get; set; } +#if PREVIEW + public +#else + internal +#endif + CosmosClientTelemetryOptions CosmosClientTelemetryOptions { get; set; } internal void SetSerializerIfNotConfigured(CosmosSerializer serializer) { diff --git a/Microsoft.Azure.Cosmos/src/CosmosClientTelemetryOptions.cs b/Microsoft.Azure.Cosmos/src/CosmosClientTelemetryOptions.cs index cbeae81368..b2864e0dfd 100644 --- a/Microsoft.Azure.Cosmos/src/CosmosClientTelemetryOptions.cs +++ b/Microsoft.Azure.Cosmos/src/CosmosClientTelemetryOptions.cs @@ -10,17 +10,29 @@ namespace Microsoft.Azure.Cosmos public class CosmosClientTelemetryOptions { /// - /// Enable sending telemetry to service, is not applicable to this as of now + /// Disable sending telemetry to service, is not applicable to this as of now. + /// This option will disable sending telemetry to service.even it is opt-in from portal. /// - public bool EnableSendingMetricsToService { get; set; } = false; + /// By default, it is false +#if PREVIEW + public +#else + internal +#endif + bool DisableSendingMetricsToService { get; set; } = +#if PREVIEW + false; +#else + true; +#endif /// - /// Gets or sets the flag to generate operation level for methods calls using the Source Name "Azure.Cosmos.Operation". + /// This method enable/disable generation of operation level if listener is subscribed to the Source Name "Azure.Cosmos.Operation". /// /// - /// The default value is true (for preview package). + /// The default value is true /// - /// This flag is there to disable it from source. Please Refer https://opentelemetry.io/docs/instrumentation/net/exporters/ to know more about open telemetry exporters + /// Please Refer https://opentelemetry.io/docs/instrumentation/net/exporters/ to know more about open telemetry exporters #if PREVIEW public #else @@ -34,13 +46,15 @@ public class CosmosClientTelemetryOptions #endif /// - /// Threshold values for telemetry + /// Threshold values for Distributed Tracing. + /// These values decides whether to generate operation level with request diagnostics or not. /// #if PREVIEW public #else internal #endif - CosmosThresholdOptions CosmosThresholdOptions { get; set; } + CosmosThresholdOptions CosmosThresholdOptions { get; set; } = new CosmosThresholdOptions(); + } } \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs b/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs index 31ce062d71..8ba2ffa266 100644 --- a/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs +++ b/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs @@ -682,11 +682,16 @@ internal CosmosClientBuilder WithRetryWithOptions( } /// - /// WithClientTelemetryOptions + /// To enable Telemetry features with corresponding options /// /// /// The object - public CosmosClientBuilder WithClientTelemetryOptions(CosmosClientTelemetryOptions options) +#if PREVIEW + public +#else + internal +#endif + CosmosClientBuilder WithClientTelemetryOptions(CosmosClientTelemetryOptions options) { this.clientOptions.CosmosClientTelemetryOptions = options; return this; diff --git a/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/Filters/DiagnosticsFilterHelper.cs b/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/Filters/DiagnosticsFilterHelper.cs index 029c3f4031..11cda8e211 100644 --- a/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/Filters/DiagnosticsFilterHelper.cs +++ b/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/Filters/DiagnosticsFilterHelper.cs @@ -19,6 +19,7 @@ public static bool IsLatencyThresholdCrossed( OpenTelemetryAttributes response) { config ??= new CosmosThresholdOptions(); + TimeSpan latencyThreshold = operationType == OperationType.Query ? config.NonPointOperationLatencyThreshold : config.PointOperationLatencyThreshold; return response.Diagnostics.GetClientElapsedTime() > latencyThreshold; } diff --git a/Microsoft.Azure.Cosmos/src/Telemetry/TelemetryToServiceHelper.cs b/Microsoft.Azure.Cosmos/src/Telemetry/TelemetryToServiceHelper.cs index 9212457951..5735a84028 100644 --- a/Microsoft.Azure.Cosmos/src/Telemetry/TelemetryToServiceHelper.cs +++ b/Microsoft.Azure.Cosmos/src/Telemetry/TelemetryToServiceHelper.cs @@ -67,7 +67,7 @@ public static TelemetryToServiceHelper CreateAndInitializeClientConfigAndTelemet #if INTERNAL return new TelemetryToServiceHelper(); #else - if (!connectionPolicy.EnableClientTelemetry) + if (connectionPolicy.CosmosClientTelemetryOptions.DisableSendingMetricsToService) { return new TelemetryToServiceHelper(); } @@ -177,7 +177,7 @@ private void InitializeClientTelemetry(AccountClientConfiguration clientConfig) catch (Exception ex) { DefaultTrace.TraceWarning($"Error While starting Telemetry Job : {0}. Hence disabling Client Telemetry", ex); - this.connectionPolicy.EnableClientTelemetry = false; + this.connectionPolicy.CosmosClientTelemetryOptions.DisableSendingMetricsToService = true; } } } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/EndToEndTraceWriterBaselineTests.TypedPointOperationsAsync.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/EndToEndTraceWriterBaselineTests.TypedPointOperationsAsync.xml index 2caea1c615..1bdc803867 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/EndToEndTraceWriterBaselineTests.TypedPointOperationsAsync.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/EndToEndTraceWriterBaselineTests.TypedPointOperationsAsync.xml @@ -149,14 +149,6 @@ 0 201 - - Microsoft.DocumentDB - https://opentelemetry.io/schemas/1.17.0 - Some Value - 0 - 404 - - diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ClientTelemetryTestsBase.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ClientTelemetryTestsBase.cs index 8fd17669ae..3bb8a53c0c 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ClientTelemetryTestsBase.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ClientTelemetryTestsBase.cs @@ -142,7 +142,7 @@ public virtual void TestInitialize() this.cosmosClientBuilder = this.GetBuilder() .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() { - EnableSendingMetricsToService = true + DisableSendingMetricsToService = false }) .WithApplicationPreferredRegions(ClientTelemetryTestsBase.preferredRegionList); } @@ -671,7 +671,7 @@ public virtual async Task CreateItemWithSubStatusCodeTest(ConnectionMode mode) this.cosmosClientBuilder = this.cosmosClientBuilder .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() { - EnableSendingMetricsToService = true + DisableSendingMetricsToService = false }) .WithHttpClientFactory(() => new HttpClient(httpHandler)); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/DistributedTracingOTelTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/DistributedTracingOTelTests.cs index 6ed14ff7ca..53b0eb6e24 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/DistributedTracingOTelTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/DistributedTracingOTelTests.cs @@ -163,13 +163,13 @@ await base.TestInit(validateSinglePartitionKeyRangeCacheCall: false, } [DataTestMethod] - [DataRow(false, true, "random.source.name", DisplayName = "DirectMode, DistributedFlag On, Random/No Source:Asserts no activity creation")] - [DataRow(true, true, "random.source.name", DisplayName = "GatewayMode, DistributedFlag On, Random/No Source:Asserts no activity creation")] - [DataRow(false, false, "random.source.name", DisplayName = "DirectMode, DistributedFlag Off, Random/No Source:Asserts no activity creation")] - [DataRow(true, false, "random.source.name", DisplayName = "GatewayMode, DistributedFlag Off, Random/No Source:Asserts no activity creation")] - [DataRow(false, false, $"{OpenTelemetryAttributeKeys.DiagnosticNamespace}.Operation", DisplayName = "DirectMode, DistributedFlag Off, OperationLevel Source:Asserts no activity creation")] - [DataRow(true, false, $"{OpenTelemetryAttributeKeys.DiagnosticNamespace}.Operation", DisplayName = "GatewayMode, DistributedFlag Off, OperationLevel Source:Asserts no activity creation")] - public async Task NoSourceEnabled_ResultsInNoSourceParentActivityCreation_AssertLogTraceId(bool useGateway, bool enableDistributingTracing, string source) + [DataRow(false, false, "random.source.name", DisplayName = "DirectMode, DistributedFlag On, Random/No Source:Asserts no activity creation")] + [DataRow(true, false, "random.source.name", DisplayName = "GatewayMode, DistributedFlag On, Random/No Source:Asserts no activity creation")] + [DataRow(false, true, "random.source.name", DisplayName = "DirectMode, DistributedFlag Off, Random/No Source:Asserts no activity creation")] + [DataRow(true, true, "random.source.name", DisplayName = "GatewayMode, DistributedFlag Off, Random/No Source:Asserts no activity creation")] + [DataRow(false, true, $"{OpenTelemetryAttributeKeys.DiagnosticNamespace}.Operation", DisplayName = "DirectMode, DistributedFlag Off, OperationLevel Source:Asserts no activity creation")] + [DataRow(true, true, $"{OpenTelemetryAttributeKeys.DiagnosticNamespace}.Operation", DisplayName = "GatewayMode, DistributedFlag Off, OperationLevel Source:Asserts no activity creation")] + public async Task NoSourceEnabled_ResultsInNoSourceParentActivityCreation_AssertLogTraceId(bool useGateway, bool disableDistributingTracing, string source) { using TracerProvider provider = Sdk.CreateTracerProviderBuilder() .AddCustomOtelExporter() @@ -182,8 +182,8 @@ await base.TestInit(validateSinglePartitionKeyRangeCacheCall: false, customizeClientBuilder: (builder) => builder .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() { - DisableDistributedTracing = !enableDistributingTracing - }) + DisableDistributedTracing = disableDistributingTracing + }) .WithConnectionModeGateway()); } else @@ -192,8 +192,8 @@ await base.TestInit(validateSinglePartitionKeyRangeCacheCall: false, customizeClientBuilder: (builder) => builder .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() { - DisableDistributedTracing = !enableDistributingTracing - })); + DisableDistributedTracing = disableDistributingTracing + })); } ContainerResponse containerResponse = await this.database.CreateContainerAsync( @@ -205,7 +205,7 @@ await base.TestInit(validateSinglePartitionKeyRangeCacheCall: false, string diagnosticsCreateContainer = containerResponse.Diagnostics.ToString(); JObject objDiagnosticsCreate = JObject.Parse(diagnosticsCreateContainer); - if (enableDistributingTracing) + if (!disableDistributingTracing) { //DistributedTraceId present in logs string distributedTraceId = (string)objDiagnosticsCreate["data"]["DistributedTraceId"]; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/SynchronizationContextTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/SynchronizationContextTests.cs index 52aba34800..a51a77f14f 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/SynchronizationContextTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/SynchronizationContextTests.cs @@ -61,7 +61,7 @@ public void VerifySynchronizationContextDoesNotLock(bool withClientTelemetry) customizeClientBuilder: (builder) => builder .WithClientTelemetryOptions(new CosmosClientTelemetryOptions () { - EnableSendingMetricsToService = withClientTelemetry + DisableSendingMetricsToService = !withClientTelemetry }) .WithHttpClientFactory(() => new HttpClient(httpHandler)))) { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Mocks/MockDocumentClient.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Mocks/MockDocumentClient.cs index 3484abb3ae..7d268407de 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Mocks/MockDocumentClient.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Mocks/MockDocumentClient.cs @@ -54,9 +54,11 @@ public static CosmosClient CreateMockCosmosClient( { policy = new ConnectionPolicy { - EnableClientTelemetry = true // feature flag is always true + CosmosClientTelemetryOptions = new CosmosClientTelemetryOptions + { + DisableSendingMetricsToService = !isClientTelemetryEnabled.Value + } }; - } MockDocumentClient documentClient = new MockDocumentClient(policy); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetPreviewSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetPreviewSDKAPI.json index 2b887861dc..a33628d961 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetPreviewSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetPreviewSDKAPI.json @@ -352,6 +352,31 @@ }, "NestedTypes": {} }, + "Microsoft.Azure.Cosmos.CosmosClientOptions;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Subclasses": {}, + "Members": { + "Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions CosmosClientTelemetryOptions": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions CosmosClientTelemetryOptions;CanRead:True;CanWrite:True;Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions get_CosmosClientTelemetryOptions();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_CosmosClientTelemetryOptions(Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions get_CosmosClientTelemetryOptions()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions get_CosmosClientTelemetryOptions();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Void set_CosmosClientTelemetryOptions(Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Void set_CosmosClientTelemetryOptions(Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + } + }, + "NestedTypes": {} + }, "Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { @@ -360,6 +385,11 @@ "Attributes": [], "MethodInfo": "Boolean DisableDistributedTracing;CanRead:True;CanWrite:True;Boolean get_DisableDistributedTracing();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_DisableDistributedTracing(Boolean);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, + "Boolean DisableSendingMetricsToService": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "Boolean DisableSendingMetricsToService;CanRead:True;CanWrite:True;Boolean get_DisableSendingMetricsToService();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_DisableSendingMetricsToService(Boolean);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, "Boolean get_DisableDistributedTracing()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ @@ -367,6 +397,13 @@ ], "MethodInfo": "Boolean get_DisableDistributedTracing();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, + "Boolean get_DisableSendingMetricsToService()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Boolean get_DisableSendingMetricsToService();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, "Microsoft.Azure.Cosmos.CosmosThresholdOptions CosmosThresholdOptions": { "Type": "Property", "Attributes": [], @@ -392,6 +429,13 @@ "CompilerGeneratedAttribute" ], "MethodInfo": "Void set_DisableDistributedTracing(Boolean);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Void set_DisableSendingMetricsToService(Boolean)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Void set_DisableSendingMetricsToService(Boolean);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" } }, "NestedTypes": {} @@ -519,6 +563,17 @@ }, "NestedTypes": {} }, + "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Subclasses": {}, + "Members": { + "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithClientTelemetryOptions(Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions)": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithClientTelemetryOptions(Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + } + }, + "NestedTypes": {} + }, "Microsoft.Azure.Cosmos.Linq.CosmosLinqExtensions;System.Object;IsAbstract:True;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json index 4fb60e06eb..762e3f90cf 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.json @@ -2736,18 +2736,6 @@ "Attributes": [], "MethodInfo": "Microsoft.Azure.Cosmos.ConnectionMode get_ConnectionMode();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions CosmosClientTelemetryOptions": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions CosmosClientTelemetryOptions;CanRead:True;CanWrite:True;Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions get_CosmosClientTelemetryOptions();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_CosmosClientTelemetryOptions(Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions get_CosmosClientTelemetryOptions()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions get_CosmosClientTelemetryOptions();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, "Microsoft.Azure.Cosmos.CosmosSerializationOptions get_SerializerOptions()": { "Type": "Method", "Attributes": [], @@ -3019,13 +3007,6 @@ ], "MethodInfo": "Void set_ConsistencyLevel(System.Nullable`1[Microsoft.Azure.Cosmos.ConsistencyLevel]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Void set_CosmosClientTelemetryOptions(Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Void set_CosmosClientTelemetryOptions(Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, "Void set_EnableContentResponseOnWrite(System.Nullable`1[System.Boolean])[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ @@ -3138,29 +3119,10 @@ "Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { - "Boolean EnableSendingMetricsToService": { - "Type": "Property", - "Attributes": [], - "MethodInfo": "Boolean EnableSendingMetricsToService;CanRead:True;CanWrite:True;Boolean get_EnableSendingMetricsToService();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_EnableSendingMetricsToService(Boolean);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Boolean get_EnableSendingMetricsToService()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Boolean get_EnableSendingMetricsToService();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, "Void .ctor()": { "Type": "Constructor", "Attributes": [], "MethodInfo": "[Void .ctor(), Void .ctor()]" - }, - "Void set_EnableSendingMetricsToService(Boolean)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Void set_EnableSendingMetricsToService(Boolean);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" } }, "NestedTypes": {} @@ -4462,11 +4424,6 @@ "Attributes": [], "MethodInfo": "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithBulkExecution(Boolean);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithClientTelemetryOptions(Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions)": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithClientTelemetryOptions(Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithConnectionModeDirect()": { "Type": "Method", "Attributes": [], diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs index 1508c53b0f..d8aaf80b88 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs @@ -99,6 +99,17 @@ public void VerifyCosmosConfigurationPropertiesGetUpdated() Assert.AreNotEqual(Cosmos.ConsistencyLevel.Session, clientOptions.ConsistencyLevel); Assert.IsFalse(policy.EnablePartitionLevelFailover); Assert.IsFalse(clientOptions.EnableAdvancedReplicaSelectionForTcp.HasValue); +#if PREVIEW + Assert.IsFalse(clientOptions.CosmosClientTelemetryOptions.DisableDistributedTracing); +#else + Assert.IsTrue(clientOptions.CosmosClientTelemetryOptions.DisableDistributedTracing); +#endif + +#if PREVIEW + Assert.IsFalse(clientOptions.CosmosClientTelemetryOptions.DisableSendingMetricsToService); +#else + Assert.IsTrue(clientOptions.CosmosClientTelemetryOptions.DisableSendingMetricsToService); +#endif cosmosClientBuilder.WithApplicationRegion(region) .WithConnectionModeGateway(maxConnections, webProxy) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientTests.cs index 7981ea7226..6740001f53 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientTests.cs @@ -7,7 +7,6 @@ namespace Microsoft.Azure.Cosmos.Tests using System; using System.Collections.Generic; using System.Diagnostics; - using System.Collections.Specialized; using System.Globalization; using System.Linq; using System.Net; @@ -16,7 +15,6 @@ namespace Microsoft.Azure.Cosmos.Tests using System.Threading; using System.Threading.Tasks; using System.Web; - using FluentAssertions; using global::Azure; using global::Azure.Core; using Microsoft.Azure.Cosmos.Core.Trace; @@ -248,14 +246,7 @@ public void ValidateMasterKeyAuthProvider() using (CosmosClient client = new CosmosClient( CosmosClientTests.AccountEndpoint, - masterKeyCredential, - new CosmosClientOptions() - { - CosmosClientTelemetryOptions = new CosmosClientTelemetryOptions - { - EnableSendingMetricsToService = false - } - })) + masterKeyCredential)) { Assert.AreEqual(typeof(AuthorizationTokenProviderMasterKey), client.AuthorizationTokenProvider.GetType()); } @@ -268,14 +259,7 @@ public void ValidateResourceTokenAuthProvider() using (CosmosClient client = new CosmosClient( CosmosClientTests.AccountEndpoint, - resourceToken, - new CosmosClientOptions() - { - CosmosClientTelemetryOptions = new CosmosClientTelemetryOptions - { - EnableSendingMetricsToService = false - } - })) + resourceToken)) { Assert.AreEqual(typeof(AuthorizationTokenProviderResourceToken), client.AuthorizationTokenProvider.GetType()); } @@ -289,14 +273,7 @@ public void ValidateMasterKeyAzureCredentialAuthProvider() AzureKeyCredential masterKeyCredential = new AzureKeyCredential(originalKey); using (CosmosClient client = new CosmosClient( CosmosClientTests.AccountEndpoint, - masterKeyCredential, - new CosmosClientOptions() - { - CosmosClientTelemetryOptions = new CosmosClientTelemetryOptions - { - EnableSendingMetricsToService = false - } - })) + masterKeyCredential)) { Assert.AreEqual(typeof(AzureKeyCredentialAuthorizationTokenProvider), client.AuthorizationTokenProvider.GetType()); @@ -313,14 +290,7 @@ public void ValidateResourceTokenAzureCredentialAuthProvider() AzureKeyCredential resourceTokenCredential = new AzureKeyCredential(resourceToken); using (CosmosClient client = new CosmosClient( CosmosClientTests.AccountEndpoint, - resourceTokenCredential, - new CosmosClientOptions() - { - CosmosClientTelemetryOptions = new CosmosClientTelemetryOptions - { - EnableSendingMetricsToService = false - } - })) + resourceTokenCredential)) { Assert.AreEqual(typeof(AzureKeyCredentialAuthorizationTokenProvider), client.AuthorizationTokenProvider.GetType()); @@ -389,11 +359,7 @@ public async Task ValidateAzureKeyCredentialGatewayModeUpdateAsync() masterKeyCredential, new CosmosClientOptions() { - HttpClientFactory = () => new HttpClient(new HttpHandlerHelper(mockHttpHandler.Object)), - CosmosClientTelemetryOptions = new CosmosClientTelemetryOptions() - { - EnableSendingMetricsToService = false - } + HttpClientFactory = () => new HttpClient(new HttpHandlerHelper(mockHttpHandler.Object)) })) { Container container = client.GetContainer(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); @@ -455,13 +421,7 @@ void TraceHandler(string message) for (int z = 0; z < 100; ++z) { - using CosmosClient cosmos = new(ConnectionString, new CosmosClientOptions - { - CosmosClientTelemetryOptions = new CosmosClientTelemetryOptions - { - EnableSendingMetricsToService = true - } - }); + using CosmosClient cosmos = new(ConnectionString); } string assertMsg = String.Empty; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Utils/MockCosmosUtil.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Utils/MockCosmosUtil.cs index 92a6e60038..77ba6981cb 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Utils/MockCosmosUtil.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Utils/MockCosmosUtil.cs @@ -36,7 +36,10 @@ public static CosmosClient CreateMockCosmosClient( { ConnectionPolicy policy = new ConnectionPolicy { - EnableClientTelemetry = enableTelemetry + CosmosClientTelemetryOptions = new CosmosClientTelemetryOptions + { + DisableSendingMetricsToService = !enableTelemetry + } }; DocumentClient documentClient = accountConsistencyLevel.HasValue ? new MockDocumentClient(accountConsistencyLevel.Value, policy) : new MockDocumentClient(policy);