diff --git a/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/BenchmarkConfig.cs b/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/BenchmarkConfig.cs index e3ec5c23bb..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) { @@ -220,7 +220,11 @@ internal Microsoft.Azure.Cosmos.CosmosClient CreateCosmosClient(string accountKe MaxRetryAttemptsOnRateLimitedRequests = 0, MaxRequestsPerTcpConnection = this.MaxRequestsPerTcpConnection, MaxTcpConnectionsPerEndpoint = this.MaxTcpConnectionsPerEndpoint, - EnableClientTelemetry = this.EnableClientTelemetry + CosmosClientTelemetryOptions = new Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions() + { + DisableSendingMetricsToService = this.DisableClientTelemetry, + DisableDistributedTracing = this.DisableDistributedTracing + } }; if (!string.IsNullOrWhiteSpace(this.ConsistencyLevel)) @@ -228,8 +232,6 @@ internal Microsoft.Azure.Cosmos.CosmosClient CreateCosmosClient(string accountKe clientOptions.ConsistencyLevel = (Microsoft.Azure.Cosmos.ConsistencyLevel)Enum.Parse(typeof(Microsoft.Azure.Cosmos.ConsistencyLevel), this.ConsistencyLevel, ignoreCase: true); } - clientOptions.IsDistributedTracingEnabled = this.EnableDistributedTracing; - return new Microsoft.Azure.Cosmos.CosmosClient( this.EndPoint, accountKey, diff --git a/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/run.sh b/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/run.sh index 71b647d72d..81cafc4a4a 100644 --- a/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/run.sh +++ b/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/run.sh @@ -24,6 +24,12 @@ then exit -1 fi +if [ -z "$TELEMETRY_ENDPOINT" ] +then + echo "Missing TELEMETRY_ENDPOINT" + exit -1 +fi + if [ -z "$INCLUDE_QUERY" ] then echo "Missing INCLUDE_QUERY" @@ -41,26 +47,26 @@ echo $COMMIT_TIME echo $BRANCH_NAME # Client telemetry disabled ReadStreamExistsV3 -dotnet run -c Release -- -n 2000000 -w ReadStreamExistsV3 --tcp 10 --pl $PL -e $ACCOUNT_ENDPOINT -k $ACCOUNT_KEY --disableClientTelemetry --disableDistributedTracing --enablelatencypercentiles --disablecoresdklogging --publishresults --resultspartitionkeyvalue $RESULTS_PK --commitid $COMMIT_ID --commitdate $COMMIT_DATE --committime $COMMIT_TIME --branchname $BRANCH_NAME --database testdb --partitionkeypath /pk --container testcol +dotnet run -c Release -- -n 2000000 -w ReadStreamExistsV3 --tcp 10 --pl $PL -e $ACCOUNT_ENDPOINT -k $ACCOUNT_KEY --enablelatencypercentiles --disablecoresdklogging --publishresults --resultspartitionkeyvalue $RESULTS_PK --commitid $COMMIT_ID --commitdate $COMMIT_DATE --committime $COMMIT_TIME --branchname $BRANCH_NAME --database testdb --container testcol --partitionkeypath /pk sleep 10 #Wait # Client telemetry enabled ReadStreamExistsV3. This is needed to see the impact of client telemetry. -dotnet run -c Release -- -n 2000000 -w ReadStreamExistsV3 --WorkloadName ReadStreamExistsV3WithTelemetry --telemetryScheduleInSec 60 --disableDistributedTracing --tcp 10 --pl $PL -e $ACCOUNT_ENDPOINT -k $ACCOUNT_KEY --enablelatencypercentiles --disablecoresdklogging --publishresults --resultspartitionkeyvalue $RESULTS_PK --commitid $COMMIT_ID --commitdate $COMMIT_DATE --committime $COMMIT_TIME --branchname $BRANCH_NAME --database testdb --partitionkeypath /pk --container testcol +dotnet run -c Release -- -n 2000000 -w ReadStreamExistsV3 --WorkloadName ReadStreamExistsV3WithTelemetry --enableTelemetry --telemetryScheduleInSec 60 --telemetryEndpoint $TELEMETRY_ENDPOINT --tcp 10 --pl $PL -e $ACCOUNT_ENDPOINT -k $ACCOUNT_KEY --enablelatencypercentiles --disablecoresdklogging --publishresults --resultspartitionkeyvalue $RESULTS_PK --commitid $COMMIT_ID --commitdate $COMMIT_DATE --committime $COMMIT_TIME --branchname $BRANCH_NAME --database testdb --container testcol --partitionkeypath /pk sleep 10 #Wait # Open telemetry enabled ReadStreamExistsV3. This is needed to see the impact of distributed tracing (without listener) -dotnet run -c Release -- -n 2000000 -w ReadStreamExistsV3 --WorkloadName ReadStreamExistsV3WithDistributedTracingWOListener --disableClientTelemetry --tcp 10 --pl $PL -e $ACCOUNT_ENDPOINT -k $ACCOUNT_KEY --enablelatencypercentiles --disablecoresdklogging --publishresults --resultspartitionkeyvalue $RESULTS_PK --commitid $COMMIT_ID --commitdate $COMMIT_DATE --committime $COMMIT_TIME --branchname $BRANCH_NAME --database testdb --partitionkeypath /pk --container testcol +dotnet run -c Release -- -n 2000000 -w ReadStreamExistsV3 --WorkloadName ReadStreamExistsV3WithDistributedTracingWOListener --enableDistributedTracing --tcp 10 --pl $PL -e $ACCOUNT_ENDPOINT -k $ACCOUNT_KEY --enablelatencypercentiles --disablecoresdklogging --publishresults --resultspartitionkeyvalue $RESULTS_PK --commitid $COMMIT_ID --commitdate $COMMIT_DATE --committime $COMMIT_TIME --branchname $BRANCH_NAME --database testdb --container testcol --partitionkeypath /pk sleep 10 #Wait #Point read operations for WORKLOAD_NAME in ReadNotExistsV3 ReadTExistsV3 ReadStreamExistsWithDiagnosticsV3 do - dotnet run -c Release -- -n 2000000 -w $WORKLOAD_NAME --pl $PL --telemetryScheduleInSec 60 --tcp 10 -e $ACCOUNT_ENDPOINT -k $ACCOUNT_KEY --enablelatencypercentiles --disablecoresdklogging --publishresults --resultspartitionkeyvalue $RESULTS_PK --commitid $COMMIT_ID --commitdate $COMMIT_DATE --committime $COMMIT_TIME --branchname $BRANCH_NAME --database testdb --partitionkeypath /pk --container testcol + dotnet run -c Release -- -n 2000000 -w $WORKLOAD_NAME --pl $PL --enableTelemetry --telemetryScheduleInSec 60 --telemetryEndpoint $TELEMETRY_ENDPOINT --tcp 10 -e $ACCOUNT_ENDPOINT -k $ACCOUNT_KEY --enablelatencypercentiles --disablecoresdklogging --publishresults --resultspartitionkeyvalue $RESULTS_PK --commitid $COMMIT_ID --commitdate $COMMIT_DATE --committime $COMMIT_TIME --branchname $BRANCH_NAME --database testdb --container testcol --partitionkeypath /pk sleep 10 #Wait done #Insert operation -dotnet run -c Release -- -n 2000000 -w InsertV3 --pl 30 --telemetryScheduleInSec 60 --tcp 1 -e $ACCOUNT_ENDPOINT -k $ACCOUNT_KEY --enablelatencypercentiles --disablecoresdklogging --publishresults --resultspartitionkeyvalue $RESULTS_PK --commitid $COMMIT_ID --commitdate $COMMIT_DATE --committime $COMMIT_TIME --branchname $BRANCH_NAME --database testdb --partitionkeypath /pk --container testcol +dotnet run -c Release -- -n 2000000 -w InsertV3 --pl 30 --enableTelemetry --telemetryScheduleInSec 60 --telemetryEndpoint $TELEMETRY_ENDPOINT --tcp 1 -e $ACCOUNT_ENDPOINT -k $ACCOUNT_KEY --enablelatencypercentiles --disablecoresdklogging --publishresults --resultspartitionkeyvalue $RESULTS_PK --commitid $COMMIT_ID --commitdate $COMMIT_DATE --committime $COMMIT_TIME --branchname $BRANCH_NAME --database testdb --container testcol --partitionkeypath /pk sleep 45 #Wait if [ "$INCLUDE_QUERY" = true ] @@ -70,7 +76,7 @@ then # pl is 16 because 18 was casuing a small amount of thorrtles. for WORKLOAD_NAME in ReadFeedStreamV3 QueryTSinglePkV3 QueryTSinglePkOrderByWithPaginationV3 QueryTSinglePkOrderByFullDrainV3 QueryTCrossPkV3 QueryTCrossPkOrderByWithPaginationV3 QueryTCrossPkOrderByFullDrainV3 QueryStreamSinglePkV3 QueryStreamSinglePkOrderByWithPaginationV3 QueryStreamSinglePkOrderByFullDrainV3 QueryStreamCrossPkV3 QueryStreamCrossPkOrderByWithPaginationV3 QueryStreamCrossPkOrderByFullDrainV3 do - dotnet run -c Release -- -n 200000 -w $WORKLOAD_NAME --pl 16 --telemetryScheduleInSec 60 --tcp 10 -e $ACCOUNT_ENDPOINT -k $ACCOUNT_KEY --enablelatencypercentiles --disablecoresdklogging --publishresults --resultspartitionkeyvalue $RESULTS_PK --commitid $COMMIT_ID --commitdate $COMMIT_DATE --committime $COMMIT_TIME --branchname $BRANCH_NAME --database testdb --partitionkeypath /pk --container testcol + dotnet run -c Release -- -n 200000 -w $WORKLOAD_NAME --pl 16 --enableTelemetry --telemetryScheduleInSec 60 --telemetryEndpoint $TELEMETRY_ENDPOINT --tcp 10 -e $ACCOUNT_ENDPOINT -k $ACCOUNT_KEY --enablelatencypercentiles --disablecoresdklogging --publishresults --resultspartitionkeyvalue $RESULTS_PK --commitid $COMMIT_ID --commitdate $COMMIT_DATE --committime $COMMIT_TIME --branchname $BRANCH_NAME --database testdb --container testcol --partitionkeypath /pk sleep 10 #Wait done fi \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos.Samples/Tools/CTL/CTLConfig.cs b/Microsoft.Azure.Cosmos.Samples/Tools/CTL/CTLConfig.cs index 98bba7b700..8d58271a22 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); @@ -130,12 +130,19 @@ internal CosmosClient CreateCosmosClient() CosmosClientOptions clientOptions = new CosmosClientOptions() { ApplicationName = CTLConfig.UserAgentSuffix, - EnableClientTelemetry = this.EnableClientTelemetry + CosmosClientTelemetryOptions = new CosmosClientTelemetryOptions() + { + DisableSendingMetricsToService = this.DisableClientTelemetry, + } }; + Console.WriteLine("ApplicationName = " + CTLConfig.UserAgentSuffix); + Console.WriteLine("DisableSendingMetricsToService = " + this.DisableClientTelemetry); + if (this.UseGatewayMode) { clientOptions.ConnectionMode = ConnectionMode.Gateway; + Console.WriteLine("ConnectionMode = " + ConnectionMode.Gateway); } if (!string.IsNullOrWhiteSpace(this.ConsistencyLevel)) @@ -143,6 +150,7 @@ internal CosmosClient CreateCosmosClient() if (Enum.TryParse(this.ConsistencyLevel, out ConsistencyLevel consistencyLevel)) { clientOptions.ConsistencyLevel = consistencyLevel; + Console.WriteLine("ConsistencyLevel = " + consistencyLevel); } else { diff --git a/Microsoft.Azure.Cosmos/src/ConnectionPolicy.cs b/Microsoft.Azure.Cosmos/src/ConnectionPolicy.cs index 8451918e9b..bd1b23b16c 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. /// @@ -489,6 +480,15 @@ internal int? MaxTcpPartitionCount set; } + /// + /// Gets or sets Client Telemetry Options like feature flags and corresponding options + /// + internal CosmosClientTelemetryOptions CosmosClientTelemetryOptions + { + get; + set; + } + /// /// GlobalEndpointManager will subscribe to this event if user updates the preferredLocations list in the Azure Cosmos DB service. /// diff --git a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs index 2c07f060f8..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; @@ -85,6 +84,7 @@ public CosmosClientOptions() this.ConnectionProtocol = CosmosClientOptions.DefaultProtocol; this.ApiType = CosmosClientOptions.DefaultApiType; this.CustomHandlers = new Collection(); + this.CosmosClientTelemetryOptions = new CosmosClientTelemetryOptions(); } /// @@ -730,9 +730,14 @@ internal Protocol ConnectionProtocol internal bool? EnableCpuMonitor { get; set; } /// - /// Flag to enable telemetry + /// Gets or sets Client Telemetry Options like feature flags and corresponding options /// - internal bool? EnableClientTelemetry { get; set; } +#if PREVIEW + public +#else + internal +#endif + CosmosClientTelemetryOptions CosmosClientTelemetryOptions { get; set; } internal void SetSerializerIfNotConfigured(CosmosSerializer serializer) { @@ -771,12 +776,13 @@ internal virtual ConnectionPolicy GetConnectionPolicy(int clientId) EnableTcpConnectionEndpointRediscovery = this.EnableTcpConnectionEndpointRediscovery, EnableAdvancedReplicaSelectionForTcp = this.EnableAdvancedReplicaSelectionForTcp, HttpClientFactory = this.httpClientFactory, - ServerCertificateCustomValidationCallback = this.ServerCertificateCustomValidationCallback + ServerCertificateCustomValidationCallback = this.ServerCertificateCustomValidationCallback, + CosmosClientTelemetryOptions = new CosmosClientTelemetryOptions() }; - if (this.EnableClientTelemetry.HasValue) + if (this.CosmosClientTelemetryOptions != null) { - connectionPolicy.EnableClientTelemetry = this.EnableClientTelemetry.Value; + connectionPolicy.CosmosClientTelemetryOptions = this.CosmosClientTelemetryOptions; } if (this.ApplicationRegion != null) @@ -1013,29 +1019,5 @@ public override bool CanConvert(Type objectType) return objectType == typeof(DateTime); } } - - /// - /// Distributed Tracing Options. - /// - /// Applicable only when Operation level distributed tracing is enabled through - internal DistributedTracingOptions DistributedTracingOptions { get; set; } - - /// - /// Gets or sets the flag to generate operation level for methods calls using the Source Name "Azure.Cosmos.Operation". - /// - /// - /// The default value is true (for preview package). - /// - /// 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 -#if PREVIEW - public -#else - internal -#endif - bool IsDistributedTracingEnabled { get; set; } -#if PREVIEW - = true; -#endif - } } \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/CosmosClientTelemetryOptions.cs b/Microsoft.Azure.Cosmos/src/CosmosClientTelemetryOptions.cs new file mode 100644 index 0000000000..8b2a2aa6a0 --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/CosmosClientTelemetryOptions.cs @@ -0,0 +1,58 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ + +namespace Microsoft.Azure.Cosmos +{ + /// + /// Telemetry Options for Cosmos Client to enable/disable telemetry and distributed tracing along with corresponding threshold values. + /// +#if PREVIEW + public +#else + internal +#endif + class CosmosClientTelemetryOptions + { + /// + /// 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. + /// true +#if PREVIEW + public +#else + internal +#endif + bool DisableSendingMetricsToService { get; set; } = true; + + /// + /// This method enable/disable generation of operation level if listener is subscribed to the Source Name "Azure.Cosmos.Operation". + /// + /// false + /// Please Refer https://opentelemetry.io/docs/instrumentation/net/exporters/ to know more about open telemetry exporters +#if PREVIEW + public +#else + internal +#endif + bool DisableDistributedTracing { get; set; } = +#if PREVIEW + false; +#else + true; +#endif + + /// + /// 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; } = new CosmosThresholdOptions(); + + } +} \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/CosmosThresholdOptions.cs b/Microsoft.Azure.Cosmos/src/CosmosThresholdOptions.cs new file mode 100644 index 0000000000..5a04286f68 --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/CosmosThresholdOptions.cs @@ -0,0 +1,31 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ + +namespace Microsoft.Azure.Cosmos +{ + using System; + + /// + /// Threshold values for Distributed Tracing + /// +#if PREVIEW + public +#else + internal +#endif + class CosmosThresholdOptions + { + /// + /// Latency Threshold for non point operations i.e. Query + /// + /// 500 ms + public TimeSpan NonPointOperationLatencyThreshold { get; set; } = TimeSpan.FromSeconds(3); + + /// + /// Latency Threshold for point operations i.e operation other than Query + /// + /// 100 ms + public TimeSpan PointOperationLatencyThreshold { get; set; } = TimeSpan.FromSeconds(1); + } +} diff --git a/Microsoft.Azure.Cosmos/src/DocumentClient.cs b/Microsoft.Azure.Cosmos/src/DocumentClient.cs index 9dee309028..3c261490a7 100644 --- a/Microsoft.Azure.Cosmos/src/DocumentClient.cs +++ b/Microsoft.Azure.Cosmos/src/DocumentClient.cs @@ -171,7 +171,7 @@ internal partial class DocumentClient : IDisposable, IAuthorizationTokenProvider internal RemoteCertificateValidationCallback remoteCertificateValidationCallback; //Distributed Tracing Flag - internal bool isDistributedTracingEnabled; + internal CosmosClientTelemetryOptions cosmosClientTelemetryOptions; //SessionContainer. internal ISessionContainer sessionContainer; @@ -432,7 +432,7 @@ internal DocumentClient(Uri serviceEndpoint, /// Flag to allow Quorum Read with Eventual Consistency Account /// /// This delegate responsible for validating the third party certificate. - /// This is distributed tracing flag + /// This is distributed tracing flag /// /// 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 @@ -460,7 +460,7 @@ internal DocumentClient(Uri serviceEndpoint, bool isLocalQuorumConsistency = false, string cosmosClientId = null, RemoteCertificateValidationCallback remoteCertificateValidationCallback = null, - bool isDistributedTracingEnabled = false) + CosmosClientTelemetryOptions cosmosClientTelemetryOptions = null) { if (sendingRequestEventArgs != null) { @@ -494,7 +494,7 @@ internal DocumentClient(Uri serviceEndpoint, storeClientFactory: storeClientFactory, cosmosClientId: cosmosClientId, remoteCertificateValidationCallback: remoteCertificateValidationCallback, - isDistributedTracingEnabled: isDistributedTracingEnabled); + cosmosClientTelemetryOptions: cosmosClientTelemetryOptions); } /// @@ -678,7 +678,7 @@ internal virtual void Initialize(Uri serviceEndpoint, TokenCredential tokenCredential = null, string cosmosClientId = null, RemoteCertificateValidationCallback remoteCertificateValidationCallback = null, - bool isDistributedTracingEnabled = false) + CosmosClientTelemetryOptions cosmosClientTelemetryOptions = null) { if (serviceEndpoint == null) { @@ -687,7 +687,7 @@ internal virtual void Initialize(Uri serviceEndpoint, this.clientId = cosmosClientId; this.remoteCertificateValidationCallback = remoteCertificateValidationCallback; - this.isDistributedTracingEnabled = isDistributedTracingEnabled; + this.cosmosClientTelemetryOptions = cosmosClientTelemetryOptions ?? new CosmosClientTelemetryOptions(); this.queryPartitionProvider = new AsyncLazy(async () => { @@ -6623,7 +6623,7 @@ private void InitializeDirectConnectivity(IStoreClientFactory storeClientFactory { Documents.Telemetry.DistributedTracingOptions distributedTracingOptions = new () { - IsDistributedTracingEnabled = this.isDistributedTracingEnabled + IsDistributedTracingEnabled = !this.cosmosClientTelemetryOptions.DisableDistributedTracing }; StoreClientFactory newClientFactory = new StoreClientFactory( diff --git a/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs b/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs index bf04d103bb..8ba2ffa266 100644 --- a/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs +++ b/Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs @@ -435,36 +435,6 @@ public CosmosClientBuilder WithConsistencyLevel(Cosmos.ConsistencyLevel consiste } - /// - /// Sets whether Distributed Tracing for "Azure.Cosmos.Operation" source is enabled. - /// - /// Whether is enabled. - /// The current . -#if PREVIEW - public -#else - internal -#endif - CosmosClientBuilder WithDistributedTracing(bool isEnabled = true) - { - this.clientOptions.IsDistributedTracingEnabled = isEnabled; - return this; - } - - /// - /// Enables Distributed Tracing with a Configuration ref. - /// - /// . - /// The current .] - /// Refer https://opentelemetry.io/docs/instrumentation/net/exporters/ to know more about open telemetry exporters - internal CosmosClientBuilder WithDistributedTracingOptions(DistributedTracingOptions options) - { - this.clientOptions.IsDistributedTracingEnabled = true; - this.clientOptions.DistributedTracingOptions = options; - - return this; - } - /// /// Sets the connection mode to Gateway. This is used by the client when connecting to the Azure Cosmos DB service. /// @@ -679,27 +649,6 @@ internal CosmosClientBuilder WithCpuMonitorDisabled() return this; } - /// - /// Disable Telemetry if enabled using environment properties - /// - /// The object - internal CosmosClientBuilder WithTelemetryDisabled() - { - this.clientOptions.EnableClientTelemetry = false; - return this; - } - - /// - /// To enable Telemetry, set COSMOS.CLIENT_TELEMETRY_ENABLED environment property. - /// This function is used by Test only. - /// - /// The object - internal CosmosClientBuilder WithTelemetryEnabled() - { - this.clientOptions.EnableClientTelemetry = true; - return this; - } - /// /// Enabled partition level failover in the SDK /// @@ -731,5 +680,21 @@ internal CosmosClientBuilder WithRetryWithOptions( this.clientOptions.TotalWaitTimeForRetryWithMilliseconds = totalWaitTimeForRetryWithMilliseconds; return this; } + + /// + /// To enable Telemetry features with corresponding options + /// + /// + /// The object +#if PREVIEW + public +#else + internal +#endif + CosmosClientBuilder WithClientTelemetryOptions(CosmosClientTelemetryOptions options) + { + this.clientOptions.CosmosClientTelemetryOptions = options; + return this; + } } } diff --git a/Microsoft.Azure.Cosmos/src/RequestOptions/RequestOptions.cs b/Microsoft.Azure.Cosmos/src/RequestOptions/RequestOptions.cs index dc02f9a248..56c152568a 100644 --- a/Microsoft.Azure.Cosmos/src/RequestOptions/RequestOptions.cs +++ b/Microsoft.Azure.Cosmos/src/RequestOptions/RequestOptions.cs @@ -66,7 +66,7 @@ public class RequestOptions /// /// Set Request Level Distributed Tracing Options. /// - internal DistributedTracingOptions DistributedTracingOptions { get; set; } + internal CosmosThresholdOptions CosmosThresholdOptions { get; set; } /// /// Gets or sets the boolean to use effective partition key routing in the cosmos db request. diff --git a/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs b/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs index a128e178d0..5d5b66ee71 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs @@ -82,7 +82,7 @@ internal static CosmosClientContext Create( sessionContainer: clientOptions.SessionContainer, cosmosClientId: cosmosClient.Id, remoteCertificateValidationCallback: ClientContextCore.SslCustomValidationCallBack(clientOptions.ServerCertificateCustomValidationCallback), - isDistributedTracingEnabled: clientOptions.IsDistributedTracingEnabled); + cosmosClientTelemetryOptions: clientOptions.CosmosClientTelemetryOptions); return ClientContextCore.Create( cosmosClient, diff --git a/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/CosmosDbEventSource.cs b/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/CosmosDbEventSource.cs index 8898cea96d..f7fe0c307f 100644 --- a/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/CosmosDbEventSource.cs +++ b/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/CosmosDbEventSource.cs @@ -31,7 +31,7 @@ public static bool IsEnabled(EventLevel level) [NonEvent] public static void RecordDiagnosticsForRequests( - DistributedTracingOptions config, + CosmosThresholdOptions config, Documents.OperationType operationType, OpenTelemetryAttributes response) { diff --git a/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/DistributedTracingOptions.cs b/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/DistributedTracingOptions.cs deleted file mode 100644 index 6c44f06bf2..0000000000 --- a/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/DistributedTracingOptions.cs +++ /dev/null @@ -1,30 +0,0 @@ -// ------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. All rights reserved. -// ------------------------------------------------------------ - -namespace Microsoft.Azure.Cosmos -{ - using System; - - /// - /// Options for configuring the distributed tracing and event tracing - /// - internal sealed class DistributedTracingOptions - { - /// - /// Default Latency threshold for other than query Operation - /// - internal static readonly TimeSpan DefaultCrudLatencyThreshold = TimeSpan.FromMilliseconds(100); - - /// - /// Default Latency threshold for QUERY operation - /// - internal static readonly TimeSpan DefaultQueryTimeoutThreshold = TimeSpan.FromMilliseconds(500); - - /// - /// SDK generates (Event Source Name is "Azure-Cosmos-Operation-Request-Diagnostics") with Request Diagnostics String, If Operation level distributed tracing is not disabled i.e. - /// - /// If it is not set then, by default, it will generate for query operation which are taking more than 500 ms and non-query operations taking more than 100 ms. - public TimeSpan? LatencyThresholdForDiagnosticEvent { get; set; } - } -} diff --git a/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/Filters/DiagnosticsFilterHelper.cs b/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/Filters/DiagnosticsFilterHelper.cs index d48392bb3e..3c0646f101 100644 --- a/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/Filters/DiagnosticsFilterHelper.cs +++ b/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/Filters/DiagnosticsFilterHelper.cs @@ -10,29 +10,18 @@ namespace Microsoft.Azure.Cosmos.Telemetry.Diagnostics internal static class DiagnosticsFilterHelper { + private static readonly CosmosThresholdOptions defaultThresholdOptions = new CosmosThresholdOptions(); + /// /// Allow only when Latency is not more than 100 (non-query) /250 (query) ms /// /// true or false public static bool IsLatencyThresholdCrossed( - DistributedTracingOptions config, + CosmosThresholdOptions config, OperationType operationType, OpenTelemetryAttributes response) { - TimeSpan latencyThreshold; - - if (config?.LatencyThresholdForDiagnosticEvent != null) - { - latencyThreshold = config.LatencyThresholdForDiagnosticEvent.Value; - } - else - { - latencyThreshold = DiagnosticsFilterHelper.IsPointOperation(operationType) ? - DistributedTracingOptions.DefaultCrudLatencyThreshold : - DistributedTracingOptions.DefaultQueryTimeoutThreshold; - } - - return response.Diagnostics.GetClientElapsedTime() > latencyThreshold; + return response.Diagnostics.GetClientElapsedTime() > DiagnosticsFilterHelper.DefaultThreshold(operationType, config); } /// @@ -48,11 +37,24 @@ public static bool IsSuccessfulResponse(HttpStatusCode statusCode, int substatus || (statusCode == System.Net.HttpStatusCode.PreconditionFailed && substatusCode == 0); } + /// + /// Get default threshold value based on operation type + /// + /// + /// + internal static TimeSpan DefaultThreshold(OperationType operationType, CosmosThresholdOptions config) + { + config ??= DiagnosticsFilterHelper.defaultThresholdOptions; + return DiagnosticsFilterHelper.IsPointOperation(operationType) ? + config.PointOperationLatencyThreshold : + config.NonPointOperationLatencyThreshold; + } + /// /// Check if passed operation type is a point operation /// /// - public static bool IsPointOperation(OperationType operationType) + internal static bool IsPointOperation(OperationType operationType) { return operationType == OperationType.Create || operationType == OperationType.Delete || diff --git a/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryCoreRecorder.cs b/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryCoreRecorder.cs index ced441d368..3679d7c7bd 100644 --- a/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryCoreRecorder.cs +++ b/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryCoreRecorder.cs @@ -18,7 +18,7 @@ internal struct OpenTelemetryCoreRecorder : IDisposable private const string CosmosDb = "cosmosdb"; private readonly DiagnosticScope scope = default; - private readonly DistributedTracingOptions config = null; + private readonly CosmosThresholdOptions config = null; private readonly Activity activity = null; private readonly Documents.OperationType operationType = Documents.OperationType.Invalid; @@ -51,7 +51,7 @@ private OpenTelemetryCoreRecorder( string containerName, string databaseName, Documents.OperationType operationType, - CosmosClientContext clientContext, DistributedTracingOptions config) + CosmosClientContext clientContext, CosmosThresholdOptions config) { this.scope = scope; this.config = config; @@ -96,7 +96,7 @@ public static OpenTelemetryCoreRecorder CreateOperationLevelParentActivity( string databaseName, Documents.OperationType operationType, CosmosClientContext clientContext, - DistributedTracingOptions config) + CosmosThresholdOptions config) { return new OpenTelemetryCoreRecorder( operationScope, diff --git a/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryRecorderFactory.cs b/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryRecorderFactory.cs index ca0b864d2f..61d8889aaa 100644 --- a/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryRecorderFactory.cs +++ b/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryRecorderFactory.cs @@ -42,7 +42,7 @@ public static OpenTelemetryCoreRecorder CreateRecorder(string operationName, CosmosClientContext clientContext) { OpenTelemetryCoreRecorder openTelemetryRecorder = default; - if (clientContext is { ClientOptions.IsDistributedTracingEnabled: true }) + if (clientContext is { ClientOptions.CosmosClientTelemetryOptions.DisableDistributedTracing: false }) { // If there is no source then it will return default otherwise a valid diagnostic scope DiagnosticScope scope = LazyOperationScopeFactory.Value.CreateScope(name: operationName, @@ -60,7 +60,7 @@ public static OpenTelemetryCoreRecorder CreateRecorder(string operationName, databaseName: databaseName, operationType: operationType, clientContext: clientContext, - config: requestOptions?.DistributedTracingOptions ?? clientContext.ClientOptions?.DistributedTracingOptions); + config: requestOptions?.CosmosThresholdOptions ?? clientContext.ClientOptions?.CosmosClientTelemetryOptions.CosmosThresholdOptions); } #if !INTERNAL else if (Activity.Current is null) diff --git a/Microsoft.Azure.Cosmos/src/Telemetry/TelemetryToServiceHelper.cs b/Microsoft.Azure.Cosmos/src/Telemetry/TelemetryToServiceHelper.cs index f358076b25..2d0e79071f 100644 --- a/Microsoft.Azure.Cosmos/src/Telemetry/TelemetryToServiceHelper.cs +++ b/Microsoft.Azure.Cosmos/src/Telemetry/TelemetryToServiceHelper.cs @@ -68,7 +68,7 @@ public static TelemetryToServiceHelper CreateAndInitializeClientConfigAndTelemet #if INTERNAL return new TelemetryToServiceHelper(); #else - if (!connectionPolicy.EnableClientTelemetry) + if (connectionPolicy.CosmosClientTelemetryOptions.DisableSendingMetricsToService) { return new TelemetryToServiceHelper(); } @@ -217,7 +217,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; } } else diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/EndToEndTraceWriterBaselineTests.BulkOperationsAsync.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/EndToEndTraceWriterBaselineTests.BulkOperationsAsync.xml index fa758baa05..d24e0d6ac3 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/EndToEndTraceWriterBaselineTests.BulkOperationsAsync.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/EndToEndTraceWriterBaselineTests.BulkOperationsAsync.xml @@ -3969,9 +3969,14 @@ maxRetryWaitTimeOnThrottledRequests: TimeSpan.FromSeconds(1), maxRetryAttemptsOnThrottledRequests: 3) .WithBulkExecution(true) - .WithDistributedTracingOptions(new DistributedTracingOptions() + .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() { - LatencyThresholdForDiagnosticEvent = TimeSpan.FromMilliseconds(0) + DisableDistributedTracing = false, + CosmosThresholdOptions = new CosmosThresholdOptions() + { + PointOperationLatencyThreshold = TimeSpan.Zero, + NonPointOperationLatencyThreshold = TimeSpan.Zero + } }) .WithTransportClientHandlerFactory(transportClient => new TransportClientWrapper( transportClient, diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/EndToEndTraceWriterBaselineTests.PointOperationsExceptionsAsync.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/EndToEndTraceWriterBaselineTests.PointOperationsExceptionsAsync.xml index 23f61fcef1..62b8f5b2bb 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/EndToEndTraceWriterBaselineTests.PointOperationsExceptionsAsync.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/EndToEndTraceWriterBaselineTests.PointOperationsExceptionsAsync.xml @@ -190,9 +190,14 @@ Guid exceptionActivityId = Guid.NewGuid(); using CosmosClient throttleClient = TestCommon.CreateCosmosClient(builder => builder - .WithDistributedTracingOptions(new DistributedTracingOptions() + .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() { - LatencyThresholdForDiagnosticEvent = TimeSpan.FromMilliseconds(0) + DisableDistributedTracing = false, + CosmosThresholdOptions = new CosmosThresholdOptions() + { + PointOperationLatencyThreshold = TimeSpan.Zero, + NonPointOperationLatencyThreshold = TimeSpan.Zero + } }) .WithThrottlingRetryOptions( maxRetryWaitTimeOnThrottledRequests: TimeSpan.FromSeconds(1), diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ClientTelemetryConfigurationTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ClientTelemetryConfigurationTest.cs index 57b5357055..9447191a90 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ClientTelemetryConfigurationTest.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ClientTelemetryConfigurationTest.cs @@ -80,7 +80,10 @@ public async Task Validate_ClientTelemetryJob_Status_if_Disabled_At_Instance_Lev this.cosmosClientBuilder .WithHttpClientFactory(() => new HttpClient(httpHandler)) - .WithTelemetryDisabled(); + .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() + { + DisableSendingMetricsToService = true + }); this.SetClient(this.cosmosClientBuilder.Build()); @@ -144,7 +147,10 @@ public async Task Validate_ClientTelemetryJob_Status_with_Client_Config_Api_Stat this.cosmosClientBuilder .WithHttpClientFactory(() => new HttpClient(httpHandler)) - .WithTelemetryEnabled(); + .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() + { + DisableSendingMetricsToService = false + }); this.SetClient(this.cosmosClientBuilder.Build()); @@ -212,7 +218,10 @@ public async Task Validate_ClientTelemetryJob_When_Flag_Is_Switched(bool flagSta this.cosmosClientBuilder .WithHttpClientFactory(() => new HttpClient(httpHandler)) - .WithTelemetryEnabled(); + .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() + { + DisableSendingMetricsToService = false + }); this.SetClient(this.cosmosClientBuilder.Build()); 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 30c239a036..3bb8a53c0c 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ClientTelemetryTestsBase.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ClientTelemetryTestsBase.cs @@ -140,7 +140,10 @@ public virtual void TestInitialize() }; this.cosmosClientBuilder = this.GetBuilder() - .WithTelemetryEnabled() + .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() + { + DisableSendingMetricsToService = false + }) .WithApplicationPreferredRegions(ClientTelemetryTestsBase.preferredRegionList); } @@ -666,7 +669,10 @@ public virtual async Task CreateItemWithSubStatusCodeTest(ConnectionMode mode) // Replacing originally initialized cosmos Builder with this one with new handler this.cosmosClientBuilder = this.cosmosClientBuilder - .WithTelemetryEnabled() + .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() + { + DisableSendingMetricsToService = false + }) .WithHttpClientFactory(() => new HttpClient(httpHandler)); Container container = await this.CreateClientAndContainer( 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 8b5825831c..53b0eb6e24 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/DistributedTracingOTelTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/DistributedTracingOTelTests.cs @@ -19,7 +19,6 @@ namespace Microsoft.Azure.Cosmos using System.Diagnostics; using Microsoft.Azure.Cosmos.Tracing; using System.Net.Http; - using System.ComponentModel; [VisualStudio.TestTools.UnitTesting.TestClass] public sealed class DistributedTracingOTelTests : BaseCosmosClientHelper @@ -46,7 +45,10 @@ public async Task SourceEnabled_FlagOn_DirectMode_RecordsActivity_AssertLogTrace await base.TestInit(validateSinglePartitionKeyRangeCacheCall: false, customizeClientBuilder: (builder) => builder - .WithDistributedTracing(true) + .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() + { + DisableDistributedTracing = false + }) .WithConnectionModeDirect()); Container containerResponse = await this.database.CreateContainerAsync( @@ -128,7 +130,10 @@ public async Task SourceEnabled_FlagOn_GatewayMode_RecordsActivity_AssertLogTrac await base.TestInit(validateSinglePartitionKeyRangeCacheCall: false, customizeClientBuilder: (builder) => builder - .WithDistributedTracing(true) + .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() + { + DisableDistributedTracing = false + }) .WithHttpClientFactory(() => new HttpClient(httpClientHandlerHelper)) .WithConnectionModeGateway()); @@ -158,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() @@ -175,14 +180,20 @@ public async Task NoSourceEnabled_ResultsInNoSourceParentActivityCreation_Assert { await base.TestInit(validateSinglePartitionKeyRangeCacheCall: false, customizeClientBuilder: (builder) => builder - .WithDistributedTracing(enableDistributingTracing) + .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() + { + DisableDistributedTracing = disableDistributingTracing + }) .WithConnectionModeGateway()); } else { await base.TestInit(validateSinglePartitionKeyRangeCacheCall: false, customizeClientBuilder: (builder) => builder - .WithDistributedTracing(enableDistributingTracing)); + .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() + { + DisableDistributedTracing = disableDistributingTracing + })); } ContainerResponse containerResponse = await this.database.CreateContainerAsync( @@ -194,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 1c5676a46a..a51a77f14f 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/SynchronizationContextTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/SynchronizationContextTests.cs @@ -59,7 +59,10 @@ public void VerifySynchronizationContextDoesNotLock(bool withClientTelemetry) { using (CosmosClient client = TestCommon.CreateCosmosClient( customizeClientBuilder: (builder) => builder - .WithTelemetryEnabled() + .WithClientTelemetryOptions(new CosmosClientTelemetryOptions () + { + DisableSendingMetricsToService = !withClientTelemetry + }) .WithHttpClientFactory(() => new HttpClient(httpHandler)))) { Cosmos.Database database = client.CreateDatabaseAsync(databaseId).GetAwaiter().GetResult(); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Tracing/EndToEndTraceWriterBaselineTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Tracing/EndToEndTraceWriterBaselineTests.cs index 79e947d41b..6cd8905b07 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Tracing/EndToEndTraceWriterBaselineTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Tracing/EndToEndTraceWriterBaselineTests.cs @@ -47,28 +47,48 @@ public sealed class EndToEndTraceWriterBaselineTests : BaselineTests builder + .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() + { + DisableDistributedTracing = false, + CosmosThresholdOptions = new CosmosThresholdOptions() + { + PointOperationLatencyThreshold = TimeSpan.Zero, + NonPointOperationLatencyThreshold = TimeSpan.Zero + } + })); + bulkClient = TestCommon.CreateCosmosClient(builder => builder .WithBulkExecution(true) - .WithDistributedTracingOptions(new DistributedTracingOptions() - { - LatencyThresholdForDiagnosticEvent = TimeSpan.FromMilliseconds(0) - })); - + .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() + { + DisableDistributedTracing = false, + CosmosThresholdOptions = new CosmosThresholdOptions() + { + PointOperationLatencyThreshold = TimeSpan.Zero, + NonPointOperationLatencyThreshold = TimeSpan.Zero + } + })); + // Set a small retry count to reduce test time miscCosmosClient = TestCommon.CreateCosmosClient(builder => builder .AddCustomHandlers(requestHandler) - .WithDistributedTracingOptions(new DistributedTracingOptions() - { - LatencyThresholdForDiagnosticEvent = TimeSpan.FromMilliseconds(0) - })); + .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() + { + DisableDistributedTracing = false, + CosmosThresholdOptions = new CosmosThresholdOptions() + { + PointOperationLatencyThreshold = TimeSpan.Zero, + NonPointOperationLatencyThreshold = TimeSpan.Zero + } + })); EndToEndTraceWriterBaselineTests.database = await client.CreateDatabaseAsync( "databaseName", @@ -682,7 +702,10 @@ public async Task ValidateInvalidCredentialsTraceAsync() // It is not baseline test hence disable distributed tracing for this test CosmosClientOptions clientOptions = new CosmosClientOptions() { - IsDistributedTracingEnabled = false + CosmosClientTelemetryOptions = new CosmosClientTelemetryOptions() + { + DisableDistributedTracing = true + } }; using (CosmosClient client = new CosmosClient( @@ -1015,9 +1038,14 @@ public async Task PointOperationsExceptionsAsync() Guid exceptionActivityId = Guid.NewGuid(); using CosmosClient throttleClient = TestCommon.CreateCosmosClient(builder => builder - .WithDistributedTracingOptions(new DistributedTracingOptions() + .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() { - LatencyThresholdForDiagnosticEvent = TimeSpan.FromMilliseconds(0) + DisableDistributedTracing = false, + CosmosThresholdOptions = new CosmosThresholdOptions() + { + PointOperationLatencyThreshold = TimeSpan.Zero, + NonPointOperationLatencyThreshold = TimeSpan.Zero + } }) .WithThrottlingRetryOptions( maxRetryWaitTimeOnThrottledRequests: TimeSpan.FromSeconds(1), @@ -1303,9 +1331,14 @@ public async Task BulkOperationsAsync() maxRetryWaitTimeOnThrottledRequests: TimeSpan.FromSeconds(1), maxRetryAttemptsOnThrottledRequests: 3) .WithBulkExecution(true) - .WithDistributedTracingOptions(new DistributedTracingOptions() + .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() { - LatencyThresholdForDiagnosticEvent = TimeSpan.FromMilliseconds(0) + DisableDistributedTracing = false, + CosmosThresholdOptions = new CosmosThresholdOptions() + { + PointOperationLatencyThreshold = TimeSpan.Zero, + NonPointOperationLatencyThreshold = TimeSpan.Zero + } }) .WithTransportClientHandlerFactory(transportClient => new TransportClientWrapper( transportClient, diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/TestCommon.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/TestCommon.cs index 8cfa5be33b..48a5025289 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/TestCommon.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/TestCommon.cs @@ -130,8 +130,7 @@ internal static CosmosClient CreateCosmosClient( internal static CosmosClient CreateCosmosClient( bool useGateway, - Action customizeClientBuilder = null, - bool enableDistributingTracing = false) + Action customizeClientBuilder = null) { CosmosClientBuilder cosmosClientBuilder = GetDefaultConfiguration(); @@ -141,14 +140,6 @@ internal static CosmosClient CreateCosmosClient( { cosmosClientBuilder.WithConnectionModeGateway(); } - - if(enableDistributingTracing) - { - cosmosClientBuilder.WithDistributedTracingOptions(new DistributedTracingOptions() - { - LatencyThresholdForDiagnosticEvent = TimeSpan.FromMilliseconds(0) - }); - } return cosmosClientBuilder.Build(); } @@ -164,8 +155,7 @@ internal static DocumentClient CreateClient(bool useGateway, Protocol protocol = RetryOptions retryOptions = null, ApiType apiType = ApiType.None, EventHandler recievedResponseEventHandler = null, - bool useMultipleWriteLocations = false, - bool enableClientTelemetry = false) + bool useMultipleWriteLocations = false) { string authKey = ConfigurationManager.AppSettings["MasterKey"]; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/TransportClientHelper.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/TransportClientHelper.cs index f34135b695..ebeebad7ae 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/TransportClientHelper.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/TransportClientHelper.cs @@ -83,9 +83,14 @@ internal static Container GetContainerWithIntercepter( if (enableDistributingTracing) { - builder.WithDistributedTracingOptions(new DistributedTracingOptions() + builder.WithClientTelemetryOptions(new CosmosClientTelemetryOptions() { - LatencyThresholdForDiagnosticEvent = TimeSpan.FromMilliseconds(.0001) + DisableDistributedTracing = false, + CosmosThresholdOptions = new CosmosThresholdOptions() + { + PointOperationLatencyThreshold = TimeSpan.Zero, + NonPointOperationLatencyThreshold = TimeSpan.Zero + } }); } 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 8546a93b2f..8f25a74f08 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 @@ -355,24 +355,141 @@ "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": { - "Boolean get_IsDistributedTracingEnabled()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "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": "Boolean get_IsDistributedTracingEnabled();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "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": { + "Boolean DisableDistributedTracing": { + "Type": "Property", + "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 IsDistributedTracingEnabled": { + "Boolean DisableSendingMetricsToService": { "Type": "Property", "Attributes": [], - "MethodInfo": "Boolean IsDistributedTracingEnabled;CanRead:True;CanWrite:True;Boolean get_IsDistributedTracingEnabled();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_IsDistributedTracingEnabled(Boolean);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "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": [ + "CompilerGeneratedAttribute" + ], + "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": [], + "MethodInfo": "Microsoft.Azure.Cosmos.CosmosThresholdOptions CosmosThresholdOptions;CanRead:True;CanWrite:True;Microsoft.Azure.Cosmos.CosmosThresholdOptions get_CosmosThresholdOptions();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_CosmosThresholdOptions(Microsoft.Azure.Cosmos.CosmosThresholdOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Microsoft.Azure.Cosmos.CosmosThresholdOptions get_CosmosThresholdOptions()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Microsoft.Azure.Cosmos.CosmosThresholdOptions get_CosmosThresholdOptions();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Void .ctor()": { + "Type": "Constructor", + "Attributes": [], + "MethodInfo": "[Void .ctor(), Void .ctor()]" + }, + "Void set_CosmosThresholdOptions(Microsoft.Azure.Cosmos.CosmosThresholdOptions)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Void set_CosmosThresholdOptions(Microsoft.Azure.Cosmos.CosmosThresholdOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Void set_DisableDistributedTracing(Boolean)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "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": {} + }, + "Microsoft.Azure.Cosmos.CosmosThresholdOptions;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Subclasses": {}, + "Members": { + "System.TimeSpan get_NonPointOperationLatencyThreshold()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_NonPointOperationLatencyThreshold();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan get_PointOperationLatencyThreshold()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.TimeSpan get_PointOperationLatencyThreshold();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan NonPointOperationLatencyThreshold": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan NonPointOperationLatencyThreshold;CanRead:True;CanWrite:True;System.TimeSpan get_NonPointOperationLatencyThreshold();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_NonPointOperationLatencyThreshold(System.TimeSpan);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.TimeSpan PointOperationLatencyThreshold": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.TimeSpan PointOperationLatencyThreshold;CanRead:True;CanWrite:True;System.TimeSpan get_PointOperationLatencyThreshold();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_PointOperationLatencyThreshold(System.TimeSpan);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Void .ctor()": { + "Type": "Constructor", + "Attributes": [], + "MethodInfo": "[Void .ctor(), Void .ctor()]" + }, + "Void set_NonPointOperationLatencyThreshold(System.TimeSpan)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Void set_NonPointOperationLatencyThreshold(System.TimeSpan);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Void set_IsDistributedTracingEnabled(Boolean)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Void set_PointOperationLatencyThreshold(System.TimeSpan)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ "CompilerGeneratedAttribute" ], - "MethodInfo": "Void set_IsDistributedTracingEnabled(Boolean);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Void set_PointOperationLatencyThreshold(System.TimeSpan);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" } }, "NestedTypes": {} @@ -454,10 +571,10 @@ "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 WithDistributedTracing(Boolean)": { + "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithClientTelemetryOptions(Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions)": { "Type": "Method", "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithDistributedTracing(Boolean);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithClientTelemetryOptions(Microsoft.Azure.Cosmos.CosmosClientTelemetryOptions);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" } }, "NestedTypes": {} 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 37d89c389a..f3c45adf48 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,12 @@ 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 + Assert.IsTrue(clientOptions.CosmosClientTelemetryOptions.DisableSendingMetricsToService); cosmosClientBuilder.WithApplicationRegion(region) .WithConnectionModeGateway(maxConnections, webProxy) @@ -164,9 +170,14 @@ public void VerifyCosmosConfigurationPropertiesGetUpdated() portReuseMode, enableTcpConnectionEndpointRediscovery) .WithApplicationPreferredRegions(preferredLocations) - .WithDistributedTracingOptions(new DistributedTracingOptions + .WithClientTelemetryOptions(new CosmosClientTelemetryOptions() { - LatencyThresholdForDiagnosticEvent = TimeSpan.FromMilliseconds(100) + DisableDistributedTracing = false, + CosmosThresholdOptions = new CosmosThresholdOptions() + { + PointOperationLatencyThreshold = TimeSpan.FromMilliseconds(100), + NonPointOperationLatencyThreshold = TimeSpan.FromMilliseconds(100) + } }); cosmosClient = cosmosClientBuilder.Build(new MockDocumentClient()); @@ -179,8 +190,9 @@ public void VerifyCosmosConfigurationPropertiesGetUpdated() Assert.AreEqual(portReuseMode, clientOptions.PortReuseMode); Assert.IsTrue(clientOptions.EnableTcpConnectionEndpointRediscovery); CollectionAssert.AreEqual(preferredLocations.ToArray(), clientOptions.ApplicationPreferredRegions.ToArray()); - Assert.AreEqual(TimeSpan.FromMilliseconds(100), clientOptions.DistributedTracingOptions.LatencyThresholdForDiagnosticEvent); - Assert.IsTrue(clientOptions.IsDistributedTracingEnabled); + Assert.AreEqual(TimeSpan.FromMilliseconds(100), clientOptions.CosmosClientTelemetryOptions.CosmosThresholdOptions.PointOperationLatencyThreshold); + Assert.AreEqual(TimeSpan.FromMilliseconds(100), clientOptions.CosmosClientTelemetryOptions.CosmosThresholdOptions.NonPointOperationLatencyThreshold); + Assert.IsFalse(clientOptions.CosmosClientTelemetryOptions.DisableDistributedTracing); //Verify GetConnectionPolicy returns the correct values policy = clientOptions.GetConnectionPolicy(clientId: 0); 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 8d08704eeb..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,11 +246,7 @@ public void ValidateMasterKeyAuthProvider() using (CosmosClient client = new CosmosClient( CosmosClientTests.AccountEndpoint, - masterKeyCredential, - new CosmosClientOptions() - { - EnableClientTelemetry = false, - })) + masterKeyCredential)) { Assert.AreEqual(typeof(AuthorizationTokenProviderMasterKey), client.AuthorizationTokenProvider.GetType()); } @@ -265,11 +259,7 @@ public void ValidateResourceTokenAuthProvider() using (CosmosClient client = new CosmosClient( CosmosClientTests.AccountEndpoint, - resourceToken, - new CosmosClientOptions() - { - EnableClientTelemetry = false, - })) + resourceToken)) { Assert.AreEqual(typeof(AuthorizationTokenProviderResourceToken), client.AuthorizationTokenProvider.GetType()); } @@ -283,11 +273,7 @@ public void ValidateMasterKeyAzureCredentialAuthProvider() AzureKeyCredential masterKeyCredential = new AzureKeyCredential(originalKey); using (CosmosClient client = new CosmosClient( CosmosClientTests.AccountEndpoint, - masterKeyCredential, - new CosmosClientOptions() - { - EnableClientTelemetry = false, - })) + masterKeyCredential)) { Assert.AreEqual(typeof(AzureKeyCredentialAuthorizationTokenProvider), client.AuthorizationTokenProvider.GetType()); @@ -304,11 +290,7 @@ public void ValidateResourceTokenAzureCredentialAuthProvider() AzureKeyCredential resourceTokenCredential = new AzureKeyCredential(resourceToken); using (CosmosClient client = new CosmosClient( CosmosClientTests.AccountEndpoint, - resourceTokenCredential, - new CosmosClientOptions() - { - EnableClientTelemetry = false, - })) + resourceTokenCredential)) { Assert.AreEqual(typeof(AzureKeyCredentialAuthorizationTokenProvider), client.AuthorizationTokenProvider.GetType()); @@ -377,8 +359,7 @@ public async Task ValidateAzureKeyCredentialGatewayModeUpdateAsync() masterKeyCredential, new CosmosClientOptions() { - HttpClientFactory = () => new HttpClient(new HttpHandlerHelper(mockHttpHandler.Object)), - EnableClientTelemetry = false, + HttpClientFactory = () => new HttpClient(new HttpHandlerHelper(mockHttpHandler.Object)) })) { Container container = client.GetContainer(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); @@ -440,10 +421,7 @@ void TraceHandler(string message) for (int z = 0; z < 100; ++z) { - using CosmosClient cosmos = new(ConnectionString, new CosmosClientOptions - { - EnableClientTelemetry = true - }); + using CosmosClient cosmos = new(ConnectionString); } string assertMsg = String.Empty; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Diagnostics/DiagnosticHandlerHelperTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Diagnostics/DiagnosticHandlerHelperTests.cs index c620b726e7..cd0a92ad1b 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Diagnostics/DiagnosticHandlerHelperTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Diagnostics/DiagnosticHandlerHelperTests.cs @@ -58,8 +58,9 @@ public async Task RefreshTestAsync() { // Get default instance of DiagnosticsHandlerHelper with client telemetry disabled (default) DiagnosticsHandlerHelper diagnosticHandlerHelper1 = DiagnosticsHandlerHelper.GetInstance(); - await Task.Delay(10000); // warm up + await Task.Delay(10000); // warm up to make sure there is at least one entry in the history Assert.IsNotNull(diagnosticHandlerHelper1.GetDiagnosticsSystemHistory()); + Assert.IsNull(diagnosticHandlerHelper1.GetClientTelemetrySystemHistory()); Assert.IsTrue(diagnosticHandlerHelper1.GetDiagnosticsSystemHistory().Values.Count > 0); int countBeforeRefresh = diagnosticHandlerHelper1.GetDiagnosticsSystemHistory().Values.Count; @@ -69,22 +70,21 @@ public async Task RefreshTestAsync() Assert.IsNull(TelemetrySystemUsageRecorderField1.GetValue(null)); // Refresh instance of DiagnosticsHandlerHelper with client telemetry enabled - DiagnosticsHandlerHelper.Refresh(true); - await Task.Delay(5000); // warm up again to populate telemetry data + DiagnosticsHandlerHelper.Refresh(isClientTelemetryEnabled: true); DiagnosticsHandlerHelper diagnosticHandlerHelper2 = DiagnosticsHandlerHelper.GetInstance(); - int countAfterRefresh = diagnosticHandlerHelper1.GetDiagnosticsSystemHistory().Values.Count; - + Assert.IsNotNull(diagnosticHandlerHelper2.GetDiagnosticsSystemHistory()); + int countAfterRefresh = diagnosticHandlerHelper2.GetDiagnosticsSystemHistory().Values.Count; + Assert.IsTrue(countBeforeRefresh <= countAfterRefresh, "After Refresh count should be greater than or equal to before refresh count"); - Assert.AreNotEqual(diagnosticHandlerHelper1, diagnosticHandlerHelper2); - Assert.IsNotNull(diagnosticHandlerHelper2.GetDiagnosticsSystemHistory()); + await Task.Delay(5000); // warm up to make sure there is at least one entry in the history Assert.IsNotNull(diagnosticHandlerHelper2.GetClientTelemetrySystemHistory()); Assert.IsTrue(diagnosticHandlerHelper2.GetClientTelemetrySystemHistory().Values.Count > 0); // Refresh instance of DiagnosticsHandlerHelper with client telemetry disabled - DiagnosticsHandlerHelper.Refresh(false); + DiagnosticsHandlerHelper.Refresh(isClientTelemetryEnabled: false); DiagnosticsHandlerHelper diagnosticHandlerHelper3 = DiagnosticsHandlerHelper.GetInstance(); Assert.IsNotNull(diagnosticHandlerHelper3.GetDiagnosticsSystemHistory()); Assert.IsNull(diagnosticHandlerHelper3.GetClientTelemetrySystemHistory()); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Telemetry/DiagnosticsFilterHelperTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Telemetry/DiagnosticsFilterHelperTest.cs index 5e32b26da1..62517239e3 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Telemetry/DiagnosticsFilterHelperTest.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Telemetry/DiagnosticsFilterHelperTest.cs @@ -14,7 +14,6 @@ namespace Microsoft.Azure.Cosmos.Tests.Telemetry using Documents; using VisualStudio.TestTools.UnitTesting; - [TestClass] public class DiagnosticsFilterHelperTest { @@ -33,9 +32,9 @@ public void CheckReturnFalseOnSuccessAndLowerLatencyThanConfiguredConfig() { Assert.IsTrue(this.rootTrace.Duration > TimeSpan.Zero); - DistributedTracingOptions distributedTracingOptions = new DistributedTracingOptions + CosmosThresholdOptions distributedTracingOptions = new CosmosThresholdOptions { - LatencyThresholdForDiagnosticEvent = this.rootTrace.Duration.Add(TimeSpan.FromSeconds(1)) + PointOperationLatencyThreshold = this.rootTrace.Duration.Add(TimeSpan.FromSeconds(1)) }; OpenTelemetryAttributes response = new OpenTelemetryAttributes @@ -48,7 +47,7 @@ public void CheckReturnFalseOnSuccessAndLowerLatencyThanConfiguredConfig() DiagnosticsFilterHelper .IsLatencyThresholdCrossed(distributedTracingOptions, OperationType.Read, response), $" Response time is {response.Diagnostics.GetClientElapsedTime().Milliseconds}ms " + - $"and Configured threshold value is {distributedTracingOptions.LatencyThresholdForDiagnosticEvent.Value.Milliseconds}ms " + + $"and Configured threshold value is {distributedTracingOptions.PointOperationLatencyThreshold.Milliseconds}ms " + $"and Is response Success : {response.StatusCode.IsSuccess()}" ); } @@ -56,13 +55,6 @@ public void CheckReturnFalseOnSuccessAndLowerLatencyThanConfiguredConfig() public void CheckReturnTrueOnFailedStatusCode() { Assert.IsTrue(this.rootTrace.Duration > TimeSpan.Zero); - - - DistributedTracingOptions distributedTracingOptions = new DistributedTracingOptions - { - LatencyThresholdForDiagnosticEvent = this.rootTrace.Duration.Add(TimeSpan.FromSeconds(1)) - }; - OpenTelemetryAttributes response = new OpenTelemetryAttributes { StatusCode = HttpStatusCode.BadRequest, @@ -73,9 +65,28 @@ public void CheckReturnTrueOnFailedStatusCode() !DiagnosticsFilterHelper .IsSuccessfulResponse(response.StatusCode, response.SubStatusCode), $" Response time is {response.Diagnostics.GetClientElapsedTime().Milliseconds}ms " + - $"and Configured threshold value is {distributedTracingOptions.LatencyThresholdForDiagnosticEvent.Value.Milliseconds}ms " + $"and Is response Success : {response.StatusCode.IsSuccess()}"); } + [TestMethod] + public void CheckedDefaultThresholdBasedOnOperationType() + { + Assert.IsTrue(this.rootTrace.Duration > TimeSpan.Zero); + + CosmosThresholdOptions config = new CosmosThresholdOptions(); + + Array values = Enum.GetValues(typeof(OperationType)); + + foreach(OperationType operationType in values) + { + TimeSpan defaultThreshold = DiagnosticsFilterHelper.DefaultThreshold(operationType, config); + + if(DiagnosticsFilterHelper.IsPointOperation(operationType)) + Assert.AreEqual(defaultThreshold, config.PointOperationLatencyThreshold); + else + Assert.AreEqual(defaultThreshold, config.NonPointOperationLatencyThreshold); + } + } + } } 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);