Skip to content

Commit

Permalink
public API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sourabh1007 committed Sep 4, 2023
1 parent b1bdbeb commit 705d0c6
Show file tree
Hide file tree
Showing 19 changed files with 153 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
}
};

Expand Down
6 changes: 3 additions & 3 deletions Microsoft.Azure.Cosmos.Samples/Tools/CTL/CTLConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -132,7 +132,7 @@ internal CosmosClient CreateCosmosClient()
ApplicationName = CTLConfig.UserAgentSuffix,
CosmosClientTelemetryOptions = new CosmosClientTelemetryOptions()
{
EnableSendingMetricsToService = true,
DisableSendingMetricsToService = this.DisableClientTelemetry,
}
};

Expand Down
7 changes: 2 additions & 5 deletions Microsoft.Azure.Cosmos.Samples/Tools/CTL/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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<Task> tasks = new List<Task>
Expand Down
22 changes: 9 additions & 13 deletions Microsoft.Azure.Cosmos/src/ConnectionPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}

/// <summary>
Expand Down Expand Up @@ -211,15 +211,6 @@ public bool EnableTcpConnectionEndpointRediscovery
set;
}

/// <summary>
/// Gets or sets the flag to enable client telemetry feature.
/// </summary>
internal bool EnableClientTelemetry
{
get;
set;
}

/// <summary>
/// Gets the default connection policy used to connect to the Azure Cosmos DB service.
/// </summary>
Expand Down Expand Up @@ -490,9 +481,14 @@ internal int? MaxTcpPartitionCount
}

/// <summary>
/// ClientTelemetryOptions
/// Gets or sets Client Telemetry Options like feature flags and corresponding options
/// </summary>
public CosmosClientTelemetryOptions CosmosClientTelemetryOptions
#if PREVIEW
public
#else
internal
#endif
CosmosClientTelemetryOptions CosmosClientTelemetryOptions
{
get;
set;
Expand Down
10 changes: 7 additions & 3 deletions Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -731,9 +730,14 @@ internal Protocol ConnectionProtocol
internal bool? EnableCpuMonitor { get; set; }

/// <summary>
/// Client Telemetry Options
/// Gets or sets Client Telemetry Options like feature flags and corresponding options
/// </summary>
public CosmosClientTelemetryOptions CosmosClientTelemetryOptions { get; set; }
#if PREVIEW
public
#else
internal
#endif
CosmosClientTelemetryOptions CosmosClientTelemetryOptions { get; set; }

internal void SetSerializerIfNotConfigured(CosmosSerializer serializer)
{
Expand Down
28 changes: 21 additions & 7 deletions Microsoft.Azure.Cosmos/src/CosmosClientTelemetryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,29 @@ namespace Microsoft.Azure.Cosmos
public class CosmosClientTelemetryOptions
{
/// <summary>
/// Enable sending telemetry to service, <see cref="CosmosThresholdOptions"/> is not applicable to this as of now
/// Disable sending telemetry to service, <see cref="CosmosThresholdOptions"/> is not applicable to this as of now.
/// This option will disable sending telemetry to service.even it is opt-in from portal.
/// </summary>
public bool EnableSendingMetricsToService { get; set; } = false;
/// <remarks>By default, it is false</remarks>
#if PREVIEW
public
#else
internal
#endif
bool DisableSendingMetricsToService { get; set; } =
#if PREVIEW
false;
#else
true;
#endif

/// <summary>
/// Gets or sets the flag to generate operation level <see cref="System.Diagnostics.Activity"/> for methods calls using the Source Name "Azure.Cosmos.Operation".
/// This method enable/disable generation of operation level <see cref="System.Diagnostics.Activity"/> if listener is subscribed to the Source Name "Azure.Cosmos.Operation".
/// </summary>
/// <value>
/// The default value is true (for preview package).
/// The default value is true
/// </value>
/// <remarks>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</remarks>
/// <remarks> Please Refer https://opentelemetry.io/docs/instrumentation/net/exporters/ to know more about open telemetry exporters</remarks>
#if PREVIEW
public
#else
Expand All @@ -34,13 +46,15 @@ public class CosmosClientTelemetryOptions
#endif

/// <summary>
/// Threshold values for telemetry
/// Threshold values for Distributed Tracing.
/// These values decides whether to generate operation level <see cref="System.Diagnostics.Tracing.EventSource"/> with request diagnostics or not.
/// </summary>
#if PREVIEW
public
#else
internal
#endif
CosmosThresholdOptions CosmosThresholdOptions { get; set; }
CosmosThresholdOptions CosmosThresholdOptions { get; set; } = new CosmosThresholdOptions();

}
}
9 changes: 7 additions & 2 deletions Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -682,11 +682,16 @@ internal CosmosClientBuilder WithRetryWithOptions(
}

/// <summary>
/// WithClientTelemetryOptions
/// To enable Telemetry features with corresponding options
/// </summary>
/// <param name="options"></param>
/// <returns>The <see cref="CosmosClientBuilder"/> object</returns>
public CosmosClientBuilder WithClientTelemetryOptions(CosmosClientTelemetryOptions options)
#if PREVIEW
public
#else
internal
#endif
CosmosClientBuilder WithClientTelemetryOptions(CosmosClientTelemetryOptions options)
{
this.clientOptions.CosmosClientTelemetryOptions = options;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static TelemetryToServiceHelper CreateAndInitializeClientConfigAndTelemet
#if INTERNAL
return new TelemetryToServiceHelper();
#else
if (!connectionPolicy.EnableClientTelemetry)
if (connectionPolicy.CosmosClientTelemetryOptions.DisableSendingMetricsToService)
{
return new TelemetryToServiceHelper();
}
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,6 @@
<ATTRIBUTE key="tcp.sub_status_code">0</ATTRIBUTE>
<ATTRIBUTE key="tcp.status_code">201</ATTRIBUTE>
</ACTIVITY>
<ACTIVITY source="Azure.Cosmos.Request" operationName="RequestAsync" displayName="Read Database">
<ATTRIBUTE key="az.namespace">Microsoft.DocumentDB</ATTRIBUTE>
<ATTRIBUTE key="az.schema_url">https://opentelemetry.io/schemas/1.17.0</ATTRIBUTE>
<ATTRIBUTE key="tcp.uri">Some Value</ATTRIBUTE>
<ATTRIBUTE key="tcp.sub_status_code">0</ATTRIBUTE>
<ATTRIBUTE key="tcp.status_code">404</ATTRIBUTE>
</ACTIVITY>
<EVENT name="LatencyOverThreshold" />
<EVENT name="LatencyOverThreshold" />
</OTelActivities></Output>
</Result>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public virtual void TestInitialize()
this.cosmosClientBuilder = this.GetBuilder()
.WithClientTelemetryOptions(new CosmosClientTelemetryOptions()
{
EnableSendingMetricsToService = true
DisableSendingMetricsToService = false
})
.WithApplicationPreferredRegions(ClientTelemetryTestsBase.preferredRegionList);
}
Expand Down Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -182,8 +182,8 @@ await base.TestInit(validateSinglePartitionKeyRangeCacheCall: false,
customizeClientBuilder: (builder) => builder
.WithClientTelemetryOptions(new CosmosClientTelemetryOptions()
{
DisableDistributedTracing = !enableDistributingTracing
})
DisableDistributedTracing = disableDistributingTracing
})
.WithConnectionModeGateway());
}
else
Expand All @@ -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(
Expand All @@ -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"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void VerifySynchronizationContextDoesNotLock(bool withClientTelemetry)
customizeClientBuilder: (builder) => builder
.WithClientTelemetryOptions(new CosmosClientTelemetryOptions ()
{
EnableSendingMetricsToService = withClientTelemetry
DisableSendingMetricsToService = !withClientTelemetry
})
.WithHttpClientFactory(() => new HttpClient(httpHandler))))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 705d0c6

Please sign in to comment.