Skip to content

Commit 3ad6562

Browse files
Merge branch 'master' into users/kundadebdatta/3548_replica_validation_v3_changes
2 parents b2541ec + 4b77519 commit 3ad6562

32 files changed

+499
-363
lines changed

Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<ClientOfficialVersion>3.31.2</ClientOfficialVersion>
55
<ClientPreviewVersion>3.31.2</ClientPreviewVersion>
66
<ClientPreviewSuffixVersion>preview</ClientPreviewSuffixVersion>
7-
<DirectVersion>3.30.0</DirectVersion>
7+
<DirectVersion>3.30.1</DirectVersion>
88
<EncryptionOfficialVersion>2.0.0</EncryptionOfficialVersion>
99
<EncryptionPreviewVersion>2.0.0</EncryptionPreviewVersion>
1010
<EncryptionPreviewSuffixVersion>preview</EncryptionPreviewSuffixVersion>

Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/Configuration/ChangeFeedProcessorOptions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public DateTime? StartTime
6666
throw new ArgumentException("StartTime cannot have DateTimeKind.Unspecified", nameof(value));
6767
}
6868

69-
this.startTime = value;
69+
this.startTime = value.HasValue && value.Value.Kind == DateTimeKind.Local ? value.Value.ToUniversalTime() : value;
7070
}
7171
}
7272

Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs

+16-4
Original file line numberDiff line numberDiff line change
@@ -988,17 +988,29 @@ public override bool CanConvert(Type objectType)
988988
return objectType == typeof(DateTime);
989989
}
990990
}
991-
991+
992992
/// <summary>
993993
/// Distributed Tracing Options. <see cref="Microsoft.Azure.Cosmos.DistributedTracingOptions"/>
994994
/// </summary>
995+
/// <remarks> Applicable only when Operation level distributed tracing is enabled through <see cref="Microsoft.Azure.Cosmos.CosmosClientOptions.IsDistributedTracingEnabled"/></remarks>
995996
internal DistributedTracingOptions DistributedTracingOptions { get; set; }
996997

997998
/// <summary>
998-
/// Gets or sets value indicating whether distributed tracing activities (<see cref="System.Diagnostics.Activity"/>) are going to be created for the SDK methods calls and HTTP calls.
999-
/// By default true for Preview package
999+
/// Gets or sets the flag to generate operation level <see cref="System.Diagnostics.Activity"/> for methods calls using the Source Name "Azure.Cosmos.Operation".
10001000
/// </summary>
1001-
internal bool EnableDistributedTracing { get; set; }
1001+
/// <value>
1002+
/// The default value is true (for preview package).
1003+
/// </value>
1004+
/// <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>
1005+
#if PREVIEW
1006+
public
1007+
#else
1008+
internal
1009+
#endif
1010+
bool IsDistributedTracingEnabled { get; set; }
1011+
#if PREVIEW
1012+
= true;
1013+
#endif
10021014

10031015
}
10041016
}

Microsoft.Azure.Cosmos/src/DocumentClient.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ private void InitializeClientTelemetry()
10361036
this.clientTelemetry = ClientTelemetry.CreateAndStartBackgroundTelemetry(
10371037
clientId: this.clientId,
10381038
httpClient: this.httpClient,
1039-
userAgent: this.ConnectionPolicy.UserAgentContainer.UserAgent,
1039+
userAgent: this.ConnectionPolicy.UserAgentContainer.BaseUserAgent,
10401040
connectionMode: this.ConnectionPolicy.ConnectionMode,
10411041
authorizationTokenProvider: this.cosmosAuthorization,
10421042
diagnosticsHelper: DiagnosticsHandlerHelper.Instance,

Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs

+21-3
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,30 @@ public CosmosClientBuilder WithConsistencyLevel(Cosmos.ConsistencyLevel consiste
424424
}
425425

426426
/// <summary>
427-
/// If Open Telemetry listener is subscribed for Azure.Cosmos namespace, There are <see cref="Microsoft.Azure.Cosmos.DistributedTracingOptions"/> you can leverage to control it.<br></br>
427+
/// Sets whether Distributed Tracing for "Azure.Cosmos.Operation" source is enabled.
428428
/// </summary>
429-
/// <param name="options">Tracing Options <see cref="Microsoft.Azure.Cosmos.DistributedTracingOptions"/></param>
429+
/// <param name="isEnabled">Whether <see cref="CosmosClientOptions.IsDistributedTracingEnabled"/> is enabled.</param>
430430
/// <returns>The current <see cref="CosmosClientBuilder"/>.</returns>
431-
internal CosmosClientBuilder WithDistributingTracing(DistributedTracingOptions options)
431+
#if PREVIEW
432+
public
433+
#else
434+
internal
435+
#endif
436+
CosmosClientBuilder WithDistributedTracing(bool isEnabled = true)
437+
{
438+
this.clientOptions.IsDistributedTracingEnabled = isEnabled;
439+
return this;
440+
}
441+
442+
/// <summary>
443+
/// Enables Distributed Tracing with a Configuration ref. <see cref="DistributedTracingOptions"/>
444+
/// </summary>
445+
/// <param name="options"><see cref="DistributedTracingOptions"/>.</param>
446+
/// <returns>The current <see cref="CosmosClientBuilder"/>.</returns>]
447+
/// <remarks>Refer https://opentelemetry.io/docs/instrumentation/net/exporters/ to know more about open telemetry exporters</remarks>
448+
internal CosmosClientBuilder WithDistributedTracingOptions(DistributedTracingOptions options)
432449
{
450+
this.clientOptions.IsDistributedTracingEnabled = true;
433451
this.clientOptions.DistributedTracingOptions = options;
434452

435453
return this;

Microsoft.Azure.Cosmos/src/Regions.cs

+5
Original file line numberDiff line numberDiff line change
@@ -344,5 +344,10 @@ public static class Regions
344344
/// Name of the Azure China East 3 region in the Azure Cosmos DB service.
345345
/// </summary>
346346
public const string ChinaEast3 = "China East 3";
347+
348+
/// <summary>
349+
/// Name of the Azure Poland Central region in the Azure Cosmos DB service.
350+
/// </summary>
351+
public const string PolandCentral = "Poland Central";
347352
}
348353
}

Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/CosmosDbEventSource.cs

+4-10
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static void RecordDiagnosticsForRequests(
4040
operationType: operationType,
4141
response: response) && CosmosDbEventSource.IsEnabled(EventLevel.Warning))
4242
{
43-
CosmosDbEventSource.Singleton.WriteWarningEvent(response.Diagnostics.ToString());
43+
CosmosDbEventSource.Singleton.LatencyOverThreshold(response.Diagnostics.ToString());
4444
}
4545
}
4646

@@ -49,26 +49,20 @@ public static void RecordDiagnosticsForExceptions(CosmosDiagnostics diagnostics)
4949
{
5050
if (CosmosDbEventSource.IsEnabled(EventLevel.Error))
5151
{
52-
CosmosDbEventSource.Singleton.WriteErrorEvent(diagnostics.ToString());
52+
CosmosDbEventSource.Singleton.Exception(diagnostics.ToString());
5353
}
5454
}
5555

5656
[Event(1, Level = EventLevel.Error)]
57-
private void WriteErrorEvent(string message)
57+
private void Exception(string message)
5858
{
5959
this.WriteEvent(1, message);
6060
}
6161

6262
[Event(2, Level = EventLevel.Warning)]
63-
private void WriteWarningEvent(string message)
63+
private void LatencyOverThreshold(string message)
6464
{
6565
this.WriteEvent(2, message);
6666
}
67-
68-
[Event(3, Level = EventLevel.Informational)]
69-
private void WriteInfoEvent(string message)
70-
{
71-
this.WriteEvent(3, message);
72-
}
7367
}
7468
}

Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/DistributedTracingOptions.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ namespace Microsoft.Azure.Cosmos
77
using System;
88

99
/// <summary>
10-
/// Open Telemetry Configuration
11-
/// It needs to be public once AppInsight is ready
10+
/// Options for configuring the distributed tracing and event tracing
1211
/// </summary>
1312
internal sealed class DistributedTracingOptions
1413
{
@@ -23,9 +22,9 @@ internal sealed class DistributedTracingOptions
2322
internal static readonly TimeSpan DefaultQueryTimeoutThreshold = TimeSpan.FromMilliseconds(500);
2423

2524
/// <summary>
26-
/// Latency Threshold to generate (<see cref="System.Diagnostics.Tracing.EventSource"/>) with Request diagnostics in distributing Tracing.<br></br>
27-
/// If it is not set then by default it will generate (<see cref="System.Diagnostics.Tracing.EventSource"/>) for query operation which are taking more than 500 ms and non-query operations taking more than 100 ms.
25+
/// SDK generates <see cref="System.Diagnostics.Tracing.EventSource"/> (Event Source Name is "Azure-Cosmos-Operation-Request-Diagnostics") with Request Diagnostics String, If Operation level distributed tracing is not disabled i.e. <see cref="Microsoft.Azure.Cosmos.CosmosClientOptions.IsDistributedTracingEnabled"/>
2826
/// </summary>
29-
public TimeSpan? DiagnosticsLatencyThreshold { get; set; }
27+
/// <remarks>If it is not set then, by default, it will generate <see cref="System.Diagnostics.Tracing.EventSource"/> for query operation which are taking more than 500 ms and non-query operations taking more than 100 ms.</remarks>
28+
public TimeSpan? LatencyThresholdForDiagnosticEvent { get; set; }
3029
}
3130
}

Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/Filters/DiagnosticsFilterHelper.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public static bool IsTracingNeeded(
2222
{
2323
TimeSpan latencyThreshold;
2424

25-
if (config?.DiagnosticsLatencyThreshold != null)
25+
if (config?.LatencyThresholdForDiagnosticEvent != null)
2626
{
27-
latencyThreshold = config.DiagnosticsLatencyThreshold.Value;
27+
latencyThreshold = config.LatencyThresholdForDiagnosticEvent.Value;
2828
}
2929
else
3030
{

Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryRecorderFactory.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Microsoft.Azure.Cosmos.Telemetry
66
{
7+
using System;
78
using global::Azure.Core.Pipeline;
89

910
/// <summary>
@@ -15,19 +16,19 @@ internal static class OpenTelemetryRecorderFactory
1516
/// Singleton to make sure we only have one instance of the DiagnosticScopeFactory and pattern matching of listener happens only once
1617
/// </summary>
1718
private static DiagnosticScopeFactory ScopeFactory { get; set; }
18-
19+
1920
public static OpenTelemetryCoreRecorder CreateRecorder(string operationName,
2021
string containerName,
2122
string databaseName,
2223
Documents.OperationType operationType,
2324
RequestOptions requestOptions,
2425
CosmosClientContext clientContext)
2526
{
26-
if (clientContext is { ClientOptions.EnableDistributedTracing: true })
27+
if (clientContext is { ClientOptions.IsDistributedTracingEnabled: true })
2728
{
28-
ScopeFactory = new DiagnosticScopeFactory(clientNamespace: OpenTelemetryAttributeKeys.DiagnosticNamespace,
29-
resourceProviderNamespace: OpenTelemetryAttributeKeys.ResourceProviderNamespace,
30-
isActivityEnabled: true);
29+
OpenTelemetryRecorderFactory.ScopeFactory ??= new DiagnosticScopeFactory(clientNamespace: OpenTelemetryAttributeKeys.DiagnosticNamespace,
30+
resourceProviderNamespace: OpenTelemetryAttributeKeys.ResourceProviderNamespace,
31+
isActivityEnabled: true);
3132

3233
// If there is no source then it will return default otherwise a valid diagnostic scope
3334
DiagnosticScope scope = OpenTelemetryRecorderFactory

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/EndToEndTraceWriterBaselineTests.BatchOperationsAsync.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
]
131131
}]]></Json>
132132
<OTelActivities><ACTIVITY><OPERATION>Operation.ExecuteAsync</OPERATION><ATTRIBUTE-KEY>kind</ATTRIBUTE-KEY><ATTRIBUTE-VALUE>client</ATTRIBUTE-VALUE><ATTRIBUTE-KEY>az.namespace</ATTRIBUTE-KEY><ATTRIBUTE-VALUE>Microsoft.DocumentDB</ATTRIBUTE-VALUE><ATTRIBUTE-KEY>db.operation</ATTRIBUTE-KEY><ATTRIBUTE-VALUE>ExecuteAsync</ATTRIBUTE-VALUE><ATTRIBUTE-KEY>db.name</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.container</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.system</ATTRIBUTE-KEY><ATTRIBUTE-VALUE>cosmosdb</ATTRIBUTE-VALUE><ATTRIBUTE-KEY>db.cosmosdb.machine_id</ATTRIBUTE-KEY><ATTRIBUTE-KEY>net.peer.name</ATTRIBUTE-KEY><ATTRIBUTE-VALUE>127.0.0.1</ATTRIBUTE-VALUE><ATTRIBUTE-KEY>db.cosmosdb.client_id</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.user_agent</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.connection_mode</ATTRIBUTE-KEY><ATTRIBUTE-VALUE>Direct</ATTRIBUTE-VALUE><ATTRIBUTE-KEY>db.cosmosdb.operation_type</ATTRIBUTE-KEY><ATTRIBUTE-VALUE>Replace</ATTRIBUTE-VALUE><ATTRIBUTE-KEY>db.cosmosdb.request_content_length_bytes</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.response_content_length_bytes</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.status_code</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.sub_status_code</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.request_charge</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.item_count</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.activity_id</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.correlated_activity_id</ATTRIBUTE-KEY><ATTRIBUTE-KEY>db.cosmosdb.regions_contacted</ATTRIBUTE-KEY><ATTRIBUTE-VALUE>South Central US</ATTRIBUTE-VALUE></ACTIVITY>
133-
<EVENT>Ideally, this should contain request diagnostics but request diagnostics is subject to change with each request as it contains few unique id. So just putting this tag with this static text to make sure event is getting generated for each test.</EVENT>
133+
<EVENT><EVENT-NAME>LatencyOverThreshold</EVENT-NAME><EVENT-TEXT>Ideally, this should contain request diagnostics but request diagnostics is subject to change with each request as it contains few unique id. So just putting this tag with this static text to make sure event is getting generated for each test.</EVENT-TEXT></EVENT>
134134
</OTelActivities>
135135
</Output>
136136
</Result>

0 commit comments

Comments
 (0)